4

In conjunction with https://stackoverflow.com/questions/3131393/remapping-help-in-vim-to-open-in-a-new-tab , I'm looking to also make the shift-K shortcut that opens help in a new tab.

I first tried nmap <S-K> :tab help expand("<cword>")<CR>, but it doesn't actually work - the expand is apparently taken literally as the help tag text, and is not executed.

So, how do I remap <S-K> to get help on the current word in a new tab in Vim?

Sundar R
  • 1,539

2 Answers2

10

I'm not sure what you're trying to do. <s-k>, also known as K, opens the man page for the keyword under the cursor. I assume you want to create a mapping to open the vim help page for the keyword under the cursor. This can be done by this (i'll use <c-k> to not override K):

noremap <c-k> :execute "tab h " . expand("<cword>")<cr>
madmax1
  • 252
0

For the sake of anyone stumbling upon this later: I combined the two methods mentioned in @madmax1's answer and comment, to make Vim choose the appropriate method of help automatically depending on the filetype.

function! GetHelpOnCwordInTab()
    if &filetype == "vim"
        execute 'tab help ' . expand("<cword>")
    else
        execute 'tabnew <bar> read ! ' . &keywordprg . expand("<cword>")
    endif 
endfunction
autocmd FileType * nnoremap <C-K> :call GetHelpOnCwordInTab()<CR>

(I had to take @madmax1's suggestion on keymapping too (C-K instead of S-K) because Scriptease has an autocmd overwriting the S-K mapping, and I'm not sure how to override that from within .vimrc.)

Sundar R
  • 1,539