go-vim-install

Easy environment setup for Vim addicts and go developers.

3 years after

go-vim-install

Easy environment setup for Vim addicts and go developers on Ubuntu.

Install

Hereinafter are two easy ways to get your vim environment ready for go development.

Standard
wget https://raw.githubusercontent.com/xlucas/go-vim-install/master/install.sh
chmod +x install.sh
Vagrant

If you want to boot up a clean Ubuntu VM with a GUI and all the features ready to be used, you can use this gist.

Usage

While there are a lot of great plugins of all kinds for Vim made by amazing people, that's always a hassle to retrieve them all, configure your .vimrc, install colorschemes and extra stuff to get everything eventually working. This little installer for ubuntu make the life simpler for go development with Vim, by providing a command line with 3 options to either :

  • Download and install go from a remote tarball containing the go version of your choice (option -go).
  • Setup a fully working Vim environment with amazing plugins, third party helpers and colorschemes (option -vim).
  • Setup your go workspace with required go tools for Vim plugins (option -work).

Examples :

  • ./install.sh -go https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz
  • ./install.sh -vim
  • ./install.sh -work ~/Workspace/go

Be aware to run . ~/.profile after a step is done so environment variables are up to date.

That's all !

Vim environment

The script will install pathogen and the following plugins :

The colorscheme bundled is a variant of molokai.

Here's a screenshot of what the environment will look like :

go-vim-install

The script will install the Monaco font. Set it with a size between 11 and 12 in your terminal configuration.

Workspace setup

The script will install these packages in your workspace :

Most of them are required to have the go-vim plugin fully working. Then you can run crazy things from Vim, like test units with (:GoTest), coverage report with (:GoCoverage), refactor an element name and its references (:GoRename), do code inspection and error checking (:GoDoc, :GoInfo, :GoCallers, :GoCallees, :GoErrCheck ...), build your packages (:GoBuild), detect unchecked errors (:GoErrCheck) and much more. Obviously, you can also remap all these actions to shortcuts of your choice in your .vimrc ! Check the go-vim plugin documentation to get a full list of Go-specific features.

If you don't know what other plugins are doing, you will find some other tasty functionnalities in related documentations !

Shortcuts

The following default shortcuts are set in the .vimrc file :

General

  • F2 : Create a new tab
  • F3 : Maximize/restore current window
  • F4 : Enable search highlight
  • F5 : Disable search highlight
  • F6 : Show/hide the file tree
  • F7 : Show/hide the undo tree
  • F8 : Show/hide the tagbar (shown by default)
  • F9 : Close the current tab
  • CTRL + Up : Go to the next tab
  • CTRL + Down : Go to the previous tab

Formatting

  • F10 : Align text using ',' as a delimiter
  • F12 : Align text using space as a delimiter
  • CTRL + C + , : Format Zen Coding
  • CTRL + _ : Autoclose xml/html tag(s) (repeat to close several ones)
  • CTRL + j : Expand snippet
  • CTRL + n : Go to next snippet item
  • CTRL + p : Go to previous snippet item

Search and replace

  • CTRL + p : Search for a file
  • leader + a : Search for a word recursively from project's root directory
  • leader + aa : Search word under cursor recursively from project's root directory
  • leader + leader + s : Replace all occurences of word under the cursor in this file
  • leader + vr : Recursively replace occurences of word under the cursor in all files

Grammar

  • leader + g : Run a grammar check
  • ! : Go to next grammar error
  • § : Go to previous grammar error
  • leader + ga : Fix all grammar errors automatically
  • leader + gf : Fix this grammar error
  • leader + gr : Remove this grammar error
  • leader + gd : Disable this grammar rule

Git

  • ]c : Go to next hunk
  • [c : Go to previous hunk
  • leader + hp : Preview current git hunk
  • leader + hr : Revert current git hunk
  • leader + hs : Stage current git hunk

Go code

  • , : Jump to next warning/error
  • ? : Jump to previous warning/error
  • leader + b : Go build
  • leader + c : Go coverage
  • leader + l : Go lint
  • leader + i : Show type info of word under cursor
  • leader + e : Rename word under cursor
  • leader + f : Implement an interface
  • leader + ff : Show interface implementing the type under the cursor
  • leader + p : Share selection in the go playground
  • leader + q : Import package (type package name)
  • leader + r : Go run (normal mode) / Add tags to a selected struct (visual mode)
  • leader + s : Go install
  • leader + t : Go test
  • leader + v : Go vet
  • leader + ds : Open declaration of word under cursor in new split window
  • leader + dv : Open declaration of word under cursor in new vertical window
  • leader + dt : Open declaration of word under cursor in new tab
  • leader + gs : Open godoc of word under cursor in new split window
  • leader + gv : Open godoc of word under cursor in new vertical window
  • leader + gb : Open godoc of word under cursor in browser

Related Repositories

Vundle.vim

Vundle.vim

Vundle, the plug-in manager for Vim ...

vim-go

vim-go

Go development plugin for Vim ...

vim-go-tutorial

vim-go-tutorial

Tutorial for vim-go ...

working-with-go

working-with-go

A set of example golang code to start learning Go ...

vim-godebug

vim-godebug

Go debugging for Vim ...


Top Contributors

xlucas