How to solve the collision of TAB key mapping of `UltiSnips` plugin in the Vim
Asked Answered
O

2

12

I've set the mapping keys as follows:

" Easy indent for code blocks
  nmap <tab>      v>
  nmap <s-tab>    v<
  vmap <tab>      >gv
  vmap <s-tab>    <gv

That works good. But, when I installed UltiSnips by vundle, the Tab key does't work as indent action, it will remove multi-line codes which I selected. I know this is because the default setting of UltiSnips. I would like to remain the Tab mapping for UltiSnips to trigger its functions, How do I solve the problem of using the TAB key to indent code blocks? Thanks!

Ordination answered 18/5, 2013 at 9:15 Comment(0)
F
13

Looking at UltiSnips documentation via :h UltiSnips-triggers says this:

You can define the keys used to trigger UltiSnips actions by setting global
variables. Variables define the keys used to expand a snippet, jump forward
and jump backwards within a snippet, and list all available snippets in the
current expand context. The variables with their default values are: >
   g:UltiSnipsExpandTrigger               <tab>
   g:UltiSnipsListSnippets                <c-tab>
   g:UltiSnipsJumpForwardTrigger          <c-j>
   g:UltiSnipsJumpBackwardTrigger         <c-k>

So set something like this in your ~/.vimrc` file:

let g:UltiSnipsExpandTrigger = '<f5>'

However you may want to reconsider your <tab> mappings. I suggest you remove them and use >> or << in normal mode and > or < in visual mode to do the initial indent/un-indent then repeat the action via ., the redo command. If you ever indent/un-indent too far then just undo it via u.

For more help see:

:h >>
:h .
:h u
Fimbria answered 18/5, 2013 at 15:23 Comment(2)
In my case tab collided with the supertab plugin. Note if you're using vim over putty then certain key combos may not work out of the box such as <f5> or <c-tab> in that case try something like let g:UltiSnipsExpandTrigger = '<c-j>' which also has the benefit of being more comfortable to type than <c-tab>Besprent
@PeterRincker When I use any function key e.g. <f5>, it just types <f5> while in insert mode. It works in gvim, however. But my problem with Putty persists :/Homestead
A
2

You can change the default expand trigger to other key, but I think It's better to use maps as follow:

nnoremap > v>
nnoremap < v<
vnoremap > >gv
vnoremap < <gv

It works well for me.

What's more, <Tab> remove multi-line codes which you selected is a feature of UltiSnips. You can use selected text in UltiSnips snippets. Have a look at here.

Azriel answered 3/10, 2017 at 9:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.