-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.vim
307 lines (258 loc) · 7.76 KB
/
init.vim
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
call plug#begin('~/.nvim/bundle')
Plug 'tpope/vim-sensible'
Plug 'vimwiki/vimwiki'
Plug 'benekastah/neomake'
Plug 'kchmck/vim-coffee-script'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-endwise', { 'for': ['ruby', 'eruby'] }
Plug 'tpope/vim-bundler', { 'for': ['ruby', 'eruby'] }
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-rake', { 'for': ['ruby', 'eruby'] }
Plug 'tpope/vim-rails', { 'for': ['ruby', 'eruby'] }
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-abolish'
Plug 'tpope/vim-eunuch'
Plug 'Soares/butane.vim'
Plug 'vim-ruby/vim-ruby'
Plug 'tpope/vim-rails'
Plug 'peeja/vim-cdo'
Plug 'vim-scripts/restore_view.vim'
Plug 'nelstrom/vim-visual-star-search'
Plug 'rking/ag.vim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'noprompt/vim-yardoc', { 'for': ['ruby', 'eruby'] }
Plug 'AndrewRadev/splitjoin.vim', { 'for': ['ruby', 'eruby', 'coffees'] }
Plug 'SirVer/ultisnips'
Plug 'rust-lang/rust.vim', { 'for': ['rust'] }
Plug 'ntpeters/vim-better-whitespace'
Plug '/home/m/Projects/vim/witness_protection'
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
Plug 'radenling/vim-dispatch-neovim'
call plug#end()
let mapleader = ","
set backupdir=~/.nvim-tmp
set directory=~/.nvim-tmp
set history=10000
set undofile
set undodir=~/.vim-tmp
set undolevels=1000 "maximum number of changes that can be undone
set undoreload=10000 "maximum number lines to save for undo on a buffer reload
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
set background=dark
colorscheme solarized
set tabstop=2 softtabstop=2 shiftwidth=2 expandtab
if has("multi_byte")
set listchars=tab:▸\ ,eol:⤦
endif
set encoding=utf-8
set scrolloff=6
set number
set norelativenumber
set nocursorline
set ignorecase
set wrap
set splitbelow
set splitright
set textwidth=80
set winwidth=90
set diffopt+=iwhite
set diffexpr=""
set diffopt+=vertical
set autowrite
let g:c_no_comment_fold = 1
let g:vim_markdown_folding_disabled=1
let g:markdown_fenced_languages = [ 'ruby', 'st', 'c', 'scheme' ]
let $RUST_SRC_PATH="~/Projects/rust/rust"
set statusline=%< " Truncate from here if line is too long
set statusline+=%f " Path to the file
set statusline+=%h " Show help buffer flag is so
set statusline+=%m " Show modified flag is so
set statusline+=%r " Show readonly flag is so
set statusline+=\ -\ " separator
set statusline+=%y " filetype
if exists("*fugitive#statusline")
set statusline+=%{fugitive#statusline()} " Add fugitive niceties
endif
set statusline+=%= " move over to the right
set statusline+=%-14.(%l/%L,%c%) " Start group, line/total lines, column, end group
set statusline+=\ %P " Percentage through file
augroup filetype_muttrc
au!
au FileType muttrc setlocal foldmethod=marker
augroup end
augroup filetype_java
au!
au FileType java set makeprg=javac\ %
au FileType java set errorformat=%A%f:%l:\ %m,%-Z%p^,%-C%.%#
augroup end
augroup filetype_vim
au!
au FileType vim setlocal foldmethod=marker
augroup end
augroup filetype_scm
au!
au FileType scheme nnoremap <buffer> <leader>t :!./fmsc < %<cr>
augroup end
augroup filetype_cpp
au!
au FileType cpp nnoremap <buffer> <leader>t :!g++ -g % && ./a.out < input<cr>
augroup end
augroup filetype_c
au!
au FileType c setlocal foldmethod=syntax
au FileType c setlocal foldnestmax=1
augroup end
augroup filetype_mail
au!
augroup end
augroup erb_embedded_languages
au!
au BufNewFile,BufReadPre *.ajax_html.erb let b:eruby_subtype = 'html'
" au BufNewFile,BufReadPre *.md.erb let b:eruby_subtype = 'markdown'
augroup end
" Drew Neil's hide quickfix awesomeness
function! GetBufferList()
redir =>buflist
silent! ls
redir END
return buflist
endfunction
function! BufferIsOpen(bufname)
let buflist = GetBufferList()
for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
if bufwinnr(bufnum) != -1
return 1
endif
endfor
return 0
endfunction
function! ToggleQuickfix()
if BufferIsOpen("Quickfix List")
cclose
else
call OpenQuickfix()
endif
endfunction
function! OpenQuickfix()
cgetfile tmp/quickfix
topleft cwindow
if &ft == "qf"
cc
endif
endfunction
let g:vimwiki_list = [{'path': '/home/m/vimwiki/',
\ 'syntax': 'markdown',
\ 'nested_syntaxes': {'ruby': 'ruby', 'bash': 'bash', 'java': 'java', 'c': 'c', 'js': 'javascript', 'html': 'html'},
\ 'ext': '.md'}]
let g:vimwiki_global_ext = 0
",l to show unprintable characters
nnoremap <leader>l :set list!<CR>
" leader + space will clear search highlights
nnoremap <leader><space> :noh<cr>
" Tab will work for bracket matching nnoremap <tab> %
vnoremap <tab> %
" Windows changing
nnoremap <C-h> <C-W>h
nnoremap <bs> <C-W>h
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-l> <C-W>l
" Window resizing
nnoremap + <C-W>>
nnoremap _ <C-W><
"j k return to their initial column
nnoremap j gj
nnoremap k gk
"don't you hate when you accidentally hit f1?
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" Find all files in all non-dot directories starting in the working directory.
" Fuzzy select one of those. Open the selected file with :e.
nnoremap <leader>f :call fzf#run({'source': 'find_files_exclude_boring .', 'sink': 'e'})<cr>
" redraw vim
nnoremap <leader>R :redraw!<cr>
nnoremap <leader>Q :call ToggleQuickfix()<cr>
"go back to normal mode with kj
inoremap kj <ESC>
inoremap Kj <ESC>
inoremap kJ <ESC>
inoremap KJ <ESC>
" :edit in file in the same dir as current file shortcuts
cnoremap %% <C-R>=expand('%:h').'/'<cr>
"insert mode tag completion on ctrl ]
inoremap <c-]> <c-x><c-]>
"make ,b call rake
nnoremap <leader>b :w<cr>:Dispatch rake<cr>
"remap Q to esc so we dont go to ed mode accidentally
noremap Q <ESC>
" Create spec file for current file
nnoremap <silent> ,A :call GetSpec()<cr><cr>
nmap <leader>q :StripWhitespace<cr>
" Open raw quick fix window
nnoremap <leader>r :Copen!<cr>
" Make ultisnips use tab
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
nmap <leader>q :StripWhitespace<cr>
nnoremap <leader>t :call RunTestFile()<cr>
nnoremap <leader>T :call RunNearestTest()<cr>
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" Run the tests for the previously-marked file.
let in_test_file = match(expand("%"), '_spec.rb$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
function! SetTestFile()
" Set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
if filereadable("/home/m/bin/gbtest")
exec ":Dispatch gbtest " . a:filename
else
exec ":!rspec --color " . a:filename
end
endfunction
" Open or create spec file
function! GetSpec()
let spec_path=substitute(expand("%:p:h"), "/app/", "/spec/", "")."/"
let mkdir_command=":!mkdir -p ".spec_path
silent exec mkdir_command
let ruby_prog=expand("%:t:r")
let param_array=split(ruby_prog, '[A-Z][a-z]\+\zs')
let params=join(param_array, "_")
let g:spec=spec_path.params."_spec.rb"
redraw!
let editcmd="e ".g:spec
silent exec editcmd
endfunction
nnoremap <silent> ,A :call GetSpec()<cr><cr>
let g:neomake_ruby_enabled_makers = ['mri', 'rubocop']
let g:neomake_coffeescript_enabled_makers = ['coffeelint']
autocmd! BufWritePost * Neomake
noremap <leader>x WW:Bclose<cr>
nnoremap <leader>y :!yardstick %<cr>
set gdefault
let g:rustfmt_autosave = 1