-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
348 lines (294 loc) · 12.9 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
335
336
337
338
339
340
341
342
343
344
345
346
347
"----------------------------------------------------------------------------
" __
" __ __ /\_\ ___ ___ _ __ ___
" /\ \/\ \\/\ \ /' __` __`\/\`'__\/'___\
" __\ \ \_/ |\ \ \/\ \/\ \/\ \ \ \//\ \__/
" /\_\\ \___/ \ \_\ \_\ \_\ \_\ \_\\ \____\
" \/_/ \/__/ \/_/\/_/\/_/\/_/\/_/ \/____/
"
" This .vimrc file uses folding to manage the display of its contents.
" Use the 'zR' command to open all of the sections if you're lost...
" ----------------------------------------------------------------------------
" Base {{{
" ----------------------------------------------------------------------------
set shell=bash
set nocompatible " be iMproved, required
source $HOME/.vim/plug.vim " load plugins
filetype off " required
filetype plugin indent on " required
let mapleader="," " Set leader key to ','
set hidden " hide buffers so we don't have to write them when working on another file
set lazyredraw " redraw only when we need to.
set ttyfast
set shortmess+=I " No welcome screen
set history=200 " Remember the last 200 :ex commands
set exrc " Allow custom vim configs in project folders
set secure " Don't allow malicious vim configs
set autoread
set re=1 " Use old regex engine, faster for ruby syntax
set visualbell " Sweet silence
set timeoutlen=300 ttimeoutlen=10
" }}}-------------------------------------------------------------------------
" Command Line {{{
" ----------------------------------------------------------------------------
set cmdheight=1 " how tall is command line
set wildmenu " Enable menu during command tab completion
set wildmode=longest:full,full " 1st tab = longest commong string, subsequent show possible full matches
set ignorecase " case insensitive search
set smartcase " (unless your search query has caps)
" }}}-------------------------------------------------------------------------
" Status Line {{{
" ----------------------------------------------------------------------------
set noshowmode " don't show mode in last row, it's in airline.
set laststatus=2 " Always display the status line
let g:airline_powerline_fonts = 1 " Enable special powerline font (requires install)
let g:airline_theme='wombat'
let g:airline_left_sep='' " Controls airline separator characters
let g:airline_right_sep='' " these can get a little goofy depending on font
" }}}-------------------------------------------------------------------------
" Input and Navigation {{{
" ----------------------------------------------------------------------------
if has("mouse")
set mouse=a " Enable Mouse support
endif
set ttymouse=sgr
set mouse+=a
set scrolloff=3 " how many lines to pad between cursor and edge of page when scrolling
set backspace=indent,eol,start " allow backspacing over autoindent, line breaks, start of inserts
set showmatch " briefly jump to the matching brace when you insert one, use matchtime to control how long.
set hlsearch " highlight matched search results
nnoremap <CR> :nohlsearch<cr>| " remove highlighting when you hit <Enter>
set incsearch " move cursor to matched string while typing pattern
" Nerd Tree binding and plugin options
map <leader>n :NERDTreeToggle <Return>
nmap <leader>N :NERDTreeFind<CR>
let NERDTreeDirArrows=0
let NERDTreeIgnore = ['\.DS_Store$']
nnoremap <Leader>t :call PickFile()<CR>| " Pick binding (an awesome fuzzy finder plugin)
nnoremap <Leader>T :call PickBuffer()<CR>|
nnoremap <leader>u :GundoToggle<CR>| " Gundo binding (ultra-undo plugin)
if executable('ag')
" Use the silver searcher if available
let g:ackprg = 'ag --vimgrep'
endif
" }}}-------------------------------------------------------------------------
" Key Bindings {{{
" ----------------------------------------------------------------------------
" Note: pipe characters at the end of these commands are to allow
" inline comments. Gross hack job. But look how pretty!
command! Tab :Tabularize
map Q gq| " Shortcut to rewrap selected text
command! W :w " For fat fingers: make :W == :w
" imap <c-c> <esc>| " Map Ctrl-c to <Esc> to ease finger gymnastics
imap <S-CR> <CR><CR>end<Esc>-cc| " Shift-Enger to insert 'end' from insert mode, broken?
map <leader>m Jxi\n<ESC>| " Merge Lines, replacing newlines with \n char
map <leader>w :set wrap!<CR>| " Toggle line wrapping
nnoremap gV `[v`]| " Highlight last inserted text
cmap w!! w !sudo tee > /dev/null % " Sudo save something
vmap <C-y> :w !pbcopy<CR><CR>
" Shortcut to pretty-format ugly blocks of json
nmap <leader>j <Esc>:%!python -m json.tool<CR><ESC>gg=G<Esc>:noh<CR>
" Finding and replacing interactively using over-vim, thanks toranb
nnoremap <Leader>fr :call VisualFindAndReplace()<CR>
xnoremap <Leader>fr :call VisualFindAndReplaceWithSelection()<CR>
map <leader>R :call RunRubocop()<CR>
" Copy current file path to clipboard
map <leader>s :call CopySpecCommand() <CR>
map <leader>f :call CopyFilePath()<CR>
map <leader>p :call PasteToggle()<cr>
nmap <Leader>r :call RevealInFinder()<CR>
nmap <Leader>ct :call RegenerateCtagsForYCM()<CR>
nmap <Leader>cc :call CompleteCopyFile()<CR><CR><CR>
" }}}-------------------------------------------------------------------------
" Folding {{{
" ----------------------------------------------------------------------------
set foldenable " enable folding
set foldlevelstart=10 " open most folds by default
set foldnestmax=10 " 10 nested fold max
set foldmethod=indent " fold based on indent level
nnoremap <space> za| " space open/closes folds
" }}}-------------------------------------------------------------------------
" Indentation and Whitespace {{{
" ----------------------------------------------------------------------------
set tabstop=2 " How many spaces per <Tab> char, for existing text
set shiftwidth=2 " Number of space chars used for indentation
set softtabstop=2 " Treat our hard tabs like soft tabs (backspace deletes 2 spaces)
set expandtab " When inserting <Tab> char, write as spaces instead.
set autoindent " copies indentation level from the previous line, shouldn't interfere with filetype indent.
filetype plugin on " determine various behaviour by file extension
filetype indent on " indent based on file-type
" Filetype-specific settings
autocmd FileType javascript setlocal shiftwidth=4 tabstop=4 softtabstop=4
autocmd FileType python setlocal shiftwidth=4 tabstop=4 softtabstop=4
" }}}-------------------------------------------------------------------------
" Color & Syntax {{{
" ----------------------------------------------------------------------------
syntax on " enable file syntax highlighting
" set t_Co=256 " Force 256 color only if needed
if &term == "screen"
set t_Co=256 " Force 256 color only if needed
endif
set background=dark " Use dark instead of light
colorscheme sierra
highlight NonText ctermfg=bg
let g:ruby_path = '~/.rbenv/shims/ruby'
let g:syntastic_ruby_checkers = ['rubocop', 'mri']
let g:syntastic_ruby_mri_exec = '~/.rbenv/shims/ruby'
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_eruby_ruby_quiet_messages = {'regex': 'possibly useless use of a variable in void context'}
" }}}-------------------------------------------------------------------------
" Appearance {{{
" ----------------------------------------------------------------------------
" let g:indentLine_noConcealCursor="" " prevent conflict in vim-json and indentLine
" let g:indentLine_char = '┆'
let g:indentLine_enabled = 0
set synmaxcol=500 " Prevent performance issues on long lines
set nowrap " Don't wrap lines by default
set cursorline " highlight cursor location
set number " show line numbers
" }}}-------------------------------------------------------------------------
" Plugin Configuration {{{
" ----------------------------------------------------------------------------
let g:table_mode_corner="|"
let g:ycm_collect_identifiers_from_tags_files = 1
let g:UltiSnipsExpandTrigger="<tab><tab>"
let g:vim_markdown_conceal = 0
let g:vim_markdown_fenced_languages = ['ruby=rb', ['js=js']]
" }}}-------------------------------------------------------------------------
" Custom Functions {{{
" ----------------------------------------------------------------------------
function! CopyFilePath()
let filePath = Chomp(fnamemodify(expand("%"), ":~:."))
echo filePath
execute ':silent !echo ' . filePath . " | pbcopy"
redraw!
echo "Path to file copied to clipboard!"
endfunction
" Copy spec command of current line in file
" This makes the full spec command on your behalf, and puts it on the system
" clipboard for you to call wherever you like. Using relative paths allows
" this to work when your rails app is running in some kind of container.
function! CopySpecCommand()
let l:lineNumber = line('.')
let l:filePath = fnamemodify(expand("%"), ":~:.")
let l:fullPath = "rspec " . "./" . l:filePath . ":" . l:lineNumber
execute ':silent !echo ' . l:fullPath . " | pbcopy"
redraw!
echo "Spec command copied to clipboard!"
endfunction
" Paste Toggle
" The following sets a variable to keep track of paste mode, and turns
" both paste mode and insert lines on and off for copying and pasting
let g:pasteMode = 0
function! PasteToggle()
if g:pasteMode
" bufdo IndentLinesEnable
GitGutterEnable
set nopaste
set nowrap
set number
if has("mouse")
set mouse=a
endif
setlocal conceallevel=2
let g:pasteMode = 0
echom "Paste mode OFF!"
else
" bufdo IndentLinesDisable
GitGutterDisable
set mouse=""
set paste
set wrap
set nonumber
setlocal conceallevel=0
let g:pasteMode = 1
echom "Paste mode ON!"
endif
endfunction
" Reveal files in the finder
function! RevealInFinder()
if filereadable(expand("%"))
let l:command = "open -R %"
elseif getftype(expand("%:p:h")) == "dir"
let l:command = "open %:p:h"
else
let l:command = "open ."
endif
execute ":silent! !" . l:command
" For terminal Vim not to look messed up.
redraw!
endfunction
" Copy complete contents of current file to clipboard
function! CompleteCopyFile()
! cat % | pbcopy
echom "Complete file copied to clipoard!"
endfunction
" Automatically create backup/cache dirs for vim
" in ~/.vim-tmp/
" Filenames are full paths with % separators
function! InitBackupDir()
if has('win32') || has('win32unix') "windows/cygwin
let l:separator = '_'
else
let l:separator = '.'
endif
let l:parent = $HOME . '/' . l:separator . 'vim-tmp/'
let l:backup = l:parent . 'backup/'
let l:tmp = l:parent . 'tmp/'
if exists('*mkdir')
if !isdirectory(l:parent)
call mkdir(l:parent)
endif
if !isdirectory(l:backup)
call mkdir(l:backup)
endif
if !isdirectory(l:tmp)
call mkdir(l:tmp)
endif
endif
let l:missing_dir = 0
if isdirectory(l:tmp)
execute 'set backupdir=' . escape(l:backup, ' ') . '/,.'
else
let l:missing_dir = 1
endif
if isdirectory(l:backup)
execute 'set directory=' . escape(l:tmp, ' ') . '/,.'
else
let l:missing_dir = 1
endif
if l:missing_dir
echo 'Warning: Unable to create backup directories:' l:backup 'and' l:tmp
echo 'Try: mkdir -p' l:backup
echo 'and: mkdir -p' l:tmp
set backupdir=.
set directory=.
endif
endfunction
call InitBackupDir()
function! VisualFindAndReplace()
:OverCommandLine%s/
:w
endfunction
function! VisualFindAndReplaceWithSelection() range
:'<,'>OverCommandLine s/
:w
endfunction
function! RunRubocop()
let filePath = fnamemodify(expand("%"), ":~:.")
execute ':silent w'
execute ':silent !NO_BUNDLE_EXEC=1 rubocop -f s -Ra ./' . filePath
redraw!
endfunction
function! RegenerateCtagsForYCM()
execute ":silent !ctags -R -f ./.tags --fields=+l"
redraw!
echo "Regenerated ctags in .tags"
endfunction
function! Strip(input_string)
return substitute(a:input_string, '^\s*\(.\{-}\)\s*$', '\1', '')
endfunction
function! Chomp(string)
return substitute(a:string, '\n\+$', '', '')
endfunction
" }}}