vim: Tagbar windows opened when typing <Enter> in normal mode

299 views Asked by At

When typing <Enter> in normal mode in Vim with the Tagbar plugin installed, the Tagbar window is opened automatically. I want to disable this functionality. What must I do?

3

There are 3 answers

2
shender On BEST ANSWER

Your mapping for <C-m> is actually the cause of the Enter key opening Tagbar. If you remove that map from your vimrc, the enter key will no longer trigger :TagbarToggle.

Mappings for <C-m> and <CR> (Enter) are synonymous in Vim:

The following table shows the mapping between some of the keys on the keyboard and the equivalent Ctrl-key combination:

Ctrl-I Tab
Ctrl-[ Esc
Ctrl-M Enter
Ctrl-H Backspace

If you use one of the Ctrl-key combination in the above table in a map, the map also applies to the corresponding key. Both the keys produce the same key scan code. For example, if you create a map for CTRL-I, then you can invoke the map by pressing Ctrl-I or the Tab key.

This means when you set nmap <C-m> :TagbarToggle<CR>, it is the same as also setting nmap <CR> :TagbarToggle<CR>.

You'll probably want to choose a new key instead of M. The alternative is to change the key code sent by <C-m> at the operating system level with some remapping program.

The terminal key bindings come from readline, the program that processes input text in your terminal prompt. A full list of key bindings is in the readline manual.

You can find more info about Vim key codes by typing :help keycodes in Vim, or reading the help docs here.

1
j4g0 On

Try :help tagbar to open the documentation. It sounds like you might have a mapping in your vimrc file that says something like

nnoremap <silent> <CR> :TagbarToggle<CR>

or

nnoremap <silent> <CR> :TagbarOpen<CR>

if you find and remove that mapping will no longer open Tagbar

0
Threarly Chiang On

put the flowing code in you .vimrc

unmap <cr>