Through my journey as a software engineer, I have made it my mission to try to use vim full time, for blog posts to programming. I have made this my goal to improve my overall productivity and minimize the applications I use day to

day. Eventually, everyone has this goal to only use a terminal at some point in their career. In the past month I am learning go-lang and will be blogging different aspects of my journey, you can see other posts here: https://medium.com/@joemeli51.

Setup Vim

Before we can configure vim for go-lang, I want to make sure all our vim environments are set up the same.

1. In your home directory make sure you have a .vimrc file.

2. put the following in the .vimrc:

set nocompatible “ be iMproved, required

filetype off “ required “ set the runtime path to include Vundle and initialize

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin ‘tpope/vim-fugitive’

“ Will add more here later

call vundle#end() “ required

filetype plugin indent on

3. save and quit vim

4. reopen vim, run :PluginInstall

Now you will have a .vim/. In here will be where you put all things related to your bundles and plugin related stuff will be installed.

Get ready for go

Now we can start tweaking vim for creating amazing golang projects. let's add things piece by piece to the .vimrc. The first thing to add is the vim-go.

" add it between call vundle#begin() and call vundle#end()

Plugin 'fatih/vim-go'

With this installed we now have the ability to run commands like

:GoRun %

:GoBuild

Many other go commands

Vim has a setting called autowrite, it saves file content automatically if the make command is called. The make command is called when using the tools in vim-go (like the above mentioned). Can add by putting:

" .vimrc

set autowrite

To make this process even more convenient lets map shortcuts using our leader command.

".vimrc autocmd FileType go nmap <leader>b <Plug>(go-build)

autocmd FileType go nmap <leader>r <Plug>(go-run) "I prefer to map leader to ,. the default is \

"If you want to update this use this command

let mapleader = ","

Next, we add language and styling improvements.

don't have to use go fmt anymore use goimports:

let g:go_fmt_command = "goimports"

Lets style it

let g:go_highlight_types = 1

let g:go_highlight_fields = 1

let g:go_highlight_functions = 1

let g:go_highlight_functions = 1

Now lets enable linting to helps us improve our code:

let g:go_metalinter_autosave = 1

let g:go_metalinter_autosave_enabled = ['vet', 'golint']

Check out my .vimrc setup for golang.

My partial of .vimrc

If you want to make a more complete .vimrc just use the Vim-Bootstrap tool. Make your own .vimrc here: http://vim-bootstrap.com.

Catch up with me on twitter @joemeli51