Vim: map shift-K to open help on current word in a new tab
7,045
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>
Related videos on Youtube
Comments
-
Sundar R over 1 year
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 - theexpand
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 over 8 years"<s-k>, also known as K, opens the man page" <- This is actually incorrect: it opens whatever the current
keywordprg
program is, depending on the filetype; its default isman
, but thekeywordprg
automatically changes to:help
when in a vimscript file, and can be set to for eg.perldoc -f
for filetype perl, to automatically get perldoc help within Perl files whenK
is pressed. -
Sundar R over 8 yearsWhat I wanted was a way to take this whole thing and just add the feature of opening the output in a new tab. Your
execute
idea did help me make this work just for vim keywords at least, so I'll accept your answer and split the question about making this portable for any value ofkeywordprg
a separate question (since that looks to be a more complicated requirement). -
madmax1 over 8 yearsI see what you are trying to do. You can achieve this with this mapping (i'll use <c-k> again):
nnoremap <c-k> :execute 'tabnew <bar> read !' . &keywordprg . ' ' . expand("<cword>")<cr>