25

When I use vim in normal mode, I often press the TAB key accidentally, the key TAB do the same thing as Ctrl-I in default. I want to make the key TAB do nothing, so I put this line in the vimrc file:

nmap <TAB> :echo<CR> 

Thus, the key TAB will do nothing, but this made the key Ctrl-I do nothing too. So, how to make the TAB do nothing and the Ctrl-I work well as before in vim (in normal mode) ?

tisyang
  • 303
  • 4
  • 7

3 Answers3

31

Due to the way that the keyboard input is handled internally, this unfortunately isn't generally possible today, even in GVIM. Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) This also applies to <Tab> / <C-I>, <CR> / <C-M> etc. This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals.

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • Thank you so much. I also found this impossible in this page [how to map and independently](http://vim.1045645.n5.nabble.com/how-to-map-lt-tab-gt-and-lt-c-i-gt-independently-td1185417.html). Thus I should make myself not to press the TAB key accidentally. – tisyang Feb 01 '13 at 08:22
  • Thanks for your answer. I really hope this gets sorted out soon - all the discussions seem to peter out eventually, which implies it requires a major code rethink. Here's a current(ish) thread: https://groups.google.com/d/topic/vim_dev/2bp9UdfZ63M/discussion – Prince Goulash Feb 01 '13 at 09:10
  • The current patchlevel of Vim 7.3 suggest that there'll be a new release (7.4?) soon. I hope this problem is tackled for a future Vim 8.0 then. – Ingo Karkat Feb 01 '13 at 09:18
  • I've been assuming 7.4 was around the corner since patch ~400! – Prince Goulash Feb 01 '13 at 09:22
10

I would advice to having <TAB> do something useful:

nmap <TAB> <C-W>
nmap <TAB><TAB> <C-W><C-W>

this way you can use tab for the window operations. Of course with this you cannot have the ctrl-i behavior. I map ,i for this:

nnoremap ,i <C-I>
ches
  • 6,382
  • 2
  • 35
  • 32
skeept
  • 12,077
  • 7
  • 41
  • 52
1

I found that ctrl-tab work as default ctrl-i when tab is remaped.

Works in macvim. I did not check in others vims.

Sergey Andronov
  • 173
  • 1
  • 8