Vim Resources
Vim is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is included as "vi" with most UNIX systems and with Apple macOS.
Table of Contents
Getting Started
Verify the installation
Repository : extra
Name : vim
Version : 8.1.1073-1
Description : Vi Improved, a highly configurable, improved version of the vi text editor
Architecture : x86_64
URL : https://www.vim.org
Licenses : custom:vim
Groups : None
Provides : xxd vim-minimal vim-python3
Depends On : vim-runtime=8.1.1073-1 gpm acl glibc libgcrypt pcre zlib libffi
Optional Deps : python2: Python 2 language support
python: Python 3 language support
ruby: Ruby language support
lua: Lua language support
perl: Perl language support
tcl: Tcl language support
Conflicts With : gvim vim-minimal vim-python3
Replaces : vim-python3 vim-minimal
Download Size : 1445.23 KiB
Installed Size : 3532.00 KiB
Packager : Levente Polyak <anthraxx@archlinux.org>
Build Date : Fri 29 Mar 2019 04:08:59 PM EDT
Validated By : MD5 Sum SHA-256 Sum Signature
Verify it by calling vim command.
Install vim-plug
Download vim-plug and move plug.vim to ~/.vim/autoload directory
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
Install COC
You can follow the guide in the official github page for the latest instruction, but, to save your time, i’ll give it below. Although, it will not be guaranteed for future releases.
- Make sure you have nodeJS ≥ 8.0, or else download it via the command below.
- Install yarn.
- Create directory for COC’s installation.
mkdir -p ~/.vim/pack/coc/start
- Clone COC’s repo.
cd ~/.vim/pack/coc/start
git clone https://github.com/neoclide/coc.nvim.git --depth=1
- Install COC.
cd ~/.vim/pack/coc/start/coc.nvim
yarn install
- Add Plug for COC. Open
~/.vimrc in editor and add the lines below.
call plug#begin()
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
call plug#end()
- Open vim and execute
:PlugInstall in the command-line mode.
COC Extension
The last steps is the installation of the language server you want to use with the code-completion.
You can see the list of available extensions here. Make sure to follow the requirements of the extensions you want to install as they’re different with each other.
For this example, I will use Python language server.
- Execute
:CocInstall coc-python in the vim’s command-line mode.
- Open Vim with any Python code:
vim test.py and see if the code-completion works.
To manage the extensions you can read the guide in the official page.
Custom Language Servers
If your favorite language server is not available yet. You can add custom language server in your coc-settings.json for more information click here.
{
"languageserver": {
"bash": {
"command": "bash-language-server",
"args": ["start"],
"filetypes": ["sh"],
"ignoredRootPaths": ["~"]
},
"dockerfile": {
"command": "docker-langserver",
"filetypes": ["dockerfile"],
"args": ["--stdio"]
},
"golang": {
"command": "gopls",
"rootPatterns": ["go.mod", ".vim/", ".git/", ".hg/"],
"filetypes": ["go"]
}
}
}
Configuration
There're two types of user configuration file.
-
The user configuration is named as coc-settings.json and placed inside folder $XDG_CONFIG_HOME/nvim or $HOME/.config/nvim by default(or $HOME/.vim for vim). Run command :CocConfig to open your user configuration file.
-
The workspace configuration should be named with coc-settings.json and would be resolve in directory .vim. After a file opened in vim, this directory would be resolved from parent directories of that file.
The active configuration would be a merged result from 'default', 'user' and 'workspace' configuration file, the later one have higher priority.
To enable intellisense of coc-settings.json, install json language extension coc-json by:
Key mapping
coc.nvim doesn't come with a default key mapping commands, you need to configure it yourself.
Here's a recommended configuration:
" ~/.vimrc
" Configuration for coc.nvim
" Smaller updatetime for CursorHold & CursorHoldI
set updatetime=300
" don't give |ins-completion-menu| messages.
set shortmess+=c
" always show signcolumns
set signcolumn=yes
" Some server have issues with backup files, see #649
set nobackup
set nowritebackup
" Better display for messages
set cmdheight=2
" Use <c-space> for trigger completion.
inoremap <silent><expr> <c-space> coc#refresh()
" Use <cr> for confirm completion, `<C-g>u` means break undo chain at current position.
" Coc only does snippet and additional edit on confirm.
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Use `[c` and `]c` for navigate diagnostics
nmap <silent> [c <Plug>(coc-diagnostic-prev)
nmap <silent> ]c <Plug>(coc-diagnostic-next)
" Remap keys for gotos
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Remap for do codeAction of current line
nmap <leader>ac <Plug>(coc-codeaction)
" Remap for do action format
nnoremap <silent> F :call CocAction('format')<CR>
" Use K for show documentation in preview window
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if &filetype == 'vim'
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight symbol under cursor on CursorHold
autocmd CursorHold * silent call CocActionAsync('highlight')
" Remap for rename current word
nmap <leader>rn <Plug>(coc-rename)
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
Example