Skip to content

Instantly share code, notes, and snippets.

@lpabon
Last active June 11, 2019 23:05
Show Gist options
  • Save lpabon/5984803fc90ed4d3e07e6ef977f3db1d to your computer and use it in GitHub Desktop.
Save lpabon/5984803fc90ed4d3e07e6ef977f3db1d to your computer and use it in GitHub Desktop.
Vim for Golang and markdown development

Assuming this is a new installation of vim. If not, you may want to backup your .vimrc and $HOME/.vim/ directory.

Initial Setup

  • Install vundle
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  • Setup an initial .vimrc
curl -o .vimrc https://gist.githubusercontent.com/lpabon/5d8baa164a82674e7f86ffc4055d059e/raw/b47df06f7464a61ce1c31f0d424d1d5c7e813b7c/.vimrc
  • Start vim to install the plugins, then type:
:PluginInstall

This will take a little while.

Type :qa to quit when done.

Setup YouCompleteMe

Now, we need to setup YouCompleteMe:

$ cd .vim/bundle/YouCompleteMe/
$ ./install.sh --go-completer

You will need to rebuild this every time you run :PluginUpdate in Vim.

Setup the Golang tools

Go to your golang project, or open vim when your $GOPATH variable is set, then type:

:GoInstallBinaries
:qa

Trying it out

Open a golang file using Vim.

Golang commands

  • Autocompletion will be supported when a . is typed. Accept using TAB. Autocompletion will also accept appromixations.
  • Type gd on a variable/function to see its definition. Type CTRL-T to go back up the stack.
  • GoBuild to build that single file
  • GoTest to run all the tests in that package

Switch quick between buffers

  • Type gb then some matching file name

Markdown

  • Automatically collapse a line longer than 80 chars and collapse it to multiple lines of 80 chars max by typing gq.

Git commands

  • Git commands use vim-fugitive. Examples:
    • :Gblame for git blame
    • :Gdiff for git diff

Enjoy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment