Search code examples
vimparameterscode-snippetsvim-plugin

snippet in vim - any option to go back to the previous parameter?


I am using neocomplcache along with neosnippet and honza's vim-snippets. They are great, except that when I press Ctrl-k, I can go to the next parameter, but I have no way to go back to the previous parameter.

So for example, if I inserted 'for' snippet and made a typo on the index variable, but I already pressed Ctrl-k, am I screwed? Must I go through modifications of all the parameters and then come back to do replace operation? Or is there mapping for select mode that I can help me in this situation? Currently Tab and S-Tab do not do anything.

Lastly, are all snippet plugins like this? Or is neocomplcache just missing this feature (out of the box, at least)?


Solution

  • I encourage you to try UltiSnips. It is much more powerful and mature than vim-snippets or neosnippet. For instance, since UltiSnips is based on Python, it is very extensible. Concerning your problem: yes, you can jump back and forth with UltiSnips. Finally, be sure to check out screencasts (listed in the link) to see all the fancy stuff you can do with it.

    For example, I use the following configuration:

    let g:UltiSnipsSnippetsDir        = '~/.vim/snippets/'
    let g:UltiSnipsSnippetDirectories = ['UltiSnips', 'snippets']
    
    let g:UltiSnipsExpandTrigger       = '<C-CR>'
    let g:UltiSnipsJumpForwardTrigger  = '<A-d>'
    let g:UltiSnipsJumpBackwardTrigger = '<A-a>'
    

    NOTE: ~/.vim/snippets/ is my directory for custom snippets.

    As I've already mentioned UltiSnips uses Python extensively, and therefore requires Vim to be built with Python support. If you are on Windows (especially x64), that might be a trouble, the one I've run into quite some time ago. To save yourself precious time and avoid frustration you may consider downloading my Vim for Windows. Both x86 and x64 architectures are provided, and it supports both Python 2 and Python 3 simultaneously. I can assure you that it is stable. To install properly just follow the instructions. These builds are updated frequently.