# Tag Info

## Hot answers tagged plugin-ultisnips

27

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 ...

18

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.

9

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 ...

8

Currently there is no way to do this in UltiSnips. There is an open feature-request on Github for it though. Personally, I would like an alias functionality for triggers as indicated here too. Let's hope SirVer (the maintainer of UltiSnips) will think so too and include it in the future :)

6

I think you can get the same result as in the video with this code: ${1/(".*)|.*/(?1:comment => )/}${1:"some comment"}${1/(".*)|.*/(?1:, )/} It can be broken down into 3 parts: ┌ mirror of tabstop n°1 │ ┌ substitution ┌─┤┌─────────────────────────┤ (A)${1/(".*)|.*/(?1:comment => )/} ┌ tabstop n° 1 ...

6

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

Although there is no specific syntax for aliases you can achieve the same effect by using post_jump: # c.snippets global !p def expand(snip): if snip.tabstop != 1: return vim.eval('feedkeys("\<C-R>=UltiSnips#ExpandSnippet()\<CR>")') endglobal snippet incstdlib "#include <stdlib.h>" !b #include <stdlib.h> /* exit(), ...

5

The codes which keys produce varies wildly by terminal. vim tries to guess which escape sequences corresponds to which keycodes (<f1> etc) based on the $TERM variable and terminfo. The shifted f-keys are not standardized and they do not have termcap/terminfo entries. In this case, vim falls back to the xterm ones. Note, wherever ^[ is written, this ... 4 If your template expander plugin doesn't support snippets local to the current buffer, i.e. if b:UltiSnipsSnippetDirectories is not understood in your case, you can ask the maintainers to use this variable if defined, or the global one otherwise -- this is the best course of action or you can use another snippet engine that supports local snippets or you ... 4 It's difficult to point out where your problem is, since you didn't really describe what exactly you did; but this is how I added a custom PHP snippet file: I installed http://github.com/SirVer/ultisnips and http://github.com/honza/vim-snippets I created ~/.vim/UltiSnips/php.snippets with the contents: extends php, html snippet 42 The universe, life, and ... 4 From :help UltiSnips-adding-snippets (section 4.1): UltiSnips iterates over the snippet definition directories looking for files with names of the following patterns: ft.snippets, ft_*.snippets, or ft/*, where "ft" is the 'filetype' of the current document and "*" is a shell-like wildcard matching any string including the empty string. The ... 4 Use remap to trigger expansion imap "prg prg<c-a> or exe printf('imap "prg prg%s', g:UltiSnipsExpandTrigger) But not this: imap <expr> "prg 'prg' . g:UltiSnipsExpandTrigger g:UltiSnipsExpandTrigger is a variable, map won't figure out special key code of it's value for you. Manual expansion inoremap "prg prg<c-r>=UltiSnips#... 3 The problem comes from the fact that your Vim setup supports python, but python is not installed on your system. When Vim has the 'python' and/or 'python3' features enabled that means that it provides an interface to interact with python code: you can make Vim to ask the system to execute a python statement or a whole python code. Even if the interface is ... 3 First of all :h UltiSnips-snippet-search-path tells us: Snippet definition files are stored in snippet directories. A snippet directory must be a subdirectory of a directory defined in the 'runtimepath' option. Which makes me think that you can not create snippets directories anywhere since that would mean constantly add your current path to ... 3 Apparently Ultisnips only does this for tab as early adopters of the plugin complained that it broke supertab. It's worth asking the maintainer whether he'd be willing to fix this for <CR> too. That being said, there is a workaround that's described in the docs: let g:ulti_expand_or_jump_res = 0 "default value, just set once function! ... 3 You want to use UltiSnipsAddFiletypes. As the docs say: The UltiSnipsAddFiletypes command allows for explicit merging of other snippet filetypes for the current buffer. For example, if you edit a .rst file but also want the Lua snippets to be available you can issue the command > :UltiSnipsAddFiletypes rst.lua To automatically set the filetype ... 3 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

UltiSnips has the extends keyword. You pass a comma separated list of filetypes to it and it will load the snippets for those filetypes before the snippets in the file the keyword is used in. Example: extends c, obj-c This way you can have a "cpp.snippets" file which "extends" your c filetype and obj-c type. The documentation doesn't mention cyclic ...

2

Unfortunately <c-i> and <tab> are parsed as the exact same key by most terminals. You can follow a discussion about this on this neovim issue: https://github.com/neovim/neovim/issues/176 The easiest solution is to pick a different mapping for jumping backwards, like <leader>i. If you really want this fixed, I suggest following the linked ...

2

I don't think you have to do that for Pathogen + UltiSnips + vim-snippets. I have such setup and only thing in my vimrc is let g:UltiSnipsExpandTrigger="<c-j>". Both plugins are in ~/.vim/bundle.

2

From documentation on :nnoremap: :no[remap]! {lhs} {rhs} […] Disallow mapping of {rhs}, to avoid nested and recursive mappings. But the whole point of your mapping is to use recursive mapping of Tab! Use :nmap instead. Alternatively, and even preferably, use the following: nnoremap KEYCOMBO iULTISNIPTRIGGER <esc>:call UltiSnips#ExpandSnippet(...

2

g:UltiSnipsSnippetDirectories are used to search snippets, it's default to ['UltiSnips'], there are 2 kinds of settings: relative path let g:UltiSnipsSnippetDirectories = ['UltiSnips','foo'] UltiSips will loop each path in runtimepath to search for child directory named UltiSnips and foo, and use them as snippets source. Note that "snippets" is reserved ...

2

I add my comment as answer with the complete snippet file. Negative Lookbehind Assertion in Python Regular Expressions Python documentation: https://docs.python.org/3/library/re.html#index-23 (?<!...) Important limitation: Similar to positive lookbehind assertions, the contained pattern must only match strings of some fixed length. Patterns which ...

2

I use <esc>A, it's 2.5 key strokes(0.5 for shift), it's not the shortest solution, but it's the most natural one if you are used to move around in normal mode. IMO, <esc> doesn't count as a keystroke. <c-o>A works too, but I don't like it, I can't remember the last time i use :h i_CTRL-O . You can also create a map for this: inoremap <...

2

I do not know whether you have found a solution in the mean time, but according to this post https://stackoverflow.com/questions/606191/convert-bytes-to-a-string you have to decode the bytes object, so that the snippet becomes: snippet 'math(.*)math' "math" wr `!p import subprocess code = match.group(1) code = 'ToString[' + code + ',TeXForm]' res = ...

2

Thanks to husB for point me the dynamic tabstop generation, i don't know why it isn't in the doc. The final snippet: global !p def create_line_plhldr(snip): num = int(snip.buffer[snip.line].strip()) snip.buffer[snip.line] = '' anon_snippet_body = '${1:unidad}.${2:ejercicio} )' for var in range(2, int(num)+1): anon_snippet_body +=...

2

From this video: UltiSnips evaluates each text object that might have a dependency on some types of text multiple times, to make sure that all dependencies are properly updated. To prevent the date from being updated several times, you could switch to a python interpolation, and use the guard if not snip.c. For example, you could replace this: ** ...

2

It seems that when you copied the snippet you forgot to add the indentation spaces in the python snippet conditional code as shown in the error message: Executed snippet code: 1 2 if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']: 3 snip.rv = ' ' 4 else: 5 snip.rv = '' 6 Try to change it to: snippet im "create an inline ...

2

Put the check in a function so it’s not a mess: function react#add_snips() abort if search('styled-components', 'nw') != 0 UltiSnipsAddFiletypes css endif endfunction (This can go in ~/.vim/autoload/react.vim) And then call the function: augroup react autocmd! autocmd Filetype javascript,typescript call react#add_snips augroup END Alternatively,...

1

This is because of this line in UtliSnips documentation: UltiSnips comes without snippets. The default snippets can be found here: https://github.com/honza/vim-snippets UltiSnips is just an engine, you need to install/create own snippets. I use those recommended vim-snippets and they work like a charm.

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