-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
313 lines (264 loc) · 8.84 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
" https://github.com/kaar/dotfiles/blob/master/.vimrc
" # SETTINGS #
" ### Visual ###
syntax on " syntax highlight
colorscheme ron " color schema:
set background=dark
filetype indent on
filetype plugin indent on
set number " show line numbers
set norelativenumber " disable relative line numbers, remove no to sample it
set synmaxcol=1200 " syntax coloring lines that are too long just slows down the world
set scrolloff=10 " let me see more
set ruler " see ruf for formatting
set showmode " show command and insert mode
set foldmethod=manual " manual folding
set nofoldenable " disable automatic folding at all times
set linebreak " visual break lines smarter
set wildmenu " better command-line completion
set cursorline " show line cursor
set relativenumber
" visualize whitespace characters
" Activate <F4> (:set list)
set listchars=space:*,trail:*,nbsp:*,extends:>,precedes:<,tab:\|>,eol:¬
" Mode-dependent cursor in vim (Mintty)
" still needed in gh gist edit, not sure why
" don't need it as long as i use xterm-256color
" well well...still needed to not keep insert mode in block mode
" I most be missing some setting
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
" ### Search ###
set ignorecase " ignore case for search
set smartcase " unless uppercase is used in search string
set incsearch " highlight and match when typing
set hlsearch " highlight matching search results
" ### Clipboard (Copy/Paste) ###
set clipboard=unnamedplus
" WSL yank support
let s:clip = 'clip.exe' " change this path according to your mount point
if executable(s:clip)
augroup WSLYank
autocmd!
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif
augroup END
endif
" ### Text and Formating ###
set autoindent " automatically indent new lines
set tabstop=2 " tab length
set softtabstop=2 " number of spaces in tab when editing
set shiftwidth=2 " number of spaces when shift ident
set smartindent " be smart with indent
set smarttab " be smart with tab
set expandtab " replace tabs with spaces automatically
set nofixendofline " stop vim from silently fucking with files that it shouldn't
" set textwidth=72 " enough for line numbers + gutter within 80 standard
set nowrap " no wrapping of text
set omnifunc=syntaxcomplete#Complete " enable omni-completion, Insert Mode: <C-X><C-O>
" ### Files and Backup ###
set autoread " auto-reload buffers when files are changed on disk
set autowrite " automatically write files when changing when multiple files open
set nobackup " more risky, but cleaner
set noswapfile " noswapfile
set nowritebackup " write without backup
" avoid most of the 'Hit Enter ...' messages
set shortmess=aoOtTI
" Disable Ex mode
map Q <Nop>
" ### Spelling ###
set spelllang=en_us
" activate for *.md
" autocmd BufRead,BufNewFile *.md setlocal spell
" start at last place you were editing
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" # KEYBINDINGS #
" space; leader key
let mapleader = " "
" remap escape
imap jj <Esc>
" split
nnoremap <leader>- :split<cr>
" split vertical
nnoremap <leader>/ :vsplit<cr>
" quit
nnoremap <leader>q <c-w>q
" close buffer
nnoremap <leader>c :bd<cr>
" write
nnoremap <leader>w :w<cr>
" select all
nnoremap <leader>a <esc>ggVG<CR>
" buffers
nnoremap <leader>b :Buffers<CR>
" toggle search highlight
nnoremap <leader>h :set hlsearch!<CR>
" quick pair word and selection
nnoremap <leader>" ciw"<C-r>""<Esc>
vnoremap <leader>" c"<C-r>""<Esc>
nnoremap <leader>' ciw'<C-r>"'<Esc>
vnoremap <leader>' c'<C-r>"'<Esc>
nnoremap <leader>( ciw(<C-r>")<Esc>
vnoremap <leader>( c(<C-r>")<Esc>
nnoremap <leader>[ ciw[<C-r>"]<Esc>
vnoremap <leader>[ c[<C-r>"]<Esc>
nnoremap <leader>{ ciw{<C-r>"}<Esc>
vnoremap <leader>{ c{<C-r>"}<Esc>
nnoremap <leader>` ciw`<C-r>"`<Esc>
vnoremap <leader>` c`<C-r>"`<Esc>
" check file in shellcheck:
map <leader>s :!clear && shellcheck -x %<CR>
" format file
nmap <leader>ff ggVG=
" fzf
nmap // :BLines<CR>
nmap ?? :Rg<CR>
nmap cc :Commands<CR>
nmap cm :Commits<CR>
nmap <C-P> :Files<CR>
" function keys
map <F1> :set number!<CR> :set relativenumber!<CR>
map <F3> :set hlsearch!<CR>
map <F4> :set list!<CR>
map <F5> :set cursorline!<CR>
map <F7> :set spell!<CR>
" move lines (Ctrl+[j,k,l,m])
inoremap <C-j> <Esc> :m .+1<CR>==i
inoremap <C-k> <Esc> :m .-2<CR>==i
" Move text in visual mode
vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv
" collides with vim-tmux-navigator
"nnoremap <C-j> <Esc> :m .+1<CR>==
"nnoremap <C-k> <Esc> :m .-2<CR>==
" completion menu
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>"
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
" keep things center
" n - next
" N - previews
" zz - center
" zv - open folds
nnoremap n nzzzv
nnoremap N Nzzzv
nnoremap J mzJ`z
" yank & paste
nnoremap <leader>y "+y
vnoremap <leader>y "+y
nnoremap <leader>Y gg"+yG
vnoremap <leader>p "_dP
" copy/paste
" make Y consitent with D and C (yank til end)
map Y y$
" jump buffers
" nmap J :bnext<CR>
" nmap K :bprev<CR>
" line break
nmap <C-CR> m'a<CR><Esc>`'
" nmap K m'a<CR><Esc>`'
" undo break points
" inoremap , ,<c-g>u
" inoremap . .<c-g>u
" inoremap ! !<c-g>u
" inoremap ? ?<c-g>u
" release my pinky
nnoremap ; :
" swap them around
" nnoremap : ;
" *** Emacs-Like in insert mode ***
" Go to beginning of the line [Normal Mode && Insert Mode]
map <C-a> <ESC>^
imap <C-a> <ESC>I
" Go to end of line [Normal Mode && Insert Mode]
map <C-e> <ESC>$
imap <C-e> <ESC>A
" Backward a word [Insert Mode]
inoremap <M-b> <Esc>Bi
" Forward a word [Insert Mode]
inoremap <M-f> <ESC><Space>Wi
" Delete a word (backward) [Insert Mode]
inoremap <M-d> <ESC><Space>cW
" maps gX to use xdg-open with a relative filepath under your cursor
nnoremap gX :silent :execute
\ "!xdg-open" expand('%:p:h') . "/" . expand("<cfile>") " &"<cr>
" NerdTree
map <C-b> :NERDTreeToggle<CR>
map <C-f> :NERDTreeFind<CR>
let g:NERDTreeDirArrowExpandable = '►'
let g:NERDTreeDirArrowCollapsible = '▼'
let NERDTreeShowLineNumbers=1
let NERDTreeShowHidden=1
let NERDTreeMinimalUI = 1
let g:NERDTreeWinSize=38
" indent with tab/s-tab
nnoremap <Tab> >>_
nnoremap <S-Tab> <<_
inoremap <S-Tab> <C-D>
vnoremap <Tab> >gv
vnoremap <S-Tab> <gv
" auto-center
nmap G Gzz
nmap n nzz
nmap N Nzz
nmap } }zz
nmap { {zz
" paste clipboard as markdown link
nmap <leader>pl i* []()<ESC>PF]i
" use arrows for number increment/decrement
nnoremap <up> <C-a>
nnoremap <down> <C-x>
" move cursor position back and forth in change list
nnoremap <left> g;
nnoremap <right> g,
" ### Commands ###
"
" format json using jq
command! FormatJson :execute '%!jq .'
command! VimEdit execute ':e ~/.vimrc'
command! VimReload execute ':source ~/.vimrc'
" ### Auto Commands ###
" rename tmux window when open *.md files
" autocmd BufReadPost,FileReadPost,BufNewFile *.md call system("tmux rename-window " . expand("%"))
" rename tmux window to current directory then closing markdown file
" autocmd VimLeave *.md call system("tmux rename-window " . expand('%:p:h:t'))
" Commenting blocks of code.
" ,cc - commment
" ,cu - uncomment
augroup commenting_blocks_of_code
autocmd!
autocmd FileType c,cpp,java,scala let b:comment_leader = '// '
autocmd FileType sh,ruby,python let b:comment_leader = '# '
autocmd FileType conf,fstab let b:comment_leader = '# '
autocmd FileType tex let b:comment_leader = '% '
autocmd FileType mail let b:comment_leader = '> '
autocmd FileType vim let b:comment_leader = '" '
autocmd FileType csharp let b:comment_leader = '# '
augroup END
noremap <silent> ,cc :<C-B>silent <C-E>s/^/<C-R>=escape(b:comment_leader,'\/')<CR>/<CR>:nohlsearch<CR>
noremap <silent> ,cu :<C-B>silent <C-E>s/^\V<C-R>=escape(b:comment_leader,'\/')<CR>//e<CR>:nohlsearch<CR>
" Remove trailing whitespace on write
" autocmd BufWritePre * %s/\s\+$//e
" Mark trailing spaces as errors
match ErrorMsg '\s\+$'
" Disable folding
let g:pandoc#modules#disabled = ["folding", "spell"]
" auto-pairs
" activate fly mode
let g:AutoPairsFlyMode = 1
" # vim-markdown (vim-polyglot)
" https://github.com/plasticboy/vim-markdown
" disable auto insert bullets
let g:vim_markdown_auto_insert_bullets = 0
let g:vim_markdown_new_list_item_indent = 0
" ### Functions
function! FixLastSpellingError()
" mm - set mark m at cursor pos
" [s - move to the previous misspelled word
" 1z= - pick first spelling suggestions
" 1m - jump to the mark m
normal! mm[s1z=`m
endfunction
nnoremap <leader>sp :call FixLastSpellingError()<cr>