Last active
April 21, 2020 02:13
-
-
Save bfrg/2b91d647746b24bb9478b162416f323e to your computer and use it in GitHub Desktop.
More intelligent :help that automatically splits vertically when it makes more sense
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" in file ~/.vim/autoload/vim.vim | |
function! vim#help(arg) | |
let cmd = winwidth(0) * 2 < winheight(0) * 5 ? '' : 'vertical' | |
" Vim escapes special characters, therefore we need to remove backslash, | |
" otherwise it will jump to the wrong help tag, for example, :h | and :h \| | |
" Make sure characters inside [] are in correct order, see E944 | |
let arg = substitute(a:arg, '\\\ze[ !#$%''*+-<[`{|]', '', 'g') | |
try | |
execute cmd 'help' arg | |
catch /^Vim\%((\a\+)\)\=:E149:/ | |
" Need to redraw or the echo'd message is not visible when the function | |
" is called from visual mode, see :help :echo-redraw | |
redraw | |
echohl ErrorMsg | |
echomsg 'E149: Sorry, no help for ' .. arg | |
echohl None | |
endtry | |
endfunction | |
" in file ~/.vim/after/ftplugin/vim.vim | |
setlocal keywordprg=:Vimhelp | |
command! -buffer -nargs=? -complete=help Vimhelp call vim#help(<q-args>) | |
let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'execute') .. ' | setlocal keywordprg< | delcommand Vimhelp' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment