Skip to content
This repository was archived by the owner on Oct 11, 2018. It is now read-only.

Commit 06bae28

Browse files
committed
Add default vimrc to be used directly
Closes #12
1 parent 041e825 commit 06bae28

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

vimrc

+174
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
" A sensible vimrc for Go development
2+
"
3+
" Please note that the following settings is just are some default that was
4+
" used by myself for years. However it might be not the case for you (and your
5+
" environment). I highly encourage to change/adapt the vimrc to your own
6+
" needs. Think of a vimrc as a garden that needs to be maintained and fostered
7+
" throughout years. Keep it clean and useful - Fatih Arslan
8+
9+
call plug#begin()
10+
Plug 'fatih/vim-go'
11+
Plug 'fatih/molokai'
12+
Plug 'AndrewRadev/splitjoin.vim'
13+
Plug 'SirVer/ultisnips'
14+
Plug 'ctrlpvim/ctrlp.vim'
15+
call plug#end()
16+
17+
""""""""""""""""""""""
18+
" Settings "
19+
""""""""""""""""""""""
20+
set nocompatible " Enables us Vim specific features
21+
filetype off " Reset filetype detection first ...
22+
filetype plugin indent on " ... and enable filetype detection
23+
set ttyfast " Indicate fast terminal conn for faster redraw
24+
set ttymouse=xterm2 " Indicate terminal type for mouse codes
25+
set ttyscroll=3 " Speedup scrolling
26+
set number " Show line number
27+
set laststatus=2 " Show status line always
28+
set encoding=utf-8 " Set default encoding to UTF-8
29+
set autoread " Automatically read changed files
30+
set autoindent " Enabile Autoindent
31+
set backspace=indent,eol,start " Makes backspace key more powerful.
32+
set incsearch " Shows the match while typing
33+
set hlsearch " Highlight found searches
34+
set noerrorbells " No beeps
35+
set number " Show line numbers
36+
set showcmd " Show me what I'm typing
37+
set noswapfile " Don't use swapfile
38+
set nobackup " Don't create annoying backup files
39+
set splitright " Vertical windows should be split to right
40+
set splitbelow " Horizontal windows should split to bottom
41+
set autowrite " Automatically save before :next, :make etc.
42+
set hidden " Buffer should still exist if window is closed
43+
set fileformats=unix,dos,mac " Prefer Unix over Windows over OS 9 formats
44+
set noshowmatch " Do not show matching brackets by flickering
45+
set noshowmode " We show the mode with airline or lightline
46+
set ignorecase " Search case insensitive...
47+
set smartcase " ... but not it begins with upper case
48+
set completeopt=menu,menuone " Show popup menu, even if there is one entry
49+
set pumheight=10 " Completion window max size
50+
set nocursorcolumn " Do not highlight column (speeds up highlighting)
51+
set nocursorline " Do not highlight cursor (speeds up highlighting)
52+
set lazyredraw " Wait to redraw
53+
54+
" Enable to copy to clipboard for operations like yank, delete, change and put
55+
" http://stackoverflow.com/questions/20186975/vim-mac-how-to-copy-to-clipboard-without-pbcopy
56+
if has('unnamedplus')
57+
set clipboard^=unnamed
58+
set clipboard^=unnamedplus
59+
endif
60+
61+
" This enables us to undo files even if you exit Vim.
62+
if has('persistent_undo')
63+
set undofile
64+
set undodir=~/.config/vim/tmp/undo//
65+
endif
66+
67+
" Colorscheme
68+
syntax enable
69+
set t_Co=256
70+
let g:rehash256 = 1
71+
let g:molokai_original = 1
72+
colorscheme molokai
73+
74+
""""""""""""""""""""""
75+
" Mappings "
76+
""""""""""""""""""""""
77+
78+
" Set leader shortcut to a comma ','. By default it's the backslash
79+
let mapleader = ","
80+
81+
" Jump to next error with Ctrl-n and previous error with Ctrl-p. Close the
82+
" quickfix window with <leader>a
83+
map <C-n> :cnext<CR>
84+
map <C-m> :cprevious<CR>
85+
nnoremap <leader>a :cclose<CR>
86+
87+
" Visual linewise up and down by default (and use gj gk to go quicker)
88+
noremap <Up> gk
89+
noremap <Down> gj
90+
noremap j gj
91+
noremap k gk
92+
93+
" Search mappings: These will make it so that going to the next one in a
94+
" search will center on the line it's found in.
95+
nnoremap n nzzzv
96+
nnoremap N Nzzzv
97+
98+
" Act like D and C
99+
nnoremap Y y$
100+
101+
" Enter automatically into the files directory
102+
autocmd BufEnter * silent! lcd %:p:h
103+
104+
105+
"""""""""""""""""""""
106+
" Plugins "
107+
"""""""""""""""""""""
108+
109+
" vim-go
110+
let g:go_fmt_command = "goimports"
111+
let g:go_autodetect_gopath = 1
112+
let g:go_list_type = "quickfix"
113+
114+
let g:go_highlight_types = 1
115+
let g:go_highlight_fields = 1
116+
let g:go_highlight_functions = 1
117+
let g:go_highlight_methods = 1
118+
let g:go_highlight_extra_types = 1
119+
let g:go_highlight_generate_tags = 1
120+
121+
" Open :GoDeclsDir with ctrl-g
122+
nmap <C-g> :GoDeclsDir<cr>
123+
imap <C-g> <esc>:<C-u>GoDeclsDir<cr>
124+
125+
126+
augroup go
127+
autocmd!
128+
129+
" Show by default 4 spaces for a tab
130+
autocmd BufNewFile,BufRead *.go setlocal noexpandtab tabstop=4 shiftwidth=4
131+
132+
" :GoBuild and :GoTestCompile
133+
autocmd FileType go nmap <leader>b :<C-u>call <SID>build_go_files()<CR>
134+
135+
" :GoTest
136+
autocmd FileType go nmap <leader>t <Plug>(go-test)
137+
138+
" :GoRun
139+
autocmd FileType go nmap <leader>r <Plug>(go-run)
140+
141+
" :GoDoc
142+
autocmd FileType go nmap <Leader>d <Plug>(go-doc)
143+
144+
" :GoCoverageToggle
145+
autocmd FileType go nmap <Leader>c <Plug>(go-coverage-toggle)
146+
147+
" :GoInfo
148+
autocmd FileType go nmap <Leader>i <Plug>(go-info)
149+
150+
" :GoMetaLinter
151+
autocmd FileType go nmap <Leader>l <Plug>(go-metalinter)
152+
153+
" :GoDef but opens in a vertical split
154+
autocmd FileType go nmap <Leader>v <Plug>(go-def-vertical)
155+
" :GoDef but opens in a horizontal split
156+
autocmd FileType go nmap <Leader>s <Plug>(go-def-split)
157+
158+
" :GoAlternate commands :A, :AV, :AS and :AT
159+
autocmd Filetype go command! -bang A call go#alternate#Switch(<bang>0, 'edit')
160+
autocmd Filetype go command! -bang AV call go#alternate#Switch(<bang>0, 'vsplit')
161+
autocmd Filetype go command! -bang AS call go#alternate#Switch(<bang>0, 'split')
162+
autocmd Filetype go command! -bang AT call go#alternate#Switch(<bang>0, 'tabe')
163+
augroup END
164+
165+
" build_go_files is a custom function that builds or compiles the test file.
166+
" It calls :GoBuild if its a Go file, or :GoTestCompile if it's a test file
167+
function! s:build_go_files()
168+
let l:file = expand('%')
169+
if l:file =~# '^\f\+_test\.go$'
170+
call go#cmd#Test(0, 1)
171+
elseif l:file =~# '^\f\+\.go$'
172+
call go#cmd#Build(0)
173+
endif
174+
endfunction

0 commit comments

Comments
 (0)