Skip to content

Instantly share code, notes, and snippets.

@bigkevmcd
Last active April 3, 2017 06:24
Show Gist options
  • Save bigkevmcd/16e1fa07b8dd9df13c087e341be32e91 to your computer and use it in GitHub Desktop.
Save bigkevmcd/16e1fa07b8dd9df13c087e341be32e91 to your computer and use it in GitHub Desktop.

Please ensure you have Go 1.8 installed on your machine.

If you're on Ubuntu this might help

 $ sudo add-apt-repository ppa:longsleep/golang-backports
 $ sudo apt-get update
 $ sudo apt-get install golang-go

If you're on Mac OS, I recommend homebrew https://brew.sh/ and then

 $ brew install go

I personally, also like macvim installed on Mac OS (easily installed with homebrew).

If you're on Windows, I've tested this with Chocolatey https://chocolatey.org/install in which case you can

 $ choco install golang
 $ choco install vim # if you're going to use vim

If want to use vim as your editor (it's what I use), I'll help with configuration if not, you can run the tests easily from the command-line, or if your editor has Go support, that's great.

First off, if you're a normal vim user, I recommend doing this...

 myhost:~$ mkdir vim_backup
 myhost:~$ mv .vimrc .vim vim_backup

Install vim-plug from here https://github.com/junegunn/vim-plug

 $ curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
    https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim

Under Go 1.8, the default GOPATH is now ~/go which means that the binaries installed below will get put into ~/go/binwe want these to be on our PATH...

 $ export PATH=~/go/bin:$PATH

Replace your .vimrc with the .vimrc below (or edit, if you really want to use something you like).

Start vim, enter command mode (hit escape) type :PlugInstall this will split a screen and fetch the plugins from the .vimrc.

Once this has completed, ensure you're in command mode again and type :GoInstallBinaries this will fetch and install some additional Go tools that will make your life a lot easier.

You're now setup and ready to Go!

I recommend doing this for the Kata coming up...

 $ mkdir ~/go/src/glasgowtdd
 $ cd ~/go/src/glasgowtdd
 $ vim hello.go

The vim-go plugin will generate a "Hello, World!" file, which you can test by going to vim command-mode, and typing :GoRun you should see a familiar message.

My .vimrc for Go

call plug#begin('~/.vim/plugged')

Plug 'junegunn/vim-easy-align'
Plug 'janko-m/vim-test'
Plug 'scrooloose/nerdtree'
Plug 'tpope/vim-markdown'
Plug 'fatih/vim-go'
Plug 'nsf/gocode'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'vim-airline/vim-airline'

" Add plugins to &runtimepath
call plug#end()

nmap <silent> <leader>t :TestNearest<CR>
nmap <silent> <leader>T :TestFile<CR>
nmap <silent> <leader>a :TestSuite<CR>
nmap <silent> <leader>l :TestLast<CR>
nmap <silent> <leader>g :TestVisit<CR>
map  <C-o>              :NERDTreeToggle<CR>

set history=50
set ruler         " show the cursor position all the time
set showcmd       " display incomplete commands
set incsearch     " do incremental searching
set laststatus=3  " Always display the status line
set tw=80
set sw=2
set ts=4
set expandtab

" Display extra whitespace
set list listchars=tab:»·,trail:·
colorscheme elflord
set guifont=Monaco:h12
autocmd BufNewFile,BufReadPost *.md set filetype=markdown

let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
set modelines=5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment