# Tag Info

26

I've been using ultisnips for several weeks now. I think the main advantages of this plugin are the following: It is pretty fast even with a great number of snippets available. The basic syntax to define a new snippet is easy to understand, thus it is easy to quickly create a new snippet doing what you want to do. (For more complex snippets some additional ...

16

I've been using the original SnipMate since I started using Vim. It doesn't have external dependencies. It uses a very simple syntax. It is very easy to set up. It has been abandoned since 2009. I have nothing to complain about.

8

Here is a list of features from mu-template. Discl.: I'm its maintainer. Template-files can be expanded: automatically when opening a new buffer (unless deactivated from the .vimrc), explicitly through menus or the command line, from the INSERT-mode in a snippet-like fashion ; from the VISUAL-mode to surround the selection with a snippet -- the surrounding ...

6

Honza's UltiSnips Snippet gentbl<number>x<number> available in the repository https://github.com/honza/vim-snippets/blob/master/UltiSnips/tex.snippets Using this snippet which uses the python interpolation feature of UltiSnips, you can enter e.g. gentbl5x3<tab> which will expand to \begin{tabular}{||||} & & \\ & &...

5

readtags universal-ctags provide readtags to filter tags: Read all members of a struct: readtags -Q '(and (eq? $kind "member") (eq?$scope-name "struct_name") )' -l (and (...) (...)): (...) and (...) (eq? $kind "member") restrict kind to member (eq?$scope-name "struct_name") restrict scope-name to struct_name, your tag fields must include Z for this to ...

5

SnipMate and UltiSnips are the two most popular snippet engine for Vim. Both are inspired from TextMate's snippet syntax. UltiSnips can run all SnipMate snippets but also have additional syntax to make it more powerful. A good rule of thumb is that if your Vim has python support, then use UltiSnips. If not, then use SnipMate. In my .vimrc, I load (using ...

5

You could probably implement this as a snippet by leveraging Ultisnips's Interpolation feature (VimCasts demo). As an alternative, I whipped up a simplistic function to generate a matrix template on the current line per your sample: function! CreateMatrix(rows, ...) abort let cols = a:0 ? a:1 : 3 let matrix = ['\begin{bmatrix}'] call extend(matrix, ...

4

I came across a solution that suits me well, it may be useful for you also. I add some mappings/abbreviations in insert mode starting with \ (or any character you like, and use not all the time): " use an abbreviation (css debugging) iabbrev \r *{color: red !important;} " use a mapping (html doctype insertion) inoremap \doctype <!DOCTYPE map PUBLIC "-//...

3

When you register it this way, your new autocommand will be triggered after all other autocommands registered on the same event, in particular after the one that sources your ftplugin -- I suppose you define the mapping in an ftplugin (*). You could change that, probably by changing the order between this line and the :filetype xxxx in your .vimrc, but this ...

3

The inoremap <expr><TAB> ... also has a <Plug>-mapping on the right-hand side of the mapping. These mappings only get expanded when you use :imap. So, though you should normally use :noremap, this is one exceptional case where you need to allow recursive mappings.

3

As multiple people have said in various comments, check out :h skeleton. This sounds like just what your looking for. However if you want a little more customizability you can try the following... Detecting when a file is "created" might be hard, since vim creates files by writing buffers to files. But you can detect when you write to a file with the ...

2

Discl. I'm maintaining an alternative to c.vim. As such, I don't use it and I don't know its intricacies. If you've installed c.vim into ~/.vim/cvim and if by % vim ~/.vim/cvim/c-support/templates/Templates you are editing the original files shipped with the plugin, it's probably a bad idea. Indeed, next time you'll update the plugin, you'll lose all your ...

2

It's because you indent the snippet options ('keywords'), by not following the help example (:h neosnippet-snippet-syntax). So, you need: snippet stdlib options head alias std #include<stdlib.h>${0} BTW, I'm not sure if${0} is needed at all, in this example.

2

You can manually fix the indent by typing CTRL-F (this is documented at :help indentkeys-format). Thus, an autonomous solution would be to issue this key-press after snippet expansion. global !p def fix_indent(snip): vim.eval('feedkeys("\<c-f>")') endglobal post_expand "fix_indent(snip)" snippet it "Individual item" b \item $0 endsnippet 2 All you need to do is to insert a \ before the <tab> Now the code will look like this instead: execute "normal! o\<tab>" 1 At this time, I have something extremely similar in my lh-cpp plugin for C++. Within a class context, I type :Constructor init, and my plugin will fetch all the member data (thanks to the API of two other plugins of mine: lh-dev + lh-tags) and generate the constructor. We aren't far from what you wish to accomplish. The first step will be to extract the ... 1 UltiSnips#SnippetsInCurrentScope return all snippets whose trigger matches the current word, I think the match here means =~, not ==. You need to check word before cursor and the triggers by yourself: function! s:is_ultisnips_expandable() " get word before cursor let word = matchstr(getline('.'), printf('\v\w*%%%dc\w', col('.') - 1)) if(empty(word)) ... 1 Try this: snippet guard "add guard to functions" b if !exists('*!p snip.rv = re.search('\S+\s+(\S+)\(', snip.v.text.splitlines()[0]).group(1)')${VISUAL} endif ${0:jump here <C-j>} endsnippet The !p snip.rv = ... part is a python interpolation. The evaluation of the expression to the right of the assignment operator after snip.rv replaces ... 1 The answer is synchronized placeholders; I just couldn't find anything online/in the manual because I didn't know the terminology. The correct snippet would be: snippet thing abbr thing #ifndef THING_${1:something}_H #define THING_$1_H #include <something.h> BEGIN_DECLS // ... END_DECLS #endif /* THING_$1_H */ For ...

1

There exist many ways to define snippets for control statements: via abbreviations or via snippets. I remember a Q/A about abbreviations versus snippet plugins. TL;DR: We can achieve the same things with both. The main difference is that snippet plugins provide a much simpler way to define maintainable code snippets. For instance, in my lh-cpp plugin you ...

1

This answer was actually provided by the author himself. In his own words: It seems like a common enough problem that someone should have addressed it. But apparently, not yet. It is necessary to map a solution, and here are a some of the possibilities: inoremap <C-f> <esc>f>a inoremap - create a map that works in insert mode <C-f> ...

1

This should work: snippet fn option word abbr () => {} (${1}) => {${2}} You can find the necessary information if you read :h neosnippet-snippet-syntax, in particular the help under the snippet keyword option: - options [options] (Optional) Options influence the snippet behavior. The possible values are: + word This snippet expands by ...

Only top voted, non community-wiki answers of a minimum length are eligible