# This file contains snippets that are always defined. I personally # have snippets for signatures and often needed texts # sligthly lower priority than everything else since specialized versions # should overwrite. The user needs to adjust her priority in her snippets to # ~-55 so that other filetypes will still overwrite. priority -60 global !p def _parse_comments(s): """ Parses vim's comments option to extract comment format """ i = iter(s.split(",")) rv = [] try: while True: # get the flags and text of a comment part flags, text = next(i).split(':', 1) if len(flags) == 0: rv.append(('OTHER', text, text, text, "")) # parse 3-part comment, but ignore those with O flag elif 's' in flags and 'O' not in flags: ctriple = ["TRIPLE"] indent = "" if flags[-1] in string.digits: indent = " " * int(flags[-1]) ctriple.append(text) flags, text = next(i).split(':', 1) assert flags[0] == 'm' ctriple.append(text) flags, text = next(i).split(':', 1) assert flags[0] == 'e' ctriple.append(text) ctriple.append(indent) rv.append(ctriple) elif 'b' in flags: if len(text) == 1: rv.insert(0, ("SINGLE_CHAR", text, text, text, "")) except StopIteration: return rv def get_comment_format(): """ Returns a 4-element tuple (first_line, middle_lines, end_line, indent) representing the comment format for the current file. It first looks at the 'commentstring', if that ends with %s, it uses that. Otherwise it parses '&comments' and prefers single character comment markers if there are any. """ commentstring = vim.eval("&commentstring") if commentstring.endswith("%s"): c = commentstring[:-2] return (c, c, c, "") comments = _parse_comments(vim.eval("&comments")) for c in comments: if c[0] == "SINGLE_CHAR": return c[1:] return comments[0][1:] endglobal ########################## # LOREM IPSUM GENERATORS # ########################## snippet lorem "Lorem Ipsum - 50 Words" b Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. endsnippet ########################## # VIM MODELINE GENERATOR # ########################## # See advice on `:help 'tabstop'` for why these values are set. Uses second # modeline form ('set') to work in languages with comment terminators # (/* like C */). snippet modeline "Vim modeline" vim`!v ':set '. (&expandtab ? printf('et sw=%i ts=%i', &sw, &ts) : printf('noet sts=%i sw=%i ts=%i', &sts, &sw, &ts)) . (&tw ? ' tw='. &tw : '') . ':'` endsnippet ######### # DATES # ######### snippet date "YYYY-MM-DD" w `!v strftime("%Y-%m-%d")` endsnippet snippet ddate "DD.MM.YYYY" w `!v strftime("%d.%m.%Y")` endsnippet snippet diso "ISO format datetime" w `!v strftime("%Y-%m-%d %H:%M:%S%z")` endsnippet snippet time "hh:mm" w `!v strftime("%H:%M")` endsnippet snippet datetime "YYYY-MM-DD hh:mm" w `!v strftime("%Y-%m-%d %H:%M")` endsnippet snippet todo "TODO comment" bw `!p snip.rv=get_comment_format()[0]` ${2:TODO}: $1 ${3: <${4:`!v strftime('%d.%m.%y %H:%M')`}${5:, `git config --get user.name`}>} `!p snip.rv=get_comment_format()[2]` endsnippet ########## # Misc # ########## snippet uuid "Random UUID" w `!p if not snip.c: import uuid; snip.rv = uuid.uuid4()` endsnippet # vim:ft=snippets: