My nvim setup

I use vim btw
Mon Feb 19, 2024
587 Words

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 definition
  • ctrl + 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.
  • tab - go forward
    • If you used ctrl + o to go back you can use tab to go forward.
  • ctrl + e - Open NERDtree and focus on it
  • \ + f - Formats the file
  • shift + k - Shows the documentation for the hovered code
  • \ + r + n - Renames the hovered variable/function
  • ctrl + w + v - Creates a vertical split with the same file
  • ctrl + w + s - Creates a horizontal split with the same file
  • g + t - Next tab
  • g + T - Previous tab

Visual Mode

  • ctrl + v - Visual block
  • shift + i - Edit multiple lines

My Plugins

I try to avoid bloating my setup so I only have a few plugins installed.

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.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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