Configuring Neovim

I use Neovim as my main text editor, here I will document the configuration I use for developing software using Go.

I’ve tried using “distributions” like lazy vim but I prefer creating my own init.vim with my configuration. The first thin I add is the Plug plugin manager by downloading the plug.vim file and saving it to $HOME/.config/nvim/autoload/plug.vim. This allows me to just add modules to the init.vim and Plug takes care of downloading and keeping the modules up to date.

hen I start adding the plugins to my init.vim configuration, starting by the basics: my favorite colorscheme/theme monochrome and lightline an improved status bar.

call plug#begin()
Plug 'fxn/vim-monochrome'
Plug 'itchyny/lightline.vim'
call plug#end()

" Colorscheme options
let g:monochrome_italic_comments = 1
colorscheme monochrome

The second configuration that I add is setting the spacebar as the “leader” key, I also make sure to deactivate anyother functionality assigned to the spacebar in vim’s normal mode. I also disable F1 opening neovim’s help as I like to use the F keys to control the compilers, linters and other language specific tools.

let mapleader="\<Space>"
nnoremap <SPACE> <Nop>

" Deactivate F1 as help, I use it for other stuff
map <F1> <Nop>
imap <F1> <Nop>

" Move between buffers
nnoremap <leader>bn :bnext<cr>
nnoremap <leader>bt :b#<cr>

I add the Telescope plugin to get a visual menu to search for files and Neovim buffers.

" Telescope has several plugin dependencies
call plug#begin()
Plug 'nvim-lua/plenary.nvim'
Plug 'BurntSushi/ripgrep'
Plug 'sharkdp/fd'
Plug 'nvim-treesitter/nvim-treesitter'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-tree/nvim-web-devicons'
Plug 'nvim-telescope/telescope.nvim', { 'tag': '0.1.8' }
call plug#end()


nnoremap <leader>ff <cmd>Telescope find_files<cr>
" Grep the buffer
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
" Manage buffers
nnoremap <leader>fb <cmd>Telescope buffers<cr>

Other general thing I like to include is using the leader to insert unicode characters, I use Nerdfonts in the terminal to make sure that I can display them in my terminal.

" Insert symbols for to do lists
" To do
nnoremap <leader>rt r○
" Done
nnoremap <leader>rd r✓
" Current
nnoremap <leader>rc r➤
" Failed
nnoremap <leader>rf rx

Following the basic configuration I start adding plugins and configurations for development, right now I just have it configurated for Go but I will be adding more configuration for other languages as I keep going into them (in the near future I plan to add JavaScript, TypeScript and Python.) The first thing that I add for mananging different languages is enable the included filetype plugin to use different .vim files for each language.

" Use the filetype plugin system to configure the
" different types of languages
" ~/.config/nvim/ftplugin/
filetype plugin on

For the Go specific configuration first I load the plugins that I will be using for development, starting by the general vimtest and dap with its improvement related plugins. This are added in the plug configuration of the main init.vim.

Plug 'vim-test/vim-test'
Plug 'mfussenegger/nvim-dap'
" Debug UI improvements
Plug 'nvim-neotest/nvim-nio'
Plug 'rcarriga/nvim-dap-ui'

Followed by the Go specific plugins.

Plug 'fatih/vim-go'
Plug 'sebdah/vim-delve'
Plug 'leoluz/nvim-dap-go'

I create an additional file in $HOME/.config/nvim/ftplugin/go.vim that neovim with the filetype plugin enable will autoload when opening a file of type Go. For Go I mainly setup the F keys to run tests and control the Delve debugger. I also set up F6 to submitt the Exercism exercises that I use to practice my Go and programming skills. The vim-go takes care of most of the needs for writing Go with the default configuration.

lua require('dap-go').setup()
lua require('dapconfig')

" I want real tabs in Go files
set noexpandtab

nmap <F1> <Plug>(go-test)
nmap <F2> :DlvToggleBreakpoint<CR>
nmap <F3> :DlvTest<CR>
nmap <F4> <Plug>(go-run)
nmap <F5> <Plug>(go-coverage)
nmap <F6> :!exercism submit %<CR>

2025-03-25