Setting up vim for golang

Set up a plugin manager

  • Run the following command to install pathogen.vim.
mkdir -p ~/.vim/autoload ~/.vim/bundle && \
curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim
  • Create a .vimrc file in the home directory.
cd ~
touch .vimrc
  • Add following lines in the .vimrc file.
execute pathogen#infect()
syntax on
filetype plugin indent on

Set up a file explorer

git clone https://github.com/scrooloose/nerdtree.git ~/.vim/bundle/nerdtree
  • Add following lines in .vimrc to configure nerdtree
" open a NERDTree automatically when vim starts up
autocmd vimenter * NERDTree

" open a NERDTree automatically when vim starts up if no files were specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

" open NERDTree automatically when vim starts up on opening a directory
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif

" map a specific key or shortcut to open NERDTree
map <F2> :NERDTreeToggle<CR>

" close vim if the only window left open is a NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif

" change default arrows
let g:NERDTreeDirArrowExpandable = '▸'
let g:NERDTreeDirArrowCollapsible = '▾'

Install a color scheme

syntax enable
set background=dark
colorscheme _name-of-colorscheme_

Set up support for Go language. Install vim-go plugin

git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go
:GoInstallBinaries

--

--

--

Product Engineer at Gojek.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Asheet Bhaskar

Asheet Bhaskar

Product Engineer at Gojek.

More from Medium

Docker buildx on Apple Silicon

Unit Testing & Debugging Setup For Golang with VS Code

Gomo — 📐 Simple Golang multi modules tool.

Raspberry Pi read-only kiosk mode: 2022 complete tutorial