Setting up neovim for golang on Ubuntu 18.04

Ankit
3 min readJan 18, 2020

--

This is an update for this previous post about setting up vim for golang. I switched to neovim because I wanted autocompletion and debugger support.

Step 1: Install nvim

Follow the official instructions here.

And then add the following aliases in your .bashrc

# Map vi and vim to nvim
alias vi="nvim"
alias vim="nvim"

Step 2: Generate vim configuration

Select both go and neovim.

Use vim-bootstrap to generate a vim configuration. Open the website, select golang and nvim options and click on the Generate button. This downloads a file called generate.vim.

The default nvim configration file is: ~/.config/nvim/init.vim

So copy this generated config file using the following command. (Don’t forget to use the correct path of the downloaded file)

cp ~/Downloads/generate.vim ~/.config/nvim/init.vim

Open nvim, it will prompt you to press enter. Then it will install a bunch of plugins(this could take some time). When it’s done, restart nvim.

(Optional) Disable Parenthesis Matching

I like to disable parenthesis matching because I find it confusing. If you would like to do the same simply paste the following lines at the end of your init.vim file.

" Disable parentheses matching depends on system. This way we should address all cases (?)
set noshowmatch
" NoMatchParen " This doesnt work as it belongs to a plugin, which is only loaded _after_ all files are.
" Trying disable MatchParen after loading all plugins
"
function! g:FckThatMatchParen ()
if exists(":NoMatchParen")
:NoMatchParen
endif
endfunction
augroup plugin_initialize
autocmd!
autocmd VimEnter * call FckThatMatchParen()
augroup END

Step 3: Setup auto-completion

I use deoplete for auto-completion. Enable python 3 interface: pip3 install --user pynvim

Then, add the following line to the list of plugs in the nvim configuration file i.e. ~/.config/nvim/init.vim

Plug 'Shougo/deoplete.nvim', {'do':':UpdateRemotePlugins'}

Add the following line at the end of your vim configuration so deoplete auto-completion is enabled at vim startup.

let g:deoplete#enable_at_startup = 1

Deoplete auto-completion in Nvim

Step 4: Setup delve debugger

Install delve on you machine by following instructions here. I use vim-delve for setting up debugger support in vim. You only need to add the following plug in you vim configuration.

Plug 'sebdah/vim-delve'

Then, restart neovim and run PlugInstall command.

Now in any go file, try adding a breakpoint using DlvAddBreakpoint command. And run the program using DlvDebug command and the execution should stop at the breakpoint. You can read about the other commands and options here.

--

--