Add do#show_documentation() using coc.nvim

Change the `K` normal mode overrides to use the example given in the
coc.nvim README file which uses Vim's builtin help when in `vim` or
`help` files, or checks if coc.nvim is ready and invokes
`CocActionAsync('doHover')`, otherwise fallback to using `keywordprg`.
This commit is contained in:
Kenneth Benzie 2021-02-22 20:48:33 +00:00
parent ecd8659df7
commit 3a2337cd63
6 changed files with 17 additions and 17 deletions

View File

@ -15,5 +15,3 @@ nnoremap K :YcmCompleter GetDoc<CR>
let b:surround_{char2nr("t")} = "TODO(\r):"
" "ys{motion}/" turns "text" into "/*text*/"
let b:surround_{char2nr("/")} = "/*\r*/"
" Map K to get YouCompleteMe documentation.
nnoremap K :YcmCompleter GetDoc<CR>

View File

@ -1,5 +1,3 @@
" Add Doxygen documentation generation plugin.
packadd DoxygenToolkit.vim
nnoremap <leader>d :Dox<CR>
" Map K to get YouCompleteMe documentation
nnoremap K :YcmCompleter GetDoc<CR>

View File

@ -25,6 +25,3 @@ setlocal encoding=utf-8
" Set up file format
setlocal fileformat=unix
let g:python_highlight_all=1
" Mappings
nnoremap K :YcmCompleter GetDoc<CR>

View File

@ -1,9 +1,6 @@
" Add omnifunc completion package.
packadd vimomni
" Mapping for Vim help of the word under cursor.
nnoremap K :help <C-r><C-w><CR>
" Set custom fold expression
setlocal foldmethod=expr
setlocal foldexpr=VimFold(v:lnum)

View File

@ -100,3 +100,14 @@ endfunction
" A sink for mappings to do nothing
function! do#sink() abort
endfunction
" Used by normal mode K mapping to show documentation
function! do#show_documentation()
if index(['vim','help'], &filetype) >= 0
execute 'help '.expand('<cword>')
elseif coc#rpc#ready() " TODO: Check if the LS supports doHover
call CocActionAsync('doHover')
else
execute '!'.&keywordprg.' '.expand('<cword>')
endif
endfunction

View File

@ -1,9 +1,10 @@
" coc.nvim
nmap <leader>fi <Plug>(coc-fix-current)
nmap <leader>gd <Plug>(coc-definition)
nmap <leader>gt <Plug>(coc-type-definition)
nmap <leader>sd <Plug>(coc-diagnostic-info)
nmap <leader>gr <Plug>(coc-references)
nnoremap <silent> <leader>fi <Plug>(coc-fix-current)
nnoremap <silent> <leader>gd <Plug>(coc-definition)
nnoremap <silent> <leader>gt <Plug>(coc-type-definition)
nnoremap <silent> <leader>sd <Plug>(coc-diagnostic-info)
nnoremap <silent> <leader>gr <Plug>(coc-references)
nnoremap <silent> K :call do#show_documentation()<CR>
if has('nvim')
" Make nvim :terminal more like vim :terminal
@ -110,8 +111,6 @@ nnoremap <C-s> i<C-g>u<C-X>s
" Disable 'Q' from opening Ex mode
nnoremap Q <nop>
" Disable 'K' from loading man pages
noremap K <nop>
" Split line at the cursor
nnoremap [j i<CR><Esc>