forked from kerryb/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvimrc
334 lines (275 loc) · 8.97 KB
/
vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
set nocompatible
filetype off
let vimDir = '$HOME/.vim'
let plugin_dir = expand(vimDir . '/plugins')
call plug#begin(plugin_dir)
Plug 'vim-scripts/Align'
Plug 'AndrewRadev/splitjoin.vim'
Plug 'vim-scripts/Tabular'
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'airblade/vim-gitgutter'
Plug 'alkesh/projector_mode'
Plug 'avakhov/vim-yaml'
Plug 'vim-scripts/bufexplorer.zip'
Plug 'chase/vim-ansible-yaml'
Plug 'christoomey/vim-tmux-navigator'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'dense-analysis/ale'
Plug 'derekwyatt/vim-scala'
Plug 'dkprice/vim-easygrep'
Plug 'ecomba/vim-ruby-refactoring'
Plug 'elixir-lang/vim-elixir'
Plug 'ervandew/supertab'
Plug 'fatih/vim-go'
Plug 'int3/vim-extradite'
Plug 'jasoncodes/ctrlp-modified.vim'
Plug 'jgdavey/tslime.vim'
Plug 'jgdavey/vim-turbux'
Plug 'jgdavey/vim-blockle'
Plug 'vim-scripts/matchit.zip'
Plug 'mileszs/ack.vim'
Plug 'mustache/vim-mustache-handlebars'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'nvie/vim-togglemouse'
Plug 'othree/html5.vim'
Plug 'plasticboy/vim-markdown'
Plug 'vim-scripts/rake.vim'
Plug 'vim-scripts/repeat.vim'
Plug 'rizzatti/dash.vim'
Plug 'rizzatti/funcoo.vim'
Plug 'preservim/nerdcommenter'
Plug 'preservim/nerdtree'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-cucumber'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-ragtag'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-surround'
Plug 'vim-scripts/unimpaired.vim'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'vim-scripts/ZoomWin'
call plug#end()
filetype plugin indent on
syntax on
set sessionoptions=blank,buffers,curdir,folds,help,resize,tabpages,winsize
set guioptions-=T " no toolbar
set laststatus=2 " Always show status line.
set number " line numbers
set scrolloff=3 " More context around cursor
set hlsearch " highlight search matches...
set incsearch " ...as you type
set ignorecase
set smartcase
set hidden " Allow buffer switching without saving
set history=1000
set wildmode=list:longest " Shell-like behaviour for command autocompletion
set visualbell
set mousehide
set cf " Enable error files & error jumping.
set autowrite " Writes on make/shell commands
set ruler " Ruler on
set nowrap " Line wrapping off
set timeoutlen=500
" swap files are really not needed if you're using git
set noswapfile
let mapleader = ","
" Display soft column limit
au WinEnter,FileType * set cc=
au WinEnter,FileType ruby,eruby,rspec,cucumber set cc=120
" Override the colour in .vimrc.local like this:
"hi ColorColumn ctermbg=lightgrey guibg=lightgrey
set tabstop=2
set smarttab
set shiftwidth=2
set autoindent
set expandtab
set backspace=start,indent,eol
" mouse mode for terminal
set mouse=a
if !has('nvim')
set ttymouse=xterm2
endif
autocmd FileType make set noexpandtab
" treat scss files as css
au BufRead,BufNewFile *.scss set filetype=css
runtime! plugin/matchit.vim " extends % to do/end etc
colorscheme railscasts
if has("mac")
let g:ruby_debugger_progname = 'mvim'
else
let g:ruby_debugger_progname = 'gvim'
endif
if $COLORTERM == 'gnome-terminal'
set term=xterm-color
set guifont=DejaVu\ Sans\ Mono\ 10
else
set guifont=Monaco\ for\ Powerline:h10
endif
" highlight cursor line
:set cursorline
",p to toggle projector mode
let g:default_colorscheme = 'railscasts'
let g:projector_colorscheme = 'mac-classic'
noremap <silent> <leader>p :ToggleProjectorMode<CR>
" ,c to hide hidden characters
"set listchars=tab:>-,trail:·,eol:$
set listchars=tab:▸\ ,trail:·
set list
nmap <silent> <leader>c :set nolist!<CR>
" Highlight trailing whitespace
highlight RedundantSpaces term=standout ctermbg=red guibg=red
match RedundantSpaces /\s\+$\| \+\ze\t/ "\ze sets end of match so only spaces highlighted
" ,h to dismiss search result highlighting until next search or press of 'n'
:noremap <silent> <leader>h :noh<CR>
" ,w to toggle line wrap
:map <silent> <Leader>w :set wrap!<CR>
" ,f to find current file in NERDTree
map <silent> <Leader>f :NERDTreeFind<CR>
" ,m to toggle NERDTree
nmap <silent> <Leader>m :NERDTreeToggle<CR>
" ,. to open BufExplorer
nmap <silent> <unique> <Leader>. :BufExplorer<CR>
" ,x to open git commit history for current file
nnoremap <Leader>x :Extradite<CR>
" ,, to run current spec file
map <Leader>, :wa\|:!rspec %<CR>
" Fix supertab/endwise incompatibility
let g:SuperTabCrMapping = 0
" ,r for rake
map <Leader>r :Rake<CR>
" ,rr to rerun last tmx command
map <Leader>rr :call Send_to_Tmux("!!\n")<CR>
" ,s to toggle spelling highlighting
nmap <silent> <Leader>sp :setlocal spell! spelllang=en_gb<CR>
" Dash
nmap <silent> <leader>d <Plug>DashSearch
" Ragtag
let g:ragtag_global_maps = 1
" ,u to run rubocop using ALEFix
nmap <Leader>u :ALEFix<CR>
" copy current filename and path to the system clipboard
nmap <Leader>ff :let @*=@%<CR>
"CtrlP
let g:ctrlp_max_files = 0
let g:ctrlp_max_depth = 40
let g:ctrlp_clear_cache_on_exit = 0
let g:ctrlp_custom_ignore = '\v[\/](\.git|bower_components|log|node_modules|tmp|vendor)$'
set runtimepath^=~/.vim/bundle/ctrlp.vim
map <leader>t :CtrlP<cr>
map <leader>g :CtrlPModified<cr>
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
endif
" Vim-markdown
let g:vim_markdown_folding_disabled=1
" NERDCommenter
let NERDSpaceDelims=1
" NERDTree
" open NERDTree if no files were specified on startup
autocmd vimenter * if !argc() | NERDTree | endif
" close vim if only window left is NERDTree
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" ZoomWin
map <Leader>z :ZoomWin<CR>
" Tabular
vnoremap <silent> <Leader>aa :Tabularize /\|<CR>
" make Y consistent with C and D
nnoremap Y y$
" strip trailing whitespace
"autocmd BufWritePre,FileWritePre * call StripTrailingWhitespace()
function! StripTrailingWhitespace()
normal mz
normal Hmy
exec '%s/\s*$//g'
normal 'yz<cr>
normal `z
endfunction
nmap <silent> <Leader>sw :call StripTrailingWhitespace()<CR>
" ALE linting
let b:ale_linters = {'ruby': ['rubocop', 'ruby']}
let g:ale_ruby_rubocop_executable = 'bundle'
let g:ale_fixers = {'ruby': ['rubocop']}
let g:ale_sign_error = '⚠'
let g:ale_sign_warning = '⚠'
let g:ale_sign_column_always = 1 " Always show the sign column to avoid annoying popping in
let g:ale_lint_delay = 1000 " Lint at most once per second incase we're on battery power
" refresh both ctags and CtrlP cache
function! RebuildCaches()
" needs universal ctags: https://github.com/universal-ctags/homebrew-universal-ctags
exec '!ctags --exclude=.js --exclude=.git --exclude=bower_components --exclude=node_modules --exclude=tmp --exclude=vendor --exclude=log --exclude=clients --links=no --extras=+q -R *'
if exists("g:loaded_ctrlp") && g:loaded_ctrlp
CtrlPClearCache
endif
endfunction
map <Leader>rt :call RebuildCaches()<CR>
function! OpenInBrowser(url)
if has("mac")
exec '!open '.a:url
else
exec '!firefox -new-tab '.a:url.' &'
endif
endfunction
" Open the Ruby ApiDock page for the word under cursor
function! OpenRubyDoc(keyword)
let url = 'http://apidock.com/ruby/'.a:keyword
call OpenInBrowser(url)
endfunction
noremap RB :call OpenRubyDoc(expand('<cword>'))<CR><CR>
" Open the Rails ApiDock page for the word under cursor
function! OpenRailsDoc(keyword)
if filereadable('config/application.rb')
let url = 'http://apidock.com/rails/'.a:keyword
endif
call OpenInBrowser(url)
endfunction
noremap RR :call OpenRailsDoc(expand('<cword>'))<CR><CR>
" :SudoW to save file using sudo (must be already authorised, eg sudo -v)
command! -bar -nargs=0 SudoW :silent exe "write !sudo tee % >/dev/null"|silent edit!
" ack.vim
if executable('rg')
let g:ackprg = 'rg --vimgrep --no-heading'
endif
" Align =>
vnoremap <silent> <Leader>t> :Align =><CR>
" Use xmllint to pretty format XML
au FileType xml setlocal equalprg=xmllint\ --format\ --recover\ -\ 2>/dev/null
" customize line-number background (railscasts defaults are a bit rubbish)
highlight LineNr ctermbg=241 ctermfg=0 guibg=DimGray
" enable, and customise indentguides
if !has('gui')
let g:indent_guides_auto_colors = 0
endif
let g:indent_guides_enable_on_vim_startup = 1
highlight IndentGuidesOdd ctermbg=233
highlight IndentGuidesEven ctermbg=235
" settings for the git-gutter
highlight SignColumn ctermbg=234
" airline settings
"let g:airline_theme= "luna"
let g:airline_theme= "murmur"
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline#extensions#ale#enabled = 1
" turbux
let g:turbux_runner = 'tslime'
let g:turbux_command_rspec = 's'
let g:turbux_command_cucumber = 'c'
let g:no_turbux_mappings = 1
map <leader>s <Plug>SendTestToTmux
map <leader>S <Plug>SendFocusedTestToTmux
" set clipboard to unnamed, so it uses the system clipboard
"set clipboard=unnamed
" allow the . to execute once for each line of a visual selection
vnoremap . :normal .<CR>
" Source a local configuration file if available.
if filereadable(expand("~/.vimrc.local"))
source ~/.vimrc.local
endif