-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
executable file
·334 lines (254 loc) · 9.06 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
call plug#begin('~/.vim/plugged')
Plug 'preservim/nerdtree'
Plug 'jlanzarotta/bufexplorer'
Plug 'rbgrouleff/bclose.vim'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'jremmen/vim-ripgrep'
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'itchyny/lightline.vim'
Plug 'MattesGroeger/vim-bookmarks'
Plug 'bkad/CamelCaseMotion'
Plug 'Yggdroot/indentLine'
Plug 'ojroques/vim-oscyank'
Plug 'lifepillar/vim-solarized8'
Plug 'w0rp/ale'
Plug 'ludovicchabant/vim-gutentags'
Plug 'vim-scripts/VimCompletesMe'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'tpope/vim-rails'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-obsession'
Plug 'tpope/vim-rhubarb'
call plug#end()
" turn on syntax highlighting
syntax enable
" setup theme
set termguicolors
colorscheme solarized8_high
set background=dark
augroup SetSolarizedColorSchema
autocmd!
autocmd vimenter * ++nested colorscheme solarized8_high
augroup END
" change cursor based on mode
if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
endif
else
" Use a blinking vertical bar cursor in insert mode, and a blinking block in normal
if &term == 'xterm-256color' || &term == 'screen-256color'
let &t_SI = "\<Esc>[5 q"
let &t_EI = "\<Esc>[1 q"
endif
endif
" if a given file type (perl, ruby, python, c, etc) has its own special auto-indentation rules, use them
filetype plugin indent on
" Set file encoding
set encoding=utf-8
" allow clipboard across platforms
set clipboard^=unnamed,unnamedplus
" Show line numbers
set number
" add a line / column display in the bottom right-hand section of the screen.
set ruler
" --- Whitespace stuff ---
set nowrap
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
augroup SetGoWhitespace
autocmd!
autocmd filetype go setlocal noexpandtab
augroup end
" backspace should delete over line breaks and such
set backspace=indent,eol,start
" Do not display whitespace (list/nolist)
set nolist
" --- Search related ---
set hlsearch " highlight search matches
set incsearch " enable incremental searching
set ignorecase " searching is not case sensitive
set smartcase " When 'ignorecase' and 'smartcase' are both on, if a pattern contains an uppercase letter, it is case sensitive, otherwise, it is not.
set gdefault " search globally by default
" --- command line completion ----
" Pressing Tab (repeatedly) will autocomplete in command mode
set wildmenu
set wildmode=list:longest,list:full
"do not autocomplete the following
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,node_modules
" allow switching away from modified buffers. will keep the changes to the buffer without writing them to the file
set hidden
" Status bar - always show
set laststatus=2
" lightly highlight the current line on which the cursor is placed (turn this off if it gets annoying)
set cursorline
" lightly highlight the current column in which the cursor is placed (turn this off if it gets annoying)
" set cursorcolumn
" enable mouse support - sometimes handy
set mouse=a
" tell vim to scan the file for a modeline that contains in-line vim commands and options, just for that file
set modeline
set modelines=10
" Enable indent folding
set foldenable
set fdm=indent
set nofoldenable
set foldnestmax=10
set foldlevel=1
" Force vim to make backup copy and overwrite original
set backupcopy=yes
" Directories for swp files
set backupdir=~/.vim/backup
set directory=~/.vim/backup
" map ]q and [q to cnext and cprev in quickfix
nnoremap ]q :cnext<CR>
nnoremap [q :cprev<CR>
" highlight trailing whitespace as errors
match ErrorMsg '\s\+$'
" Removes trailing spaces
function! TrimWhiteSpace() abort
%s/\s\+$//e
endfunction
" remove trailing whitespace
nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
nnoremap <Leader>rtw :call TrimWhiteSpace()<CR>
augroup ReloadVimrcAfterEdit
autocmd!
" When vimrc is edited, reload it
autocmd bufwritepost .vimrc source ~/.vimrc
augroup END
augroup SetYamlIndent
autocmd!
" yaml requires 2 space indenting
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
augroup END
" Show (partial) command in the status line
set showcmd
" Super easy saves
nnoremap <leader>s :w<CR>
" Use jj to leave insert mode
inoremap jj <Esc>
" Use v to leave insert mode while in visual mode
vnoremap v <esc>
" NOTE: single escape causes vim to start in insert mode on debian9.
" unhilight on escape escape
noremap <esc><esc> :nohl<cr>
" --- NERDTree ---
nnoremap <Leader>n :NERDTreeToggle<CR>
" --- Buffer switching ---
nnoremap <Leader>bf :bnext<cr>
nnoremap <Leader>bb :bprevious<cr>
nnoremap <Leader>bc :Bclose<cr>
" --- ALE ---
let g:ale_ruby_rubocop_executable = 'bin/rubocop'
" only enable explicitly defined linters below
let g:ale_linters_explicit = 1
let g:ale_linters = {'javascript': ['eslint'], 'ruby': ['rubocop'], 'go': ['gopls']}
let g:ale_fixers = { 'javascript': ['prettier-eslint', 'eslint'], 'typescript': ['prettier-eslint', 'eslint'], 'typescriptreact': ['prettier-eslint', 'eslint'], 'ruby': ['rubocop'], 'go': ['gofumpt']}
let g:ale_linter_aliases = {'typescriptreact': 'typescript'}
" use rubocop if there's a config for it
if filereadable(".rubocop.yml")
let g:ale_linters.ruby = ['mri', 'rubocop']
let g:ale_fixers.ruby = ['rubocop']
endif
" fix files automatically on save.
let g:ale_fix_on_save = 1
" ale go completion
let g:ale_go_langserver_executable = ''
let g:ale_completion_enabled = 0
"--- FZF ---
set rtp+=~/.fzf
" map leader+ff to fuzzy find files
nnoremap <Leader>ff :Files<CR>
" map leader+fc to find commits
nnoremap <Leader>fc :Commits<CR>
"--- vim-commentary ---
nmap <leader>c gc<CR>
"--- vim-javascript ---
" do not syntax highlight jsdocs
let g:javascript_plugin_jsdoc = 0
" --- vim-jsx ---
" jsx extension is not required for syntax highlighting and indenting
let g:jsx_ext_required = 0
" --- vim-go ---
" use the gopls language server
let g:go_gopls_enabled = 1
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" Specifies the type of list to use for command outputs (such as errors from builds, results from static analysis commands, etc...
let g:go_list_type="quickfix"
" Use a popup window for Shift+K and :GoDoc rather than preview window
let g:go_doc_popup_window = 1
" Highlight struct and interface names.
let g:go_highlight_types = 1
" Highlight struct field names.
let g:go_highlight_fields = 1
" Highlight function and method declarations.
let g:go_highlight_functions = 1
" Highlight function and method calls.
let g:go_highlight_function_calls = 1
" Highlight operators such as `:=` , `==`, `-=`, etc.
let g:go_highlight_operators = 1
" Highlight commonly used library types (`io.Reader`, etc.).
let g:go_highlight_extra_types = 1
" Highlights build constraints.
let g:go_highlight_build_constraints = 1
" Highlight go:generate directives.
let g:go_highlight_generate_tags = 1
" Highlight printf-style formatting verbs inside string literals.
let g:go_highlight_format_strings = 1
" Highlight variable names in variable declarations (`x` in ` x :=`).
let g:go_highlight_variable_declarations = 1
" Highlight variable names in variable assignments (`x` in `x =`).
let g:go_highlight_variable_assignments = 1
" Highlight diagnostic errors.
let g:go_highlight_diagnostic_errors = 1
" Highlight diagnostic warnings.
let g:go_highlight_diagnostic_warnings = 1
" --- vim-gutentags ---
if filereadable('/usr/local/bin/ctags')
" homebrew
let g:gutentags_ctags_executable = '/usr/local/bin/ctags'
else
let g:gutentags_ctags_executable = 'ctags'
endif
set statusline+=%{gutentags#statusline()}
" --- indentline ---
let g:indentLine_char = '⦙'
let g:indentLine_fileTypeExclude = ['json']
" --- CamelCaseMotion ---
let g:camelcasemotion_key = '<leader>'
" --- vim-obsession ---
let g:sessions_dir = '~/vim-sessions'
" start session - displays listing of existing session files.
" BS are to delete the *.vim part after typing it.
exec 'nnoremap <Leader>ss :Obsession ' . g:sessions_dir . '/*.vim<C-D><BS><BS><BS><BS><BS>'
" restore session
exec 'nnoremap <Leader>sr :so ' . g:sessions_dir. '/*.vim<C-D><BS><BS><BS><BS><BS>'
" pause session
nnoremap <Leader>sp :Obsession<CR>
" destroy session
nnoremap <Leader>sx :Obsession!<CR>
"--- enable matchit macro for do...end and various others ---
runtime macros/matchit.vim
" --- pretty print json using python
command! PrettyPrintJSON %!python3 -m json.tool
command! PrettyJSON PrettyPrintJSON
command! PrettyJson PrettyPrintJSON
command! FormatJSON PrettyPrintJSON
command! FormatJson PrettyPrintJSON
" " --- yank text in visual mode using the ANSI OSC52 sequence ---
vnoremap <leader>y :OSCYankVisual<CR>
vnoremap yy :OSCYankVisual<CR>
" --- copy file path of current buffer to clipboard ---
nnoremap <leader>cp :let @" = expand("%")<cr>:OSCYankRegister "<CR>