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?

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.

  • "I used nmap here instead of nnoremap, because <Nop> 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: learnvimscriptthehardway.stevelosh.com/chapters/… – filbranden Aug 7 at 1:27
  • 1
    @filbranden You're right! I rolled my edit back :) – ruohola Aug 7 at 5:39
  • 1
    👍 That's much better, thanks! – filbranden Aug 7 at 5: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>
  • 1
    Any reason not to use nnoremap? – D. Ben Knoble Aug 6 at 13:03
  • @D.BenKnoble I believe <Nop> cannot be remapped, so there's absolutely no reason to use nnoremap. – Matt Aug 6 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.