3

I've mapped 'L' and 'H' to change buffers in vim. I often end up hitting these keys in NERDTree and Tagbar.

I'm able to use NERDTreeAddKeyMap to make NERDTree ignore keys. Tagbar only allows the use of g:tagbar_map_.* to replace key bindings that exist.

Is there a way I can make 'H' and 'L' do nothing in the Tagbar?

ruohola
  • 666
  • 5
  • 20
Scoobie
  • 131
  • 3

2 Answers2

3

You can use a FileType autocmd and map those keys to <Nop>:

augroup TagBar
    autocmd!
    autocmd FileType tagbar nnoremap <buffer> H <Nop>
    autocmd FileType tagbar nnoremap <buffer> L <Nop>
augroup END

Also always remember to enclose your autocmds with a augroup.

ruohola
  • 666
  • 5
  • 20
  • "I used nmap here instead of nnoremap, because cannot be remapped." Use non-recursive mappings by default. Only use recursive ones when you really need them (which is not the case here.) Get into the habit of always using non-recursive mappings. See also excellent advice here: http://learnvimscriptthehardway.stevelosh.com/chapters/05.html#nonrecursive-mapping – filbranden Aug 07 '19 at 01:27
  • 1
    @filbranden You're right! I rolled my edit back :) – ruohola Aug 07 '19 at 05:39
  • 1
    That's much better, thanks! – filbranden Aug 07 '19 at 05:41
0

You can easily do this with <buffer>-specific mappings. Like this:

autocmd FileType tagbar nmap <buffer>H <Nop>
autocmd FileType tagbar nmap <buffer>L <Nop>
Matt
  • 20,685
  • 1
  • 11
  • 24