├── .travis.yml ├── README.md ├── deps ├── go_packages ├── ubuntu_packages └── vim_plugins ├── doc └── screenshot.png ├── install.sh ├── resources ├── .vimrc ├── go.snippets └── molokai.vim └── test.sh /.travis.yml: -------------------------------------------------------------------------------- 1 | language: bash 2 | 3 | script: 4 | - ./test.sh vim_plugins 5 | - ./test.sh go_packages 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-vim-install 2 | 3 | [![Build Status](https://travis-ci.org/xlucas/go-vim-install.svg?branch=master)](https://travis-ci.org/xlucas/go-vim-install) 4 | 5 | Easy environment setup for Vim addicts and go developers on Ubuntu. 6 | 7 | ## Install 8 | 9 | Hereinafter are two easy ways to get your vim environment ready for go development. 10 | 11 | ###### Standard 12 | 13 | ``` 14 | wget https://raw.githubusercontent.com/xlucas/go-vim-install/master/install.sh 15 | chmod +x install.sh 16 | ``` 17 | 18 | ###### Vagrant 19 | 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](https://gist.github.com/xlucas/a7e9e56db314aafada2f). 20 | 21 | ## Usage 22 | 23 | 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 : 24 | - Download and install go from a remote tarball containing the go version of your choice (option `-go`). 25 | - Setup a fully working Vim environment with amazing plugins, third party helpers and colorschemes (option `-vim`). 26 | - Setup your go workspace with required go tools for Vim plugins (option `-work`). 27 | 28 | Examples : 29 | 30 | - `./install.sh -go https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz` 31 | - `./install.sh -vim` 32 | - `./install.sh -work ~/Workspace/go` 33 | 34 | Be aware to run `. ~/.profile` after a step is done so environment variables are up to date. 35 | 36 | That's all ! 37 | 38 | ## Vim environment 39 | 40 | The script will install [pathogen](https://github.com/tpope/vim-pathogen) and the following plugins : 41 | 42 | - [vim-go](https://github.com/fatih/vim-go) 43 | - [YouCompleteMe](https://github.com/Valloric/YouCompleteMe) 44 | - [tagbar](https://github.com/majutsushi/tagbar) 45 | - [fugitive](https://github.com/tpope/vim-fugitive) 46 | - [vim-airline](https://github.com/bling/vim-airline) 47 | - [powerline](https://github.com/powerline/powerline) 48 | - [NERDTree](https://github.com/scrooloose/nerdtree) 49 | - [vim-NERDTree-tabs](https://github.com/jistr/vim-nerdtree-tabs) 50 | - [syntastic](https://github.com/scrooloose/syntastic) 51 | - [better-whitespace](https://github.com/ntpeters/vim-better-whitespace) 52 | - [gundo.vim](https://github.com/sjl/gundo.vim) 53 | - [emmet-vim](https://github.com/mattn/emmet-vim) 54 | - [delimitMate](https://github.com/Raimondi/delimitMate) 55 | - [vim-maximizer](https://github.com/szw/vim-maximizer) 56 | - [tabular](https://github.com/godlygeek/tabular) 57 | - [ultisnips](https://github.com/sirver/ultisnips) 58 | - [vim-instant-markdown](https://github.com/suan/vim-instant-markdown) 59 | - [ctrlp](https://github.com/kien/ctrlp.vim) 60 | - [ag.vim](https://github.com/rking/ag.vim.git) 61 | - [vim-gitgutter](https://github.com/airblade/vim-gitgutter.git) 62 | - [vim-qargs](https://github.com/nelstrom/vim-qargs) 63 | - [vim-easygrep](https://github.com/dkprice/vim-easygrep) 64 | - [vim-grammarous](https://github.com/rhysd/vim-grammarous) 65 | - [vim-easy-align](https://github.com/junegunn/vim-easy-align) 66 | - [vim-multiple-cursors](https://github.com/terryma/vim-multiple-cursors) 67 | 68 | The colorscheme bundled is a variant of [molokai](https://github.com/fatih/molokai). 69 | 70 | Here's a screenshot of what the environment will look like : 71 | 72 | ![go-vim-install](https://raw.githubusercontent.com/xlucas/go-vim-install/master/doc/screenshot.png) 73 | 74 | The script will install the Monaco font. Set it with a size between 11 and 12 in your terminal configuration. 75 | 76 | ## Workspace setup 77 | 78 | The script will install these packages in your workspace : 79 | - [gocov](https://github.com/axw/gocov) 80 | - [gotags](https://github.com/jstemmer/gotags) 81 | - [gocode](https://github.com/nsf/gocode) 82 | - [godef](https://github.com/rogpeppe/godef) 83 | - [goimports](https://golang.org/x/tools/cmd/goimports) 84 | - [guru](https://golang.org/x/tools/cmd/guru) 85 | - [gorename](https://golang.org/x/tools/cmd/gorename) 86 | - [golint](https://github.com/golang/lint) 87 | - [errcheck](https://github.com/kisielk/errcheck) 88 | 89 | 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](https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt) of Go-specific features. 90 | 91 | If you don't know what other plugins are doing, you will find some other tasty functionnalities in related documentations ! 92 | 93 | ## Shortcuts 94 | 95 | The following default shortcuts are set in the `.vimrc` file : 96 | 97 | ### General 98 | - F2 : Create a new tab 99 | - F3 : Maximize/restore current window 100 | - F4 : Enable search highlight 101 | - F5 : Disable search highlight 102 | - F6 : Show/hide the file tree 103 | - F7 : Show/hide the undo tree 104 | - F8 : Show/hide the tagbar (shown by default) 105 | - F9 : Close the current tab 106 | - CTRL + Up : Go to the next tab 107 | - CTRL + Down : Go to the previous tab 108 | 109 | ### Formatting 110 | - F10 : Align text using ',' as a delimiter 111 | - F12 : Align text using space as a delimiter 112 | - CTRL + C + , : Format Zen Coding 113 | - CTRL + \_ : Autoclose xml/html tag(s) (repeat to close several ones) 114 | - CTRL + j : Expand snippet 115 | - CTRL + n : Go to next snippet item 116 | - CTRL + p : Go to previous snippet item 117 | 118 | ### Search and replace 119 | - CTRL + p : Search for a file 120 | - leader + a : Search for a word recursively from project's root directory 121 | - leader + aa : Search word under cursor recursively from project's root directory 122 | - leader + leader + s : Replace all occurences of word under the cursor in this file 123 | - leader + vr : Recursively replace occurences of word under the cursor in all files 124 | 125 | ### Grammar 126 | - leader + g : Run a grammar check 127 | - ! : Go to next grammar error 128 | - § : Go to previous grammar error 129 | - leader + ga : Fix all grammar errors automatically 130 | - leader + gf : Fix this grammar error 131 | - leader + gr : Remove this grammar error 132 | - leader + gd : Disable this grammar rule 133 | 134 | ### Git 135 | - ]h : Go to next hunk 136 | - [h : Go to previous hunk 137 | - leader + hp : Preview current git hunk 138 | - leader + hr : Revert current git hunk 139 | - leader + hs : Stage current git hunk 140 | 141 | ### Go code 142 | - , : Jump to next warning/error 143 | - ? : Jump to previous warning/error 144 | - gi : Go install 145 | - leader + b : Go build 146 | - leader + c : Go coverage 147 | - leader + l : Go lint 148 | - leader + i : Show type info of word under cursor 149 | - leader + e : Rename word under cursor 150 | - leader + f : Implement an interface 151 | - leader + ff : Show interface implementing the type under the cursor 152 | - leader + p : Share selection in the go playground 153 | - leader + q : Import package (type package name) 154 | - leader + r : Go run (normal mode) / Add tags to a selected struct (visual mode) 155 | - leader + s : Go install 156 | - leader + t : Go test 157 | - leader + v : Go vet 158 | - leader + ds : Open declaration of word under cursor in new split window 159 | - leader + dv : Open declaration of word under cursor in new vertical window 160 | - leader + dt : Open declaration of word under cursor in new tab 161 | - leader + gs : Open godoc of word under cursor in new split window 162 | - leader + gv : Open godoc of word under cursor in new vertical window 163 | - leader + gb : Open godoc of word under cursor in browser 164 | -------------------------------------------------------------------------------- /deps/go_packages: -------------------------------------------------------------------------------- 1 | github.com/axw/gocov/gocov 2 | github.com/jstemmer/gotags 3 | github.com/nsf/gocode 4 | github.com/rogpeppe/godef 5 | golang.org/x/tools/cmd/goimports 6 | golang.org/x/tools/cmd/guru 7 | golang.org/x/tools/cmd/gorename 8 | github.com/golang/lint/golint 9 | golang.org/x/tools/cmd/godoc 10 | github.com/kisielk/errcheck 11 | -------------------------------------------------------------------------------- /deps/ubuntu_packages: -------------------------------------------------------------------------------- 1 | git 2 | vim 3 | build-essential 4 | cmake 5 | python-dev 6 | python-pip 7 | python-setuptools 8 | ctags 9 | xdg-utils 10 | npm 11 | silversearcher-ag 12 | openjdk-8-jre 13 | -------------------------------------------------------------------------------- /deps/vim_plugins: -------------------------------------------------------------------------------- 1 | github.com/majutsushi/tagbar 2 | github.com/fatih/vim-go 3 | github.com/Valloric/YouCompleteMe 4 | github.com/bling/vim-airline 5 | github.com/tpope/vim-fugitive 6 | github.com/scrooloose/nerdtree 7 | github.com/jistr/vim-nerdtree-tabs 8 | github.com/scrooloose/syntastic 9 | github.com/ntpeters/vim-better-whitespace 10 | github.com/sjl/gundo.vim 11 | github.com/mattn/emmet-vim 12 | github.com/Raimondi/delimitMate 13 | github.com/szw/vim-maximizer 14 | github.com/godlygeek/tabular 15 | github.com/SirVer/ultisnips 16 | github.com/suan/vim-instant-markdown 17 | github.com/kien/ctrlp.vim 18 | github.com/rking/ag.vim 19 | github.com/rhysd/vim-grammarous 20 | github.com/airblade/vim-gitgutter 21 | github.com/dkprice/vim-easygrep 22 | github.com/nelstrom/vim-qargs 23 | github.com/junegunn/vim-easy-align 24 | github.com/terryma/vim-multiple-cursors 25 | -------------------------------------------------------------------------------- /doc/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xlucas/go-vim-install/ce01e8e3018afc077f53ebb54c50d204e13d9d3b/doc/screenshot.png -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | REPO_URL="https://raw.githubusercontent.com/xlucas/go-vim-install/master" 4 | DEPS_URL="$REPO_URL/deps" 5 | RESR_URL="$REPO_URL/resources" 6 | 7 | install_go() { 8 | curl -s "$1" | sudo tar -C /usr/local -xzvf - 9 | echo 'export PATH=$PATH:/usr/local/go/bin' >> ~/.profile 10 | exit 0 11 | } 12 | 13 | install_vim() { 14 | packages=$(curl -s "$DEPS_URL/ubuntu_packages") 15 | plugins=$(curl -s "$DEPS_URL/vim_plugins") 16 | 17 | # Backup 18 | cp -f ~/.vimrc ~/.vimrc.old.$(date +%s) 19 | 20 | # Install packages 21 | sudo apt-get install -y ${packages[@]} 22 | 23 | # Plugin manager bootstrap 24 | mkdir -p ~/.vim/{autoload,bundle,colors,scripts} 25 | wget -P ~/.vim/autoload "https://tpo.pe/pathogen.vim" 26 | wget -P ~/.vim/colors "$RESR_URL/molokai.vim" 27 | 28 | # Clone necessary stuff 29 | for plugin in ${plugins[@]} ; do 30 | echo "INSTALLING plugin $plugin" 31 | git clone "https://${plugin}.git" ~/.vim/bundle/${plugin##*/} 32 | done 33 | 34 | # Closetag script and snippets 35 | curl -sL -o ~/.vim/scripts/closetag.vim "http://vim.sourceforge.net/scripts/download_script.php?src_id=4318" 36 | wget -P ~/.vim/bundle/vim-go/gosnippets/UltiSnips "$RESR_URL/go.snippets" 37 | 38 | # YCM compilation 39 | cd ~/.vim/bundle/YouCompleteMe && { 40 | git submodule update --init --recursive 41 | bash install.sh 42 | } && cd - 43 | 44 | # Powerline 45 | pip install --user powerline-status 46 | 47 | # Fonts 48 | mkdir -p ~/.{fonts,config/fontconfig/conf.d} 49 | wget -P ~/.fonts "http://jorrel.googlepages.com/Monaco_Linux.ttf" 50 | wget -P ~/.fonts "https://github.com/Lokaltog/powerline/raw/develop/font/PowerlineSymbols.otf" 51 | wget -P ~/.config/fontconfig/conf.d "https://github.com/Lokaltog/powerline/raw/develop/font/10-powerline-symbols.conf" 52 | fc-cache -vf ~/.fonts 53 | 54 | # Instant markdown 55 | sudo npm -g install instant-markdown-d 56 | 57 | # Vimrc 58 | wget -P ~ "$RESR_URL/.vimrc" 59 | 60 | # Path 61 | echo "export PATH=\$PATH:$(readlink -f ~/.local/bin)" >> ~/.profile 62 | exit 0 63 | } 64 | 65 | 66 | install_ws() { 67 | packages=$(curl -s "$RAW_URL/go_packages") 68 | 69 | # Prepare workspace path 70 | mkdir -p $1 71 | echo "export GOPATH=$1" >> ~/.profile 72 | echo "export PATH=\$PATH:$1/bin" >> ~/.profile 73 | . ~/.profile 74 | 75 | # Download dependencies 76 | cd ${GOPATH} 77 | for package in ${packages[@]} ; do 78 | go get ${package} 79 | done 80 | 81 | cd - 82 | exit 0 83 | } 84 | 85 | # Main 86 | case $1 in 87 | "-go") install_go $2;; 88 | "-vim") install_vim $2;; 89 | "-work") install_ws $2;; 90 | esac 91 | 92 | echo "Usage : $0 OPTION" 93 | echo " OPTION { " 94 | echo " -go TARBALL_URL : go installation" 95 | echo " -vim : vim installation" 96 | echo " -work PATH : workspace setup" 97 | echo " }" 98 | exit 1 99 | -------------------------------------------------------------------------------- /resources/.vimrc: -------------------------------------------------------------------------------- 1 | " Common 2 | set shiftwidth=4 3 | set tabstop=4 4 | set expandtab 5 | set number 6 | set selection=exclusive 7 | set autoindent 8 | set autoread 9 | set showcmd 10 | set nocompatible 11 | set relativenumber 12 | set nrformats-=octal 13 | 14 | " Closetag script 15 | autocmd Filetype html let g:closetag_html_style=1 16 | autocmd Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim 17 | autocmd FileType ruby,yaml setl nowrap sw=2 sts=2 et 18 | autocmd BufNewFile,BufReadPost *.md set filetype=markdown 19 | autocmd FileType qf wincmd J 20 | au BufEnter * set scrolloff=30 21 | au VimLeave * !echo -ne "\033[0m" 22 | 23 | " Pathogen 24 | execute pathogen#infect() 25 | filetype plugin indent on 26 | 27 | " Syntax highlighting 28 | syntax enable 29 | colorscheme molokai 30 | 31 | " Easygrep 32 | let g:EasyGrepRecursive=1 33 | 34 | " Ag 35 | let g:ag_working_path_mode="r" 36 | 37 | " Grammarous 38 | let g:grammarous#default_comments_only_filetypes = { 39 | \ '*' : 1, 'help' : 0, 'markdown' : 0, 40 | \ } 41 | 42 | " Tagbar plugin 43 | autocmd VimEnter * nested :TagbarOpen 44 | autocmd VimEnter * nested :NERDTreeFind 45 | autocmd VimEnter * nested :NERDTreeFocusToggle 46 | 47 | " Go-vim plugin 48 | let g:go_highlight_functions = 1 49 | let g:go_highlight_methods = 1 50 | let g:go_highlight_structs = 1 51 | let g:go_highlight_operators = 1 52 | let g:go_highlight_build_constraints = 1 53 | let g:go_auto_type_info = 0 54 | let g:go_highlight_trailing_whitespace_error = 0 55 | let g:go_fmt_command = "goimports" 56 | 57 | " Emmet plugin 58 | let g:user_emmet_leader_key='' 59 | 60 | " YouCompleteMe plugin 61 | let g:ycm_add_preview_to_completeopt = 1 62 | let g:ycm_autoclose_preview_window_after_insertion = 1 63 | 64 | " DelimitMate plugin 65 | let delimitMate_expand_cr = 1 66 | let delimitMate_expand_space = 1 67 | let delimitMate_jump_expansion = 0 68 | 69 | " Airline plugin 70 | let g:airline_theme = 'badwolf' 71 | let g:airline_powerline_fonts = 1 72 | 73 | " NERDTree & NERDTree tabs plugins 74 | let g:nerdtree_tabs_smart_startup_focus = 2 75 | let g:nerdtree_tabs_open_on_console_startup = 1 76 | let g:nerdtree_tabs_focus_on_files = 1 77 | 78 | " Ultisnips 79 | let g:UltiSnipsExpandTrigger="" 80 | let g:UltiSnipsJumpForwardTrigger="" 81 | let g:UltiSnipsJumpBackwardTrigger="" 82 | 83 | " Instant markdown 84 | let g:instant_markdown_autostart = 0 85 | 86 | " Syntastic plugin 87 | set statusline+=%#warningmsg# 88 | set statusline+=%{SyntasticStatuslineFlag()} 89 | set statusline+=%* 90 | let g:go_list_type='quickfix' 91 | let g:syntastic_go_checkers = ['go', 'gofmt', 'golint', 'govet'] 92 | let g:syntastic_ignore_files = ['\.s$'] 93 | let g:syntastic_always_populate_loc_list = 1 94 | 95 | " Exit if quickfix is last window 96 | au BufEnter * call MyLastWindow() 97 | function! MyLastWindow() 98 | " if the window is quickfix go on 99 | if &buftype=="quickfix" 100 | " if this window is last on screen quit without warning 101 | if winbufnr(2) == -1 102 | quit! 103 | endif 104 | endif 105 | endfunction 106 | 107 | " Shortcuts remap 108 | nmap :tabnew 109 | nmap :set hlsearch 110 | nmap :nohlsearch 111 | nmap :NERDTreeTabsToggle 112 | nmap :GundoToggle 113 | nmap :TagbarToggle 114 | nmap :tabclose 115 | nmap :Tabularize /,\zs 116 | vmap :Tabularize /,\zs 117 | nmap :Tabularize / \zs 118 | vmap :Tabularize / \zs 119 | nmap :tabprevious 120 | nmap :tabnext 121 | 122 | " Developper 123 | nmap , :lnext 124 | nmap ? :lprevious 125 | nmap ]h GitGutterNextHunk 126 | nmap [h GitGutterPrevHunk 127 | 128 | " Grammar 129 | nmap g :GrammarousCheck 130 | nmap ga (grammarous-fixall) 131 | nmap gf (grammarous-fixit) 132 | nmap gr (grammarous-remove-error) 133 | nmap gd (grammarous-disable-rule) 134 | nmap ! (grammarous-move-to-next-error) 135 | nmap § (grammarous-move-to-previous-error) 136 | 137 | " Search 138 | nmap s :%s// 139 | nmap a :Ag 140 | nmap aa :Ag 141 | 142 | " Easy Align 143 | xmap ga (EasyAlign) 144 | nmap ga (EasyAlign) 145 | 146 | " Go-Specific 147 | au FileType go nmap gi (go-install) 148 | au FileType go nmap b (go-build) 149 | au FileType go nmap c (go-coverage) 150 | au FileType go nmap e (go-rename) 151 | au FileType go nmap i (go-info) 152 | au FileType go nmap l :GoLint 153 | au FileType go nmap q :GoImport 154 | au FileType go nmap f :GoImpl 155 | au FileType go nmap ff (go-implements) 156 | au FileType go vmap r :GoAddTags 157 | au FileType go vmap p :GoPlay 158 | au FileType go nmap r (go-run) 159 | au FileType go nmap s (go-install) 160 | au FileType go nmap t (go-test) 161 | au FileType go nmap v (go-vet) 162 | au FileType go nmap ds (go-def-split) 163 | au FileType go nmap dv (go-def-vertical) 164 | au FileType go nmap dt (go-def-tab) 165 | au FileType go nmap gb (go-doc-browser) 166 | au FileType go nmap gs (go-doc-split) 167 | au FileType go nmap gv (go-doc-vertical) 168 | -------------------------------------------------------------------------------- /resources/go.snippets: -------------------------------------------------------------------------------- 1 | # Snippets for Go 2 | 3 | priority -10 4 | 5 | snippet com "Simple comment" 6 | // $1 7 | endsnippet 8 | 9 | snippet comb "Comment including a BUG statement" 10 | // BUG($1): $2 11 | endsnippet 12 | 13 | snippet comc "Comment embedding a code block" 14 | // $1 15 | // // $2 16 | endsnippet 17 | 18 | snippet comd "Comment including a Deprecated statement" 19 | // Deprecated: $1 20 | endsnippet 21 | 22 | snippet comse "Small comment block surrounded by equals" 23 | //=========================== 24 | // $1 25 | //=========================== 26 | endsnippet 27 | 28 | snippet comle "Large comment block surrounded by equals" 29 | //=========================== 30 | // 31 | // $1 32 | // 33 | //=========================== 34 | endsnippet 35 | 36 | snippet comsd "Small comment block surrounded by dashes" 37 | //--------------------------- 38 | // $1 39 | //--------------------------- 40 | endsnippet 41 | 42 | snippet comld "Large comment block surrounded by dashes" 43 | //--------------------------- 44 | // 45 | // $1 46 | // 47 | //--------------------------- 48 | endsnippet 49 | 50 | snippet comsb "Small comment block between square brackets" 51 | // ---- [$1] ---- 52 | endsnippet 53 | 54 | snippet todo "TODO comment" 55 | // TODO: $1 56 | endsnippet 57 | 58 | snippet bug "BUG comment" 59 | // BUG($1): $2 60 | endsnippet 61 | 62 | # shorthand variable declaration 63 | snippet : "v := value" 64 | ${1} := ${0} 65 | endsnippet 66 | 67 | # anonymous function 68 | snippet anon "fn := func() { ... }" 69 | ${1:fn} := func() { 70 | ${2:${VISUAL}} 71 | } 72 | ${0} 73 | endsnippet 74 | 75 | # append 76 | snippet ap "append(slice, value)" 77 | append(${1:slice}, ${0:value}) 78 | endsnippet 79 | 80 | # append assignment 81 | snippet ap= "a = append(a, value)" 82 | ${1:slice} = append($1, ${0:value}) 83 | endsnippet 84 | 85 | # break 86 | snippet br "break" 87 | break 88 | endsnippet 89 | 90 | # channel 91 | snippet ch "chan Type" 92 | chan ${0:int} 93 | endsnippet 94 | 95 | # case 96 | snippet case "case ...:" 97 | case ${1:value}: 98 | ${0:${VISUAL}} 99 | endsnippet 100 | 101 | # constant 102 | snippet con "const XXX Type = ..." 103 | const ${1:NAME} ${2:Type} = ${0:0} 104 | endsnippet 105 | 106 | # constants 107 | snippet cons "const ( ... )" 108 | const ( 109 | ${1:NAME} ${2:Type} = ${3:value} 110 | ${0} 111 | ) 112 | endsnippet 113 | 114 | # constants with iota 115 | snippet iota "const ( ... = iota )" 116 | const ( 117 | ${1:NAME} ${2:Type} = iota 118 | ${0} 119 | ) 120 | endsnippet 121 | 122 | # continue 123 | snippet cn "continue" 124 | continue 125 | endsnippet 126 | 127 | # default case 128 | snippet default "default: ..." 129 | default: 130 | ${0:${VISUAL}} 131 | endsnippet 132 | 133 | # defer 134 | snippet df "defer someFunction()" 135 | defer ${1:func}(${2}) 136 | ${0} 137 | endsnippet 138 | 139 | snippet def "defer func() { ... }" 140 | defer func() { 141 | ${0:${VISUAL}} 142 | }() 143 | endsnippet 144 | 145 | # defer recover 146 | snippet defr 147 | defer func() { 148 | if err := recover(); err != nil { 149 | ${0:${VISUAL}} 150 | } 151 | }() 152 | endsnippet 153 | 154 | # gpl 155 | snippet gpl 156 | /* 157 | * This program is free software; you can redistribute it and/or modify 158 | * it under the terms of the GNU General Public License as published by 159 | * the Free Software Foundation; either version 2 of the License, or 160 | * (at your option) any later version. 161 | * 162 | * This program is distributed in the hope that it will be useful, 163 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 164 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 165 | * GNU General Public License for more details. 166 | * 167 | * You should have received a copy of the GNU General Public License 168 | * along with this program; if not, see . 169 | * 170 | * Copyright (C) ${1:Author}, `strftime("%Y")` 171 | */ 172 | ${0} 173 | endsnippet 174 | 175 | # import 176 | snippet import "import ( ... )" 177 | import ( 178 | "${1:package}" 179 | ) 180 | endsnippet 181 | 182 | # full interface snippet 183 | snippet interface "interface I { ... }" 184 | type ${1:Interface} interface { 185 | ${2:/* TODO: add methods */} 186 | } 187 | endsnippet 188 | 189 | # if condition 190 | snippet if "if ... { ... }" 191 | if ${1:condition} { 192 | ${0:${VISUAL}} 193 | } 194 | endsnippet 195 | 196 | # else snippet 197 | snippet else 198 | else { 199 | ${0:${VISUAL}} 200 | } 201 | endsnippet 202 | 203 | # error snippet 204 | snippet errn "Error return " !b 205 | if err != nil { 206 | return err 207 | } 208 | ${0} 209 | endsnippet 210 | 211 | # error snippet 212 | snippet errt "Error test fatal " !b 213 | if err != nil { 214 | t.Fatal(err) 215 | } 216 | ${0} 217 | endsnippet 218 | 219 | snippet errn, "Error return with two return values" !b 220 | if err != nil { 221 | return ${1:nil}, err 222 | } 223 | ${0} 224 | endsnippet 225 | 226 | snippet errh "Error handle and return" !b 227 | if err != nil { 228 | ${1} 229 | return 230 | } 231 | ${0} 232 | endsnippet 233 | 234 | snippet json "\`json:key\`" 235 | \`json:"${1:keyName}"\` 236 | endsnippet 237 | 238 | # fallthrough 239 | snippet ft "fallthrough" 240 | fallthrough 241 | endsnippet 242 | 243 | # for loop 244 | snippet for "for ... { ... }" 245 | for ${1} { 246 | ${0:${VISUAL}} 247 | } 248 | endsnippet 249 | 250 | # for integer loop 251 | snippet fori "for 0..N-1 { ... }" 252 | for ${1:i} := 0; $1 < ${2:N}; $1++ { 253 | ${0:${VISUAL}} 254 | } 255 | endsnippet 256 | 257 | # for range loop 258 | snippet forr "for k, v := range items { ... }" 259 | for ${2:k}, ${3:v} := range ${1} { 260 | ${0:${VISUAL}} 261 | } 262 | endsnippet 263 | 264 | # function 265 | snippet func "func Function(...) [error] { ... }" 266 | func ${1:name}(${2:params})${3/(.+)/ /}`!p opening_par(snip, 3)`$3`!p closing_par(snip, 3)` { 267 | ${0:${VISUAL}} 268 | } 269 | endsnippet 270 | 271 | # Fmt Printf debug 272 | snippet ff "fmt.Printf(...)" 273 | fmt.Printf("${1:${VISUAL}} = %+v\n", $1) 274 | endsnippet 275 | 276 | # Fmt Println debug 277 | snippet fn "fmt.Println(...)" 278 | fmt.Println("${1:${VISUAL}}") 279 | endsnippet 280 | 281 | # log printf 282 | snippet lf "log.Printf(...)" 283 | log.Printf("${1:${VISUAL}} = %+v\n", $1) 284 | endsnippet 285 | 286 | # log println 287 | snippet ln "log.Println(...)" 288 | log.Println("${1:${VISUAL}}") 289 | endsnippet 290 | 291 | # make 292 | snippet make "make(Type, size)" 293 | make(${1:[]string}, ${2:0})${0} 294 | endsnippet 295 | 296 | # map 297 | snippet map "map[Type]Type" 298 | map[${1:string}]${0:int} 299 | endsnippet 300 | 301 | # main() 302 | snippet main "func main() { ... }" 303 | func main() { 304 | ${0:${VISUAL}} 305 | } 306 | endsnippet 307 | 308 | # method 309 | snippet meth "func (self Type) Method(...) [error] { ... }" 310 | func (${1:receiver} ${2:type}) ${3:name}(${4:params})${5/(.+)/ /}`!p opening_par(snip, 5)`$5`!p closing_par(snip, 5)` { 311 | ${0:${VISUAL}} 312 | } 313 | endsnippet 314 | 315 | # ok 316 | snippet ok "if !ok { ... }" 317 | if !ok { 318 | ${0:${VISUAL}} 319 | } 320 | endsnippet 321 | 322 | # package 323 | snippet package "package ..." 324 | // Package $1 provides ${2:...} 325 | package ${1:main} 326 | ${0} 327 | endsnippet 328 | 329 | # panic 330 | snippet pn "panic()" 331 | panic("${0:msg}") 332 | endsnippet 333 | 334 | # return 335 | snippet rt "return" 336 | return ${0:${VISUAL}} 337 | endsnippet 338 | 339 | # select 340 | snippet select "select { case a := <-chan: ... }" 341 | select { 342 | case ${1:v1} := <-${2:chan1} 343 | ${0} 344 | } 345 | endsnippet 346 | 347 | # struct 348 | snippet st "type T struct { ... }" 349 | type ${1:Type} struct { 350 | ${0} 351 | } 352 | endsnippet 353 | 354 | # switch 355 | snippet switch "switch x { ... }" 356 | switch ${1:var} { 357 | case ${2:value1}: 358 | ${0} 359 | } 360 | endsnippet 361 | 362 | # sprintf 363 | snippet sp "fmt.Sprintf(...)" 364 | fmt.Sprintf("%${1:s}", ${2:var}) 365 | endsnippet 366 | 367 | # goroutine named function 368 | snippet go "go someFunc(...)" 369 | go ${1:funcName}(${0}) 370 | endsnippet 371 | 372 | # goroutine anonymous function 373 | snippet gof "go func() { ... }()" 374 | go func() { 375 | ${1:${VISUAL}} 376 | }() 377 | ${0} 378 | endsnippet 379 | 380 | # test function 381 | snippet test "func TestXYZ(t *testing.T) { ... }" 382 | func Test${1:Function}(t *testing.T) { 383 | ${0:${VISUAL}} 384 | } 385 | endsnippet 386 | 387 | # quick test server 388 | snippet tsrv "httptest.NewServer" 389 | ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 390 | fmt.Fprintln(w, ${1:`response`}) 391 | })) 392 | defer ts.Close() 393 | 394 | ${0:someUrl} = ts.URL 395 | endsnippet 396 | 397 | # test error handling 398 | snippet ter "if err != nil { t.Errorf(...) }" 399 | if err != nil { 400 | t.Errorf("${0:message}") 401 | } 402 | endsnippet 403 | 404 | # test fatal error 405 | snippet terf "if err != nil { t.Fatalf(...) }" 406 | if err != nil { 407 | t.Fatalf("${0:message}") 408 | } 409 | endsnippet 410 | 411 | # variable declaration 412 | snippet var "var x Type [= ...]" 413 | var ${1:x} ${2:Type}${3: = ${0:value}} 414 | endsnippet 415 | 416 | # variables declaration 417 | snippet vars "var ( ... )" 418 | var ( 419 | ${1:x} ${2:Type}${3: = ${0:value}} 420 | ) 421 | endsnippet 422 | 423 | # equals fails the test if exp is not equal to act. 424 | snippet eq "equals: test two identifiers with DeepEqual" 425 | if !reflect.DeepEqual(${1:expected}, ${2:actual}) { 426 | _, file, line, _ := runtime.Caller(0) 427 | fmt.Printf("%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\n\n", filepath.Base(file), line, $1, $2) 428 | t.FailNow() 429 | } 430 | endsnippet 431 | 432 | 433 | global !p 434 | 435 | import re 436 | 437 | # Automatically wrap return types with parentheses 438 | 439 | def return_values(s): 440 | # remove everything wrapped in parentheses 441 | s = re.sub("\(.*?\)|\([^)]*$", "", s) 442 | return len(s.split(",")) 443 | 444 | def opening_par(snip, pos): 445 | if return_values(t[pos]) > 1 and not t[pos].startswith("("): 446 | snip.rv = "(" 447 | else: 448 | snip.rv = "" 449 | 450 | def closing_par(snip, pos): 451 | if return_values(t[pos]) > 1: 452 | snip.rv = ")" 453 | else: 454 | snip.rv = "" 455 | 456 | endglobal 457 | 458 | # vim:ft=snippets: 459 | -------------------------------------------------------------------------------- /resources/molokai.vim: -------------------------------------------------------------------------------- 1 | " Vim color file 2 | " Converted from Textmate theme Monokai using Coloration v0.3.2 (http://github.com/sickill/coloration) 3 | 4 | set background=dark 5 | highlight clear 6 | 7 | if exists("syntax_on") 8 | syntax reset 9 | endif 10 | 11 | 12 | set t_Co=256 13 | 14 | let g:colors_name="molokai" 15 | 16 | if exists("g:molokai_original") 17 | let s:molokai_original = g:molokai_original 18 | else 19 | let s:molokai_original = 0 20 | endif 21 | 22 | hi Boolean guifg=#AE81FF 23 | hi Character guifg=#E6DB74 24 | hi Number guifg=#AE81FF 25 | hi String guifg=#E6DB74 26 | hi Conditional guifg=#F92672 gui=bold 27 | hi Constant guifg=#AE81FF gui=bold 28 | hi Cursor guifg=#000000 guibg=#F8F8F0 29 | hi iCursor guifg=#000000 guibg=#F8F8F0 30 | hi Debug guifg=#BCA3A3 gui=bold 31 | hi Define guifg=#66D9EF 32 | hi Delimiter guifg=#8F8F8F 33 | hi DiffAdd guibg=#13354A 34 | hi DiffChange guifg=#89807D guibg=#4C4745 35 | hi DiffDelete guifg=#960050 guibg=#1E0010 36 | hi DiffText guibg=#4C4745 gui=italic,bold 37 | 38 | hi Directory guifg=#A6E22E gui=bold 39 | hi Error guifg=#E6DB74 guibg=#1E0010 40 | hi ErrorMsg guifg=#F92672 guibg=#232526 gui=bold 41 | hi Exception guifg=#A6E22E gui=bold 42 | hi Float guifg=#AE81FF 43 | hi FoldColumn guifg=#465457 guibg=#000000 44 | hi Folded guifg=#465457 guibg=#000000 45 | hi Function guifg=#A6E22E 46 | hi Identifier guifg=#FD971F 47 | hi Ignore guifg=#808080 guibg=bg 48 | hi IncSearch guifg=#C4BE89 guibg=#000000 49 | 50 | hi Keyword guifg=#F92672 gui=bold 51 | hi Label guifg=#E6DB74 gui=none 52 | hi Macro guifg=#C4BE89 gui=italic 53 | hi SpecialKey guifg=#66D9EF gui=italic 54 | 55 | hi MatchParen guifg=#000000 guibg=#FD971F gui=bold 56 | hi ModeMsg guifg=#E6DB74 57 | hi MoreMsg guifg=#E6DB74 58 | hi Operator guifg=#F92672 59 | 60 | " complete menu 61 | hi Pmenu guifg=#66D9EF guibg=#000000 62 | hi PmenuSel guibg=#808080 63 | hi PmenuSbar guibg=#080808 64 | hi PmenuThumb guifg=#66D9EF 65 | 66 | hi PreCondit guifg=#A6E22E gui=bold 67 | hi PreProc guifg=#A6E22E 68 | hi Question guifg=#66D9EF 69 | hi Repeat guifg=#F92672 gui=bold 70 | hi Search guifg=#000000 guibg=#FFE792 71 | " marks 72 | hi SignColumn guifg=#A6E22E guibg=#232526 73 | hi SpecialChar guifg=#F92672 gui=bold 74 | hi SpecialComment guifg=#7E8E91 gui=bold 75 | hi Special guifg=#66D9EF guibg=bg gui=italic 76 | if has("spell") 77 | hi SpellBad guisp=#FF0000 gui=undercurl 78 | hi SpellCap guisp=#7070F0 gui=undercurl 79 | hi SpellLocal guisp=#70F0F0 gui=undercurl 80 | hi SpellRare guisp=#FFFFFF gui=undercurl 81 | endif 82 | hi Statement guifg=#F92672 gui=bold 83 | hi StatusLine guifg=#455354 guibg=fg 84 | hi StatusLineNC guifg=#808080 guibg=#080808 85 | hi StorageClass guifg=#FD971F gui=italic 86 | hi Structure guifg=#66D9EF 87 | hi Tag guifg=#F92672 gui=italic 88 | hi Title guifg=#ef5939 89 | hi Todo guifg=#FFFFFF guibg=bg gui=bold 90 | 91 | hi Typedef guifg=#66D9EF 92 | hi Type guifg=#66D9EF gui=none 93 | hi Underlined guifg=#808080 gui=underline 94 | 95 | hi VertSplit guifg=#808080 guibg=#080808 gui=bold 96 | hi VisualNOS guibg=#403D3D 97 | hi Visual guibg=#403D3D 98 | hi WarningMsg guifg=#FFFFFF guibg=#333333 gui=bold 99 | hi WildMenu guifg=#66D9EF guibg=#000000 100 | 101 | "hi TabLineFill guifg=#1B1D1E guibg=#64645e 102 | "hi TabLine guibg=#1B1D1E guifg=#64645e gui=none 103 | 104 | if s:molokai_original == 1 105 | hi Normal guifg=#F8F8F2 guibg=#272822 106 | hi Comment guifg=#75715E 107 | hi CursorLine guibg=#3E3D32 108 | hi CursorLineNr guifg=#FD971F gui=none 109 | hi CursorColumn guibg=#3E3D32 110 | hi ColorColumn guibg=#3B3A32 111 | hi LineNr guifg=#8F908A guibg=#272822 112 | hi NonText guifg=#75715E 113 | hi SpecialKey guifg=#75715E 114 | else 115 | hi Normal guifg=#F8F8F2 guibg=#1B1D1E 116 | hi Comment guifg=#7E8E91 117 | hi CursorLine guibg=#293739 118 | hi CursorLineNr guifg=#FD971F gui=none 119 | hi CursorColumn guibg=#293739 120 | hi ColorColumn guibg=#232526 121 | hi LineNr guifg=#465457 guibg=#232526 122 | hi NonText guifg=#465457 123 | hi SpecialKey guifg=#465457 124 | end 125 | 126 | " 127 | " Support for 256-color terminal 128 | " 129 | if &t_Co > 255 130 | if s:molokai_original == 1 131 | hi Normal ctermbg=234 132 | hi CursorLine ctermbg=235 cterm=none 133 | hi CursorLineNr ctermfg=208 cterm=none 134 | else 135 | hi Normal ctermfg=252 ctermbg=233 136 | hi CursorLine ctermbg=234 cterm=none 137 | hi CursorLineNr ctermfg=208 cterm=none 138 | endif 139 | hi Boolean ctermfg=135 140 | hi Character ctermfg=144 141 | hi Number ctermfg=135 142 | hi String ctermfg=144 143 | hi Conditional ctermfg=161 cterm=bold 144 | hi Constant ctermfg=135 cterm=bold 145 | hi Cursor ctermfg=16 ctermbg=253 146 | hi Debug ctermfg=225 cterm=bold 147 | hi Define ctermfg=81 148 | hi Delimiter ctermfg=241 149 | 150 | hi DiffAdd ctermbg=24 151 | hi DiffChange ctermfg=181 ctermbg=239 152 | hi DiffDelete ctermfg=162 ctermbg=53 153 | hi DiffText ctermbg=102 cterm=bold 154 | 155 | hi Directory ctermfg=118 cterm=bold 156 | hi Error ctermfg=219 ctermbg=89 157 | hi ErrorMsg ctermfg=199 ctermbg=16 cterm=bold 158 | hi Exception ctermfg=118 cterm=bold 159 | hi Float ctermfg=135 160 | hi FoldColumn ctermfg=67 ctermbg=16 161 | hi Folded ctermfg=67 ctermbg=16 162 | hi Function ctermfg=118 163 | hi Identifier ctermfg=208 cterm=none 164 | hi Ignore ctermfg=244 ctermbg=232 165 | hi IncSearch ctermfg=193 ctermbg=16 166 | 167 | hi keyword ctermfg=161 cterm=bold 168 | hi Label ctermfg=229 cterm=none 169 | hi Macro ctermfg=193 170 | hi SpecialKey ctermfg=81 171 | 172 | hi MatchParen ctermfg=233 ctermbg=208 cterm=bold 173 | hi ModeMsg ctermfg=229 174 | hi MoreMsg ctermfg=229 175 | hi Operator ctermfg=161 176 | 177 | " complete menu 178 | hi Pmenu ctermfg=81 ctermbg=16 179 | hi PmenuSel ctermfg=255 ctermbg=242 180 | hi PmenuSbar ctermbg=232 181 | hi PmenuThumb ctermfg=81 182 | 183 | hi PreCondit ctermfg=118 cterm=bold 184 | hi PreProc ctermfg=118 185 | hi Question ctermfg=81 186 | hi Repeat ctermfg=161 cterm=bold 187 | hi Search ctermfg=0 ctermbg=222 cterm=NONE 188 | 189 | " marks column 190 | hi SignColumn ctermfg=118 ctermbg=235 191 | hi SpecialChar ctermfg=161 cterm=bold 192 | hi SpecialComment ctermfg=245 cterm=bold 193 | hi Special ctermfg=81 194 | if has("spell") 195 | hi SpellBad ctermbg=52 196 | hi SpellCap ctermbg=17 197 | hi SpellLocal ctermbg=17 198 | hi SpellRare ctermfg=none ctermbg=none cterm=reverse 199 | endif 200 | hi Statement ctermfg=161 cterm=bold 201 | hi StatusLine ctermfg=238 ctermbg=253 202 | hi StatusLineNC ctermfg=244 ctermbg=232 203 | hi StorageClass ctermfg=208 204 | hi Structure ctermfg=81 205 | hi Tag ctermfg=161 206 | hi Title ctermfg=166 207 | hi Todo ctermfg=231 ctermbg=232 cterm=bold 208 | 209 | hi Typedef ctermfg=81 210 | hi Type ctermfg=81 cterm=none 211 | hi Underlined ctermfg=244 cterm=underline 212 | 213 | hi VertSplit ctermfg=244 ctermbg=232 cterm=bold 214 | hi VisualNOS ctermbg=238 215 | hi Visual ctermbg=235 216 | hi WarningMsg ctermfg=231 ctermbg=238 cterm=bold 217 | hi WildMenu ctermfg=81 ctermbg=16 218 | 219 | hi Comment ctermfg=59 220 | hi CursorColumn ctermbg=236 221 | hi ColorColumn ctermbg=236 222 | hi LineNr ctermfg=250 ctermbg=236 223 | hi NonText ctermfg=59 224 | 225 | hi SpecialKey ctermfg=59 226 | 227 | if exists("g:rehash256") && g:rehash256 == 1 228 | hi Normal ctermfg=252 ctermbg=234 229 | hi CursorLine ctermbg=236 cterm=none 230 | hi CursorLineNr ctermfg=208 cterm=none 231 | 232 | hi Boolean ctermfg=141 233 | hi Character ctermfg=222 234 | hi Number ctermfg=141 235 | hi String ctermfg=222 236 | hi Conditional ctermfg=197 cterm=bold 237 | hi Constant ctermfg=141 cterm=bold 238 | 239 | hi DiffDelete ctermfg=125 ctermbg=233 240 | 241 | hi Directory ctermfg=154 cterm=bold 242 | hi Error ctermfg=222 ctermbg=233 243 | hi Exception ctermfg=154 cterm=bold 244 | hi Float ctermfg=141 245 | hi Function ctermfg=154 246 | hi Identifier ctermfg=208 247 | 248 | hi Keyword ctermfg=197 cterm=bold 249 | hi Operator ctermfg=197 250 | hi PreCondit ctermfg=154 cterm=bold 251 | hi PreProc ctermfg=154 252 | hi Repeat ctermfg=197 cterm=bold 253 | 254 | hi Statement ctermfg=197 cterm=bold 255 | hi Tag ctermfg=197 256 | hi Title ctermfg=203 257 | hi Visual ctermbg=238 258 | 259 | hi Comment ctermfg=244 260 | hi LineNr ctermfg=239 ctermbg=235 261 | hi NonText ctermfg=239 262 | hi SpecialKey ctermfg=239 263 | endif 264 | end 265 | 266 | hi Visual ctermbg=238 267 | hi Cursor ctermfg=235 ctermbg=231 cterm=NONE guifg=#272822 guibg=#f8f8f0 gui=NONE 268 | hi CursorLine ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE 269 | hi CursorColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE 270 | hi ColorColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE 271 | hi LineNr ctermfg=102 ctermbg=237 cterm=NONE guifg=#90908a guibg=#3c3d37 gui=NONE 272 | hi VertSplit ctermfg=241 ctermbg=241 cterm=NONE guifg=#64645e guibg=#64645e gui=NONE 273 | hi StatusLine ctermfg=231 ctermbg=241 cterm=bold guifg=#f8f8f2 guibg=#64645e gui=bold 274 | hi StatusLineNC ctermfg=231 ctermbg=241 cterm=NONE guifg=#f8f8f2 guibg=#64645e gui=NONE 275 | hi PmenuSel ctermfg=232 ctermbg=130 276 | hi Directory ctermfg=141 ctermbg=NONE cterm=NONE guifg=#ae81ff guibg=NONE gui=NONE 277 | hi Folded ctermfg=242 ctermbg=235 cterm=NONE guifg=#75715e guibg=#272822 gui=NONE 278 | hi SignColumn ctermfg=NONE ctermbg=237 cterm=NONE guifg=NONE guibg=#3c3d37 gui=NONE 279 | hi Normal ctermfg=231 ctermbg=235 cterm=NONE guifg=#f8f8f2 guibg=#272822 gui=NONE 280 | hi TabLine ctermbg=0 guifg=#75715E cterm=NONE guibg=#64645e gui=NONE 281 | hi TabLineFill ctermbg=0 guifg=fg cterm=NONE guibg=#64645e gui=NONE 282 | hi TabLineSel ctermbg=8 cterm=NONE gui=NONE 283 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for item in $(curl -s "https://raw.githubusercontent.com/xlucas/go-vim-install/master/deps/$1") ; do 4 | status=$(curl -o /dev/null -sw "%{http_code}" "$item") 5 | echo -e "$status\t <= $item" 6 | 7 | if [ "$status" -gt "400" ] && [ "$status" -lt "500" ] 8 | then 9 | exit 1 10 | fi 11 | done 12 | --------------------------------------------------------------------------------