-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
333 lines (267 loc) · 10.2 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
" Specify a directory for plugins
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin('~/.vim/plugged')
" Make sure you use single quotes
Plug 'mileszs/ack.vim'
Plug 'tyru/current-func-info.vim'
Plug 'junegunn/goyo.vim'
Plug 'sjl/gundo.vim'
Plug 'SirVer/ultisnips'
Plug 'scrooloose/nerdcommenter'
Plug 'dense-analysis/ale'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-sleuth'
Plug 'tpope/vim-surround'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'xolox/vim-session'
Plug 'xolox/vim-misc'
Plug 'kopischke/vim-fetch'
Plug 'othree/yajs.vim'
Plug 'easymotion/vim-easymotion'
Plug 'scrooloose/nerdtree'
Plug 'mdempsky/gocode', { 'rtp': 'vim', 'do': '~/.vim/plugged/gocode/vim/symlink.sh' }
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'danro/rename.vim'
Plug 'yuezk/vim-js'
Plug 'maxmellon/vim-jsx-pretty'
" Initialize plugin system
call plug#end()
" :PlugInstall [name ...]<CR> install plugins
" :PlugUpdate [name ...]<CR> install or update plugins
" :PlugClean<CR> remove unused directories
" :PlugUpgrade<CR> upgrade VimPlug itself
" :PlugStatus<CR> upgrade VimPlug itself
set nocompatible " Disable vi compatibility
set nostartofline " Don't jump to the start of the line when switching buffers
syntax on " Syntax highlighting on.
set title " Set the title of the terminal
set nowrap " Don't wrap long lines
set backspace=indent,eol,start " Allow backspacing over tabs, and across lines
set number " Display line numbers
set showmatch " Show matching parenthesis/brackets
set history=1000 " Large history
set undolevels=1000 " Large undo history
set visualbell " Don't play sounds.
set noerrorbells " Don't play sounds.
set wildmenu " Visual autocomplete for command menu
set noswapfile " Turns off swapfiles
set ignorecase " Must be on for smartcase to work
set smartcase " Find/Replace: when searching, CIS if all lower, otherwise CS
set incsearch " Show search matches as you type
"set expandtab " Expand tabs into spaces
set tabstop=4 " 4 spaces inserted when tab is pressed
set softtabstop=4 " Set equal to tabstop to ensure use of spaces instead of tabs
set autoindent " Autoindent when hitting return.
set copyindent " Copy the structure of existing lines indent when autoindenting
set shiftwidth=4 " Controls indentation with shift >> << commands
set shiftround " Use multiple of shiftwidth when indenting with < and >
set smarttab " Insert tabs on the start of line based on shiftwidth, not tabstop
set hidden " buffers don't get unloaded, just hidden when they go away
set noexpandtab " Don't expand tabs into spaces
set cursorline " Highlight the cursor line.
set scrolloff=5 " Always show 5 lines above/below cursor.
set colorcolumn=80 " Highlight column 80 as a soft guide.
set textwidth=0 " Don't automatically wrap
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
set undofile " create an undo file to persist undo changes
set undodir=~/.vim/undos " save all the undos in one folder
set clipboard=unnamed " Use system clipboard, CHANGE TO unnamedplus FOR LINUX
set ssop-=options " do not store global and local values in a session
set ssop-=folds " do not store folds
" Attempt to make vim faster.
set redrawtime=3000
set lazyredraw
" 'Hybrid' https://jeffkreeftmeijer.com/vim-number/
set number relativenumber
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
let mapleader = ','
set guifont=Menlo:h12
"let g:solarized_termcolors=256
"set background=dark
colorscheme hybrid
map <leader>ad :ALEDetail<CR>
map <leader>at :ALEToggle<CR>
let g:ale_linters = {
\ 'php': [],
\ 'javascript': ['eslint', 'flow-language-server'],
\}
let g:ale_fixers = {
\ 'javascript': ['prettier'],
\ 'css': ['prettier'],
\}
let g:ale_fix_on_save = 1
let g:javascript_plugin_flow = 1
set laststatus=2 " For vim-airline to always show status bar.
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#ale#enabled = 1
let g:tmuxline_powerline_separators = 0
let g:airline#extensions#tabline#enabled = 1 " For vim-airline to enable tab/buffer line.
let g:airline#extensions#tabline#formatter = 'unique_tail'
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
" UltiSnips configuration
"let g:UltiSnipsExpandTrigger="<C-s>"
let g:UltiSnipsJumpForwardTrigger="<C-j>"
let g:UltiSnipsJumpBackwardTrigger="<C-k>"
" Enter and Shift-Enter add new lines before and after, with count.
nnoremap <silent> <Enter> :<C-u>put =repeat(nr2char(10),v:count)<Bar>execute "'[-1"<CR>
nnoremap <silent> <S-Enter> :<C-u>put!=repeat(nr2char(10),v:count)<Bar>execute "']+1"<CR>
nnoremap <leader>ts :%s/\s\+$//e<CR>
" Display current function in status line
nnoremap <leader>fn :echo cfi#format("%s", "")<CR>
" <leader>na (non-ascii) highlights non ascii chars.
"nnoremap <silent> <leader>na :syntax match nonascii "[^\x00-\x7F]" <CR> | :highlight nonascii guibg=Red ctermbg=2 <CR>
" Removes default s/S functionality, which I personally don't use, but this is
" not for everyone. Insert character under cursor with s, after with S.
nnoremap s :exec "normal i".nr2char(getchar())."\e"<CR>
nnoremap S :exec "normal a".nr2char(getchar())."\e"<CR>
" Insert a character at the end of the line.
nmap <leader>e :exec "s/$/".nr2char(getchar())<CR>
" Add keymaps to switch buffers back and forth and stuff
nmap <leader>. :bprevious<CR>
nmap <leader>/ :bnext<CR>
nmap <leader>t :enew<CR>
nmap <leader>bq :bp <BAR> bd #<CR>
" Clear word, brackets, curly braces, quotes and paste
for c in ['w', 'b', 't', '{', '}', '(', ')', '[', ']', '"', '''', '`']
execute "nmap <leader>pi" . c . " \"_di" . c . "P"
execute "nmap <leader>pvi" . c . " vi" . c . "pgvy"
endfor
" Add di" etc for underscores
"nmap di_ F_dt"
"nmap ci_ F_ct"
"nmap yi_ F_yt"
"nmap <leader>pi_ F_"_dt"P
" Add d, c, y, and p behavior for inner lines
nmap dil ^D
nmap cil ^C
nmap yil ^y$
nmap <leader>pil ^"_Dp
" Remap Y to be consistent with D, C, etc
nmap Y y$
" Yank filename
nmap <leader>yfp :let @+ = expand("%")<CR>
nmap <leader>yfn :let @+ = expand("%:t")<CR>
" Shortcut to turn off syntax highlighting for matches
nmap <leader>n :noh<CR>
" Shortcut to format file as json with json.tool
nmap <leader>fj :%!python -m json.tool<CR>
" fzf
" Search filenames only
command! Filenames call fzf#run(fzf#wrap())
command! -bang -nargs=* GFilenames call fzf#vim#gitfiles(<q-args>, { 'options': ["-d", "/", "-n", "-1", "-m", "--prompt", "GFilenames\> ", "--preview", "head -$LINES {}"] }, <bang>0)
command! -bang -nargs=* TagsJump call fzf#vim#tags(expand('<cword>'), {'options': '--exact --select-1 --exit-0'}, <bang>0)
nmap <C-p> :GFilenames<CR>
nmap <C-l> :Files<CR>
nmap <leader>gs :GFiles?<CR>
nmap <C-]> :TagsJump<CR>
" easymotion, ugh
map f <Plug>(easymotion-fl)
map F <Plug>(easymotion-Fl)
map t <Plug>(easymotion-tl)
map T <Plug>(easymotion-Tl)
map yf y<Plug>(easymotion-fl)
map yF y<Plug>(easymotion-Fl)
map yt y<Plug>(easymotion-tl)
map yT y<Plug>(easymotion-Tl)
map df d<Plug>(easymotion-fl)
map dF d<Plug>(easymotion-Fl)
map dt d<Plug>(easymotion-tl)
map dT d<Plug>(easymotion-Tl)
map cf d<Plug>(easymotion-fl)
map cF c<Plug>(easymotion-Fl)
map ct c<Plug>(easymotion-tl)
map cT c<Plug>(easymotion-Tl)
let g:EasyMotion_smartcase = 1
nnoremap <Leader><Leader>f f
nnoremap <Leader><Leader>F F
nnoremap <Leader><Leader>t t
nnoremap <Leader><Leader>T T
nnoremap <Leader><Leader>yf yf
nnoremap <Leader><Leader>yF yF
nnoremap <Leader><Leader>yt yt
nnoremap <Leader><Leader>yT yT
nnoremap <Leader><Leader>df df
nnoremap <Leader><Leader>dF dF
nnoremap <Leader><Leader>dt dt
nnoremap <Leader><Leader>dT dT
" Functions to enable and disable word wrap
function! WordWrap()
:set wrap
:set linebreak
nmap j gj
nmap k gk
endfunction
function! NoWordWrap()
:set nowrap
:set nolinebreak
nmap j j
nmap k k
endfunction
nmap <leader>ww :call WordWrap()<CR>
nmap <leader>nww :call NoWordWrap()<CR>
command! GitlabUrl silent execute '!source ~/.zshrc && gitlab-url ' . expand('%') . ':' . line('.') . ' | pbcopy' | execute ':redraw!'
function! GitlabLog()
if mode() == 'n' || mode() == 'v'
silent execute '!echo ''git log -L' . line("'<") . ',' . line("'>") . ':' . expand('%') . ''' | pbcopy' | execute ':redraw!'
else
silent execute '!echo ''git log -L' . line(".") . ',' . line(".") . ':' . expand('%') . ''' | pbcopy' | execute ':redraw!'
endif
endfunction
command! GitlabLog :call GitlabLog()
" Reload .vimrc
nmap <leader>rr :source $MYVIMRC<CR>
" Print full file path
nmap <leader>pwd :echo expand('%:p')<CR>
" Turn off vim-session autosave prompt
let g:session_autosave = 'no'
let g:session_autoload = 'no'
" Turn off autocommenting of next line.
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
" Store session
"set sessionoptions+=resize,winpos,buffers,tabpages,options
"autocmd VimLeave * :mksession! ~/.vim/Session.vim
"autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | :source ~/.vim/Session.vim | endif
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
" Necesarry for nerdcommenter
filetype plugin on
" Turn on autocomplete
set omnifunc=syntaxcomplete#Complete
set completeopt+=longest,menuone
autocmd CompleteDone * pclose
inoremap <C-n> <c-x><c-o>
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" vim-go window only show first error
let g:go_list_height = 2
" :W maps to w so if shift is still being held when typing w, it works
command! W w
" :Wsudo sudo saves the file
command! Wsudo w !sudo tee % > /dev/null
" Switch CWD to the directory of the open buffer
map <leader>cd :Gcd<cr>:pwd<cr>
" Switch CWD to gitdir
map <leader>gcd :Gcd<cr>