-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
410 lines (335 loc) · 12 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
" call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'mileszs/ack.vim'
Plugin 'github/copilot.vim'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'FelikZ/ctrlp-py-matcher'
Plugin 'dyng/ctrlsf.vim'
Plugin 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plugin 'itchyny/lightline.vim'
Plugin 'scrooloose/nerdcommenter'
Plugin 'scrooloose/nerdtree'
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
Plugin 'ervandew/supertab'
Plugin 'tpope/vim-bundler'
Plugin 'altercation/vim-colors-solarized'
Plugin 'tpope/vim-dispatch'
Plugin 'elixir-editors/vim-elixir'
Plugin 'tpope/vim-fugitive'
Plugin 'airblade/vim-gitgutter'
Plugin 'roxma/vim-hug-neovim-rpc'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'sheerun/vim-polyglot'
Plugin 'tpope/vim-rails'
Plugin 'tpope/vim-repeat'
Plugin 'thoughtbot/vim-rspec'
Plugin 'vim-ruby/vim-ruby'
Plugin 'tpope/vim-sensible'
Plugin 'tpope/vim-surround'
" All of your Plugins must be added before the following line
call vundle#end() " required
syntax on
filetype plugin indent on
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" Turn deoplete on by default
" Disabling deoplete for now because it conflicts with CoPilot
" auto-complete and I prefer the CoPilot suggestions.
" call deoplete#enable()
" Enable Syntax Highlighting through vim-javascript plugin
let g:javascript_plugin_jsdoc = 1
" vim_jsx_pretty setup
"let g:vim_jsx_pretty_enable_jsx_highlight = 0 " default 1
" Colorful style vim-js-only
let g:vim_jsx_pretty_colorful_config = 1 " default 0
" VIM-JSX highlighting
let g:jsx_ext_required = 0
" Turn the numbers off in terminal mode
au TermOpen * setlocal nonumber norelativenumber
" Set proper formatting and spellcheck for commit messages
autocmd Filetype gitcommit setlocal spell textwidth=72
" Turn the goddamn bell off
set belloff=all
" Set the background to dark
set background=dark
" Always show current position
set ruler
" Height of the command bar
set cmdheight=2
" NERDTree configuration
let NERDTreeIgnore=['\.pyc$', '\.rbc$', '\~$']
map <Leader>n :NERDTreeToggle<CR>
let NERDTreeShowHidden = 1 " Show hidden files
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" automatically reload unmodified buffers when edited externally
set autoread
" improve screen refresh for terminal vim
set ttyfast
" Open new split panes to right and bottom, which feels more natural than Vim’s default:
set splitbelow
set splitright
" Automatically rebalance windows on vim resize
autocmd VimResized * :wincmd =
" Treat all lines equally, even if wrapped
nmap k gk
nmap j gj
" screen not redrawn during command execution<
set lazyredraw
" Ignore case when searching
set ignorecase
" Highlight search results
set hlsearch
" Make search act like search in modern browsers
set incsearch
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 2 spaces
set shiftwidth=2
set tabstop=2
" Linebreak on 80 characters
set lbr
set tw=80
" Auto indent, Smart indent, and Wrap lines
set ai
set si
set wrap
" Use line numbers in the gutter
" turn hybrid line numbers on
" set number relativenumber
" set nu rnu
set number
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif
autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
augroup END
" Allow nvim/vim to copy to the macOS clipboard using the mouse/trackpad
set mouse=a
set cb=unnamed
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
" Set 7 lines to the cursor when moving vertically using arrows or j/k
set so=7
" Map 'jk' and 'kj' to <esc> while in insert mode
imap jk <esc>
imap kj <esc>
" Map Ctrl-S to function like Command-S in a GUI editor(i.e. Save)
map <C-s> <esc>:w<CR>
imap <C-s> <esc>:w<CR>
" Custom mappings to open and source .vimrc
"nmap <Leader>vr :vsp $MYVIMRC<CR>
nmap <Leader>vr :vsp ~/.vimrc<CR>
"nmap <Leader>so :source $MYVIMRC<CR>
nmap <Leader>so :source ~/.vimrc<CR>
" Rebind keys for neovim's terminal mode
if has('nvim')
tnoremap <Esc> <C-\><C-n>
tnoremap <A-[> <Esc>
tnoremap <a-h> <c-\><c-n><c-w>h
tnoremap <a-j> <c-\><c-n><c-w>j
tnoremap <a-k> <c-\><c-n><c-w>k
tnoremap <a-l> <c-\><c-n><c-w>l
nnoremap <a-h> <c-w>h
nnoremap <a-j> <c-w>j
nnoremap <a-k> <c-w>k
nnoremap <a-l> <c-w>l
endif
" Fuzzy Finder plugins and using pt for searching
let g:ctrlp_map = ',f' "type comma and then f to activate ctrlP
"let g:ctrlp_cmd = 'CtrlPMixed' "start CtrlP in Mixed mode
let g:ctrlp_cmd = 'CtrlP' "start CtrlP in files mode
"let g:ctrlp_working_path_mode = 'ra' "Look for files in this project
let g:ctrlp_working_path_mode = 0 "Look for files in this directory only
" use a custom command to do searching instead of CtrlP's built in search
" which is slow.
let g:ctrlp_user_command = 'pt %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .DS_Store
\ --ignore .bundle
\ -g ""'
" Use a faster matching function
"let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
" With the user command, there's no need to have caching because it's fast enough
let g:ctrlp_use_caching = 0
" Set shortcut for Ack
map <Leader>F :Ack
" Trying to set Ack to use pt for search
let g:ackprg = 'pt --nocolor --nogroup'
" Custom command that allows one to create a new file in a folder with a one-liner
"command -nargs=1 E execute('silent! !mkdir -p "$(dirname "<args>")"') <Bar> e <args>
" Custom command allowing me to delete the current file and its buffer
" map <Leader>D :call delete(@%)|bdelete!
"---------GitGutter Settings----------
" Start GitGutter automatically
let g:gitugtter_sign_column_always = 1
" Make GitGutter symbols show up faster than default
set updatetime=250
" Make lightline display the git branch and other basic settings
let g:lightline = {
\ 'colorscheme': 'jellybeans',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"+":&modifiable?"":"-"}'
\ },
\ 'component_function': {
\ 'fugitive': 'LightlineFugitive',
\ 'filename': 'LightlineFilename'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
\ 'fugitive': '(exists("*FugitiveHead") && ""!=FugitiveHead())'
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' }
\ }
" Display the relative filename in lightline
function! LightlineFilename()
let root = fnamemodify(get(b:, 'git_dir'), ':h')
let path = expand('%:p')
if path[:len(root)-1] ==# root
return path[len(root)+1:]
endif
return expand('%')
endfunction
" Copy the relative file path of the current buffer to clipboard
nnoremap <leader>f :!echo -n % \| pbcopy<cr>:echom "FilePath copied to clipboard!"<CR>
" Display the git branch name in the lightline bar
function! LightlineFugitive()
if exists("*FugitiveHead()")
let mark = ' '
let branch = FugitiveHead()
return branch !=# '' ? ' '.branch : ''
endif
return ''
endfunction
" Use a line cursor within insert mode and a block cursor everywhere else.
"
" Using iTerm2? Go-to preferences / profile / colors and disable the smart bar
" cursor color. Then pick a cursor and highlight color that matches your theme.
" That will ensure your cursor is always visible within insert mode.
"
" Reference chart of values:
" Ps = 0 -> blinking block.
" Ps = 1 -> blinking block (default).
" Ps = 2 -> steady block.
" Ps = 3 -> blinking underline.
" Ps = 4 -> steady underline.
" Ps = 5 -> blinking bar (xterm).
" Ps = 6 -> steady bar (xterm).
" let &t_SI = "\e[5 q"
" let &t_EI = "\e[2 q"
" Enable blinking together with different cursor shapes for insert/command mode, and cursor highlighting:
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,n-v-c-sm:block-blinkon0
" Show matching brackets when text indicator is over them
set showmatch
" This didn't seem to do anything. Commenting out for now
" hi MatchParen cterm=bold ctermbg=lightgrey ctermfg=lightyellow
" How many tenths of a second to blink when matching brackets
set mat=8
" Display whitespace characters as visible characters
set list
set listchars=tab:→\ ,trail:⋅
set lcs+=space:·
" Function to strip trailing whitespace.
function! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
" Call the whitespace stripping function on write.
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
" Some golang specific settings. Testing this out to see if I like it.
augroup vimrc_golang
autocmd!
autocmd FileType go iabbrev <buffer> err- if err != nil {<C-j>log.Fatal(err)<C-j>}<C-j>
autocmd FileType go setlocal tabstop=4 shiftwidth=4 noexpandtab copyindent softtabstop=0 listchars=tab:→\ ,trail:⋅ lcs+=space:⋅
if exists("$GOPATH")
let s:gopaths = split($GOPATH, ':')
for s:gopath in s:gopaths
"set up Golint https://github.com/golang/lint
if isdirectory(s:gopath."/src/github.com/golang/lint/misc/vim")
exe 'set runtimepath+='.s:gopath.'/src/github.com/golang/lint/misc/vim'
autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow
break
endif
endfor
endif
augroup END
" RSpec.vim mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
" Tell RSpec.vim to use iTerm2
let g:rspec_runner = "os_x_iterm2"
" Make it use bundle exec because fucking reasons
let g:rspec_command = "!bundle exec rspec {spec}"
" Set the column marker to 101 characters
set colorcolumn=+21
" Add a function to toggle the color column
function! ToggleColorColumn()
if &colorcolumn == ""
set colorcolumn=+21
echo "Color column enabled"
else
set colorcolumn=""
echo "Color column disabled"
endif
redraw
endfunction
map <Leader>v :call ToggleColorColumn()<CR>
" higlight search but not when sourcing .vimrc
" This prevents the search highlighting from being applied when sourcing the
" .vimrc file.
set hls
let @/ = ""
" Mappings to move a selected line up or down
nnoremap <silent> <C-j> :m .+1<CR>==
nnoremap <silent> <C-k> :m .-2<CR>==
inoremap <silent> <C-j> <Esc>:m .+1<CR>==gi
inoremap <silent> <C-k> <Esc>:m .-2<CR>==gi
vnoremap <silent> <C-j> :m '>+1<CR>gv=gv
vnoremap <silent> <C-k> :m '<-2<CR>gv=gv
" Remap the copilot-next to use option key
nmap <M-]> <D-'>
" Remap <leader>p to paste yanked text after the last character on the current line in normal mode
nnoremap <leader>p g$p
" Remap <leader>V to visually select to the last non-blank character on the line without selecting the newline
nnoremap <leader>V v g_