I started using vim seriously a few years ago after I graduated from university. At the time, I wanted a consistent experience between my dev environment at home and at work so I decided to give vim a try. It’s been pretty stable for work and my projects, so I wanted to share my configs and workflow for those interested in playing around with vim.
I’m currently using nvim but this setup should work with regular vim as well. I decided not to go down the lua route just to keep my configuration interchangeable between nvim and vim. I may play around with lua in the future but for now I like to keep things simple.
Useful Hotkeys
One of the benefits of using vim is the hotkey system. Here are some of my favorite hotkeys.
Normal mode:
g + d
- Jump into the definitionctrl + o
- go back- Useful if you used
g + d
to jump into a new file. You can use this hotkey to go back to the last file.
- Useful if you used
tab
- go forward- If you used
ctrl + o
to go back you can usetab
to go forward.
- If you used
ctrl + e
- Open NERDtree and focus on it\ + f
- Formats the fileshift + k
- Shows the documentation for the hovered code\ + r + n
- Renames the hovered variable/functionctrl + w + v
- Creates a vertical split with the same filectrl + w + s
- Creates a horizontal split with the same fileg + t
- Next tabg + T
- Previous tab
Visual Mode:
ctrl + v
- Visual blockshift + i
- Edit multiple lines
My Plugins
I try to avoid bloating my setup so I only have a few plugins installed.
- coc.nvim
- Hosts my language servers in a separate NodeJS process.
- vim-airline
- Pretty status/tabline
- vim-signify
- Shows my git/mercurial diffs
- fzf
- Fuzzy find for text
- nerdtree
- File navigation
The .vimrc
Here’s my vim config with some themeing settings removed. If you’re interested in seeing the full configuration you can find it on my github.
set nocompatible
filetype plugin on
syntax on
call plug#begin('~/.vim/plugged')
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'mhinz/vim-signify'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'preservim/nerdtree'
call plug#end()
" Options
set mouse=a
set encoding=UTF-8
set wildmenu wildoptions=pum
set tabstop=4
set shiftwidth=4
set signcolumn=yes
set number relativenumber
let g:NERDTreeWinPos = "right"
autocmd VimEnter * AirlineTheme serene
set fillchars+=vert:\│
let NERDTreeMinimalUI=1
au InsertEnter * set cursorline
au InsertLeave * set nocursorline
set autoread
" Maps
nmap <leader>rn <Plug>(coc-rename)
nmap <leader>f <Plug>(coc-format) :w<CR>
vmap <leader>f <Plug>(coc-format-selected)
map <C-e> :NERDTreeToggle <Esc>
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gf <Plug>(coc-references)
" Use tab to auto complete instead of <C-y>
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<TAB>"
nnoremap <silent> K :call ShowDocumentation()<CR>
function! ShowDocumentation()
if CocAction('hasProvider', 'hover')
call CocActionAsync('doHover')
else
call feedkeys('K', 'in')
endif
endfunction
nmap <silent> sg :call ToggleColGuide()<CR>
function! ToggleColGuide()
if &colorcolumn == ""
set colorcolumn=80
else
set colorcolumn=""
endif
endfunction