This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
359 lines (305 loc) · 9.07 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
set nocompatible
" PLUGINGS {{{
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
set rtp+=/usr/local/opt/fzf
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'tpope/vim-fugitive'
Plugin 'w0rp/ale'
Plugin 'junegunn/fzf.vim'
Plugin 'tpope/vim-surround'
Plugin 'scrooloose/nerdtree'
Plugin 'ycm-core/YouCompleteMe'
" Plugin 'henrik/vim-indexed-search'
" Plugin 'vim-syntastic/syntastic'
Plugin 'tpope/vim-commentary'
" Plugin 'junegunn/vim-easy-align'
Plugin 'tpope/vim-repeat'
Plugin 'rafi/awesome-vim-colorschemes'
Plugin 'vim-scripts/ScrollColors'
" Plugin 'junegunn/goyo.vim'
Plugin 'SirVer/ultisnips'
" Plugin 'honza/vim-snippets'
Plugin 'ervandew/supertab'
Plugin 'tpope/vim-dadbod'
" Plugin 'neoclide/coc.nvim'
" filetype stuff
Plugin 'JamshedVesuna/vim-markdown-preview'
Plugin 'tpope/vim-markdown'
Plugin 'pangloss/vim-javascript'
Plugin 'tmhedberg/SimpylFold'
Plugin 'hdima/python-syntax'
Plugin 'posva/vim-vue'
Plugin 'cakebaker/scss-syntax.vim'
Plugin 'gregsexton/MatchTag'
Plugin 'vim-ruby/vim-ruby'
call vundle#end() " required
" for vim-markdown-preview
let g:vim_markdown_preview_github=1
let g:vim_markdown_preview_browser = 'Google Chrome'
let vim_markdown_preview_hotkey='<C-m>'
filetype plugin indent on " required
" }}}
" Utility functions {{{
function! IsGitDir()
let gitdir=system("git rev-parse --show-toplevel")
" See if the command output starts with 'fatal' (if it does, not in a git repo)
let isnotgitdir=matchstr(gitdir, '^fatal:.*')
return empty(isnotgitdir)
endfunction
" }}}
" Linting {{{
let g:ale_linters = {
\ 'javascript': ['eslint'],
\ 'typescript': ['eslint', 'prettier'],
\ 'sql': ['sqlint'],
\ 'python': ['pep8'],
\ 'ruby': ['rubocop'],
\}
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'python': ['autopep8'],
\ 'vue': ['eslint'],
\ 'ruby': ['rubocop'],
\ 'sql': ['sqlfmt'],
\}
let g:ale_lint_on_text_changed = 'normal'
let g:ale_fix_on_save = 1
let g:ale_javascript_standard_use_global=0
nnoremap <leader>al :ALELint<cr>
" }}}
" Key Mapping Setup {{{
" punishment {{{
inoremap <esc> <nop>
nnoremap <space> <nop>
nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <right> <nop>
nnoremap <left> <nop>
" }}}
let mapleader = " "
" }}}
" Gui settings {{{
set number
set relativenumber
set wiw=115
set hlsearch
set incsearch
syntax on
colorscheme brisket
set guioptions-=r
set guioptions-=l
" wildmenu
set wildchar=<Tab> wildmenu wildmode=full
nnoremap <leader>N :setlocal number! relativenumber!<cr>
augroup titleBarGroup
autocmd!
autocmd BufEnter * let &titlestring = getcwd() . " ----- " . expand("%")
augroup END
" Statusline {{{
set statusline=%f " Path to the file
set statusline+=\ -\ " Separator
set statusline+=%y " Filetype
set statusline+=%m
set statusline+=%= " Switch to the right side
set statusline+=%c\ \ " Current column
set statusline+=\[%5l " Current line
set statusline+=/ " Separator
set statusline+=%L\ \] " Total lines
set laststatus=2
" }}}
" }}}
" Navigation {{{
vnoremap H 0
vnoremap L $
vnoremap J <PageDown>
vnoremap K <PageUp>
nnoremap H 0
nnoremap L $
nnoremap J <PageDown>
nnoremap K <PageUp>
onoremap H 0
onoremap L $
onoremap J <PageDown>
onoremap K <PageUp>
" quickfix
nnoremap <leader>co :vert copen<cr> :vertical resize 80<cr>
nnoremap <leader>cc :cclose<cr>
nnoremap <leader>cf :cfirst<cr>
nnoremap <leader>cl :clast<cr>
nnoremap <leader>cj :cnext<cr>
nnoremap <leader>ck :cprevious<cr>
" help under cursor
nnoremap <leader>H K
cnoremap jk <C-c>
inoremap jk <esc>
" copy the current file path and line number into the 'l' register
nnoremap <leader>yy :let@l=join([expand('%'), line(".")], ':')<cr>
" remove next linebreak and surroounding whitespace
nnoremap <leader>aj $ma:s/\s*\n\s*/ /<cr>:noh<cr>`a
" remove previous linebreak and surroounding whitespace
nnoremap <leader>ak k$ma:s/\s*\n\s*/ /<cr>:noh<cr>`a
" adjust the behavior of backspace key in insert mode
set backspace=2
" }}}
" Windows and Tabs {{{
set splitbelow
set splitright
" easier than finding ctrl
nnoremap <leader>w <c-w>
nnoremap <leader>ww <c-w>c<c-w>
" tabs
nnoremap <leader>tj :tabprevious<cr>
nnoremap <leader>tk :tabnext<cr>
nnoremap <leader>tJ :tabfirst<cr>
nnoremap <leader>tK :tablast<cr>
nnoremap <leader>tc :tabnew<cr>
function! OpenBufferInNewTab()
let a:originalTab = tabpagenr() |" find the current tab number
echo a:originalTab
if tabpagewinnr(a:originalTab, '$') ==# 1
return
endif
let a:buf = bufnr("%") |" find buffer number
tabnew |" open new tab
let a:newTab = tabpagenr()
:execute "b".a:buf |" open buffer in new tab
:execute a:originalTab."tabnext" |" return to original tab
:q |" close window
:execute a:newTab."tabnext" |" return to new tab
endfunction
nnoremap <leader>tn :call OpenBufferInNewTab()<cr>
" }}}
" Indentation {{{
set expandtab
set shiftwidth=2
set autoindent
set smartindent
" format json
nnoremap <leader>jq :%!jq '.'<cr>
vnoremap <leader>jq :!jq '.'<cr>
" }}}
" Tab completion {{{
" MULTIPURPOSE TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
" inoremap <expr> <tab> InsertTabWrapper()
inoremap <s-tab> <c-n>
" }}}
" Run file {{{
" saves the current buffer into a temp file and runs it with source
function! RunFileInCurrentBuffer()
if &filetype ==# "vim"
write /tmp/vimrun
source /tmp/vimrun
!rm /tmp/vimrun
elseif &filetype ==# "sh"
execute "!source %"
endif
endfunction
noremap <leader>r :call RunFileInCurrentBuffer()<cr><cr>
" }}}
" Cursor style {{{
let &t_SI.="\e[5 q" "SI = INSERT mode
let &t_SR.="\e[4 q" "SR = REPLACE mode
let &t_EI.="\e[1 q" "EI = NORMAL mode (ELSE)
" }}}
" Highlighting {{{
" show errors
highlight Errors ctermbg=green guibg=darkred
nnoremap <leader>he :match Errors /\v\s+$/<cr>
nnoremap <leader>hE :match none<cr>
" set current line highlight in active window
augroup CursorLineOnlyInActiveWindow
autocmd!
autocmd InsertEnter,InsertLeave * set cul!
autocmd VimEnter,WinEnter,BufWinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
augroup END
" show info for the highlight group under the cursor
map <leader>hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" }}}
" Search {{{
nnoremap / /\v\c
nnoremap <leader>sg :Ggrep<space>
nnoremap <leader>ss :Ggrep '<cword>' <cr>
" }}}
" File Navigation {{{
" open filetype for current filetype
nnoremap <leader>ef :vsplit ~/.vim/ftplugin/<C-R>=&filetype<CR>.vim<CR>
" open vimrc
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" open bash_profile
nnoremap <leader>eb :vsplit ~/.bash_profile<cr>
" open .zshrc
nnoremap <leader>ez :vsplit ~/.zshrc<cr>
" open my personal vim todo list
nnoremap <leader>ea :vsplit ~/vim.annoyance<cr>
nnoremap <leader>en :vsplit notes.ariignore<cr>
nnoremap <leader>edb :vsplit scratch.SQL<cr>
nnoremap <leader>ed :vsplit .env<cr>
" fzf file searches
nnoremap <leader>eg :GFiles --exclude-standard --cached --others<cr>
nnoremap <leader>et :NERDTree<cr>
" open current colorscheme file
" assumes colorscheme is in a nicely named file
nnoremap <leader>ec :execute "vsplit ~/.vim/colors/".g:colors_name.".vim"<cr>
" }}}
" Git {{{
" vim-fugitive commands
" use "g?" in these to bring up help
nnoremap <leader>gb :Gblame<cr>
nnoremap <leader>gs :Gstatus<cr>
nnoremap <leader>gr :Gread<cr>
nnoremap <leader>gw :Gwrite<cr>
nnoremap <leader>gc :Gcommit<cr>
nnoremap <leader>gd :Gvdiff<cr>
nnoremap <leader>gps :Gpush<cr>
nnoremap <leader>gpl :Gpull<cr>
" }}}
" Copy Paste {{{
" yank to system clipboard
xnoremap <leader>c "+y
nnoremap <leader>c "+y
" paste from system clipboard
nnoremap <leader>v "+p
" shut off bracketed paste for system clipboard
set t_BE=
" }}}
" Performance {{{
" diable preprocessor checking. hopefullly speeds up vim-vue
let g:vue_disable_pre_processors=1
" }}}
" Snippets {{{
" open snippet file for current filetype
nnoremap <leader>es :UltiSnipsEdit<cr>
let g:UltiSnipsExpandTrigger="<tab>"
" for tabbing around in a snippet:
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
" If you want :UltiSnipsEdit to split your window.
let g:UltiSnipsEditSplit="vertical"
"this is a workaround for a bug that puts the snippet in the wrong place
let g:UltiSnipsSnippetDirectories = ['/Users/arikardasis/.vim/UltiSnips', 'UltiSnips']
" }}}
" make YCM compatible with UltiSnips (using supertab)
let g:ycm_key_list_select_completion = ['<C-n>', '<Down>']
let g:ycm_key_list_previous_completion = ['<C-p>', '<Up>']
let g:SuperTabDefaultCompletionType = '<C-n>'
" better key bindings for UltiSnipsExpandTrigger
let g:UltiSnipsExpandTrigger = "<tab>"
let g:UltiSnipsJumpForwardTrigger = "<tab>"
let g:UltiSnipsJumpBackwardTrigger = "<s-tab>"
set iskeyword+=-