# coc 插件配置 coc插件原理 vscode 补全利用的是LSP (language server protocol), 简单理解就是编辑时启动一个进程,补全果过程就类似app请求服务器得到补全数据。这就是为什么要装node,服务进程都是node启动。 # 第一步 安装nvim 首先你需要 安装vim8 或者nvim 我测试的是macos 如果是nvim, 需要把nvim 的配置文件做一次软链接指向 ~/.vimrc 这是延续以前的vim配置方式, 不做的话,只能修改init.vim , nvim的配置默认读取这个文件。 以下下提到的都是nvim,我在/etc/profile alias vim="nvim" 了 ln -s ~/.config/nvim/init.vim ~/.vimrc
12# 第二步 安装nvim插件管理器 Vim-plug curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
1打不开这个域名,可以直接去github搜索plug.vim ,手动复制下来. # 第四步 如何安装php补全插件 各种语言coc扩展这里有 (opens new window)
coc-phpactor 是php7以上才可以用
coc-phpls 一般都用这个
第一步 需要安装Intelephense
npm i intelephense -g
1 第二步打开vim, 安装coc-phpls
CocInstall coc-phpls
1 第三步 配置php language server (opens new window)
vim : CocConfig 会默认打开一个配置文件 ```
{
"languageserver": {
"intelephense": {
"command": "intelephense",
"args": ["--stdio"],
"filetypes": ["php"],
"initializationOptions": {
"storagePath": "/Users/kunming/php/"
}
}
}
```
这里外面的intelephense表示配置的名称 command里面的intelephense是一个文件 args 表示可执行文件后面的参数 比如你打开一个php文件,ps命令可以看到系统会启动一个进程 node /usr/local/bin/intelephense --stdio 有一个索引js的进程/usr/local/bin/node --no-warnings /Users/kunming/.SpaceVim/plugged/coc.nvim/build/index.js node还会启动一个进程类似这样/usr/local/Cellar/node/14.1.0/bin/node /Users/kunming/.config/coc/extensions/node_modules/coc-phpls/node_modules/intelephense/lib/intelephense.js --node-ipc --clientProcessId=72264 filetypes 指定了对php文件有效 storagePath 表示初始化信息存储的位置,据我观察应该是打开一个文件,进程为php建立补全信息建立的索引日志文件,安装intelephense,会附带好多php文件,常见的php库,也是为了建立索引用的,初次编辑一个php文件,这个目录会有28872930这样的文件夹。 mac上貌似只有你在storagePath目录下建立的php文件或者项目,vim编辑才会出现补全提示,在别的目录是没有提示的,这一点研究了好久才感觉出来,文档也没说这些 centos7下面貌似没这些问题, 都可以提示出来,可以不配置CocConfig。 # 其余插件,我只安装了go的coc扩展和coc的python扩展,go需要fatih/vim-go来支持 同样每次编辑他们的文件都会启动一个类似node进程/usr/local/bin/node --no-warnings /Users/kunming/.SpaceVim/plugged/coc.nvim/build/index.js 都是一个套路: 1.找到所需的插件,比如coc-python 安装他需要的依赖,一般插件后面会提到 vim中安装coc扩展 CocInstall coc-python vim来打配置CocConfig,添加对应语言的server配置 所以LSP是一个cs结构的,有服务端也就是node进程, 客户端就是vim编辑器 set nu
set ts=4
set shiftwidth=4
set expandtab
set autoindent
" 插件列表
call plug#begin('~/.config/nvim/plugged')
" 功能相关
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
call plug#end()
let s:script_cwd = expand('
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" tab 补全
" TextEdit might fail if hidden is not set.
"set hidden
" Some servers have issues with backup files, see #649.
"set nobackup
"set nowritebackup
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=100
" Don't pass messages to |ins-completion-menu|.
"set shortmess" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("patch-8.1.1564")
" Recently vim can merge signcolumn and number column into one
set signcolumn=number
else
set signcolumn=yes
endif
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap
" other plugin before putting this into your config.
inoremap
\ pumvisible() ? "\
\
\ coc#refresh()
inoremap
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use
if has('nvim')
inoremap
else
inoremap
endif
" Use
" position. Coc only does snippet and additional edit on confirm.
"
if exists('*complete_info')
inoremap
else
inoremap
endif
" Use `[g` and `]g` to navigate diagnostics
" Use `:CocDiagnostics` to get all diagnostics of current buffer in location list.
nmap
nmap
" GoTo code navigation.
nmap
nmap
nmap
nmap
" Use K to show documentation in preview window.
nnoremap
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap
" Formatting selected code.
xmap
nmap
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Applying codeAction to the selected region.
" Example: `
xmap
nmap
" Remap keys for applying codeAction to the current buffer.
nmap
" Apply AutoFix to problem on the current line.
"nmap
" Map function and class text objects
" NOTE: Requires 'textDocument.documentSymbol' support from the language server.
xmap if
omap if
xmap af
omap af
xmap ic
omap ic
xmap ac
omap ac
" Use CTRL-S for selections ranges.
" Requires 'textDocument/selectionRange' support of LS, ex: coc-tsserver
nmap
xmap
" Add `:Format` command to format current buffer.
command! -nargs=0 Format :call CocAction('format')
" Add `:Fold` command to fold current buffer.
command! -nargs=? Fold :call CocAction('fold',
" Add `:OR` command for organize imports of the current buffer.
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
" Add (Neo)Vim's native statusline support.
" NOTE: Please see `:h coc-status` for integrations with external plugins that
" provide custom statusline: lightline.vim, vim-airline.
set statusline^=%{coc#status()}%{get(b:,'coc_current_function','')}
" Mappings for CoCList
" Show all diagnostics.
nnoremap
" Manage extensions.
nnoremap
" Show commands.
nnoremap
" Find symbol of current document.
nnoremap
" Search workspace symbols.
nnoremap
" Do default action for next item.
nnoremap
" Do default action for previous item.
nnoremap
" Resume latest coc list.
nnoremap
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176