From 3a2337cd630825c8459e64ab5567a8d63a99d314 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Mon, 22 Feb 2021 20:48:33 +0000 Subject: [PATCH] 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`. --- after/ftplugin/c.vim | 2 -- after/ftplugin/cpp.vim | 2 -- after/ftplugin/python.vim | 3 --- after/ftplugin/vim.vim | 3 --- autoload/do.vim | 11 +++++++++++ plugin/mappings.vim | 13 ++++++------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/after/ftplugin/c.vim b/after/ftplugin/c.vim index c2145ba..dbd2fea 100644 --- a/after/ftplugin/c.vim +++ b/after/ftplugin/c.vim @@ -15,5 +15,3 @@ nnoremap K :YcmCompleter GetDoc 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 diff --git a/after/ftplugin/cpp.vim b/after/ftplugin/cpp.vim index 5ae0746..8dffb38 100644 --- a/after/ftplugin/cpp.vim +++ b/after/ftplugin/cpp.vim @@ -1,5 +1,3 @@ " Add Doxygen documentation generation plugin. packadd DoxygenToolkit.vim nnoremap d :Dox -" Map K to get YouCompleteMe documentation -nnoremap K :YcmCompleter GetDoc diff --git a/after/ftplugin/python.vim b/after/ftplugin/python.vim index 68da4dd..9917a89 100644 --- a/after/ftplugin/python.vim +++ b/after/ftplugin/python.vim @@ -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 diff --git a/after/ftplugin/vim.vim b/after/ftplugin/vim.vim index 771dc9c..c66d826 100644 --- a/after/ftplugin/vim.vim +++ b/after/ftplugin/vim.vim @@ -1,9 +1,6 @@ " Add omnifunc completion package. packadd vimomni -" Mapping for Vim help of the word under cursor. -nnoremap K :help - " Set custom fold expression setlocal foldmethod=expr setlocal foldexpr=VimFold(v:lnum) diff --git a/autoload/do.vim b/autoload/do.vim index aca11c8..9855f11 100644 --- a/autoload/do.vim +++ b/autoload/do.vim @@ -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('') + elseif coc#rpc#ready() " TODO: Check if the LS supports doHover + call CocActionAsync('doHover') + else + execute '!'.&keywordprg.' '.expand('') + endif +endfunction diff --git a/plugin/mappings.vim b/plugin/mappings.vim index 8c3bc78..8d6b467 100644 --- a/plugin/mappings.vim +++ b/plugin/mappings.vim @@ -1,9 +1,10 @@ " coc.nvim -nmap fi (coc-fix-current) -nmap gd (coc-definition) -nmap gt (coc-type-definition) -nmap sd (coc-diagnostic-info) -nmap gr (coc-references) +nnoremap fi (coc-fix-current) +nnoremap gd (coc-definition) +nnoremap gt (coc-type-definition) +nnoremap sd (coc-diagnostic-info) +nnoremap gr (coc-references) +nnoremap K :call do#show_documentation() if has('nvim') " Make nvim :terminal more like vim :terminal @@ -110,8 +111,6 @@ nnoremap ius " Disable 'Q' from opening Ex mode nnoremap Q -" Disable 'K' from loading man pages -noremap K " Split line at the cursor nnoremap [j i