My nvim setup
I use vim btw
Mon Feb 19, 2024
513 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.

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