NinmiM to Neovim · 4 years agoGeneral Neovim Lua config help threadmessage-squaremessage-square4fedilinkarrow-up19arrow-down11file-text
arrow-up18arrow-down1message-squareGeneral Neovim Lua config help threadNinmiM to Neovim · 4 years agomessage-square4fedilinkfile-text
minus-squarecheer@lemmy.mllinkfedilinkarrow-up3·edit-24 years agoI don’t use CoC and I don’t know every Lua API function so this might be clunky, but the following works on my machine: function _G.show_documentation() local ft = vim.bo.filetype local cword = vim.fn.expand('<cword>') if ft == 'help' or ft == 'vim' then vim.fn.execute('help ' .. cword) --[[ elseif vim.fn['coc#rpc#ready']() then vim.fn.call('CocActionAsync', {'doHover'}) ]] else vim.fn.execute(vim.o.keywordprg .. ' ' .. cword) end end vim.api.nvim_set_keymap('n', 'K', "<Cmd>call v:lua.show_documentation()<CR>", {noremap = true, silent = true}) Note that I commented out the elseif statement since I don’t have CoC and the function fails if it can’t call coc#rpc#ready.
minus-squareNinmiOPMlinkfedilinkarrow-up2·edit-24 years agoThank you! I’m gonna study this well before I copy paste time around. E: it works! Somehow the Lua version is easier to read and understand as well.
minus-squarecheer@lemmy.mllinkfedilinkarrow-up2·4 years agoGlad to hear it! Had to go digging though the help pages to find out what expand() did in the original and how to get the word under the cursor in Lua
I don’t use CoC and I don’t know every Lua API function so this might be clunky, but the following works on my machine:
function _G.show_documentation() local ft = vim.bo.filetype local cword = vim.fn.expand('<cword>') if ft == 'help' or ft == 'vim' then vim.fn.execute('help ' .. cword) --[[ elseif vim.fn['coc#rpc#ready']() then vim.fn.call('CocActionAsync', {'doHover'}) ]] else vim.fn.execute(vim.o.keywordprg .. ' ' .. cword) end end vim.api.nvim_set_keymap('n', 'K', "<Cmd>call v:lua.show_documentation()<CR>", {noremap = true, silent = true})
Note that I commented out the elseif statement since I don’t have CoC and the function fails if it can’t call
coc#rpc#ready
.Thank you! I’m gonna study this well before I copy paste time around.
E: it works! Somehow the Lua version is easier to read and understand as well.
Glad to hear it! Had to go digging though the help pages to find out what expand() did in the original and how to get the word under the cursor in Lua