-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
377 lines (319 loc) · 12.5 KB
/
Copy pathvimrc
File metadata and controls
377 lines (319 loc) · 12.5 KB
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
" use space as leader key
let mapleader = " "
map <Bslash> <nop>
" set custom folding for .vimrc, .ideavimrc, .zshrc, and .tmux.conf - use default markers: triple{ and triple} {{{
autocmd FileType vim,zsh,tmux :setlocal foldmethod=marker
"}}}
" plugins and related keymaps {{{
"ideaVim ignore
" the plug-in themselves that need to be ideavim ignored: {{{
" the built-in matchit plugin:
:filetype plugin on
runtime macros/matchit.vim
" vim-plug
" auto installation of vim-plug {{{
let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim'
if empty(glob(data_dir . '/autoload/plug.vim'))
silent execute '!curl -fLo '.data_dir.'/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" }}}
" use vim-plug
call plug#begin()
Plug 'unblevable/quick-scope'
" place inside autocmd to be called everytime colorscheme is changed
augroup qs_colors
autocmd!
" cterm: terminal vim; gui: macvim
autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=172 cterm=underline
autocmd ColorScheme * highlight QuickScopeSecondary guifg='#ec42f5' gui=underline ctermfg=163 cterm=underline
augroup END
Plug 'kana/vim-surround'
Plug 'easymotion/vim-easymotion'
" ideavim default maps: search / find n-char {{{
" but need to press return to show highlights, so is an annoying discrepancy
" therefore only use leader-s for multi-char searches, not f / t
nmap <Leader>s <Plug>(easymotion-sn)
vmap <Leader>s <Plug>(easymotion-sn)
" map <Leader>f <Plug>(easymotion-fn)
" map <Leader>F <Plug>(easymotion-Fn)
" map <Leader>t <Plug>(easymotion-tn)
" map <Leader>T <Plug>(easymotion-Tn)
" }}}
Plug 'preservim/nerdtree'
" autocmd FileType nerdtree setlocal relativenumber
" start nerd tree automatically and focus od it
autocmd VimEnter * NERDTree
" switch focus to the edited file
autocmd VimEnter * wincmd w
Plug 'kshenoy/vim-signature'
call plug#end()
" }}}
" ideaVim ignore end
" plugin configurations (ideavim compatible) {{{
" meant for ideavim -> the autocommand that sets the color can't be called in
" ideavim
" quickscope: configure color of letter that will be found after f then ;
let g:qs_secondary_color = '#ff00ff'
" to configure accepted characters to be used when highlighting
" let g:qs_accepted_chars = ['a', 'b', ... ]
" nerdtree
" don't use n/N - that's for easymotion next search
nnoremap <leader>o :NERDTree<CR>
nnoremap <leader>O :NERDTreeToggle<CR>
" vim style splits (s & v) won't work because nerdtree is still vim and v
" enters visual mode
" easymotion: ?
let g:EasyMotion_skipfoldedline = 0
" for surround with new line by enter key: see "https://github.com/tpope/vim-surround/issues/140#issuecomment-1012773520"
" but didn't work
let g:surround_{char2nr("\<CR>")} = "\n\r\n"
" }}}
" }}}
" ian's own keymaps {{{
"
" @@ = @" which makes no sense
" since you can't set the : (colon) register, use the e(ex-command) register
" instead
" use case: repeat the window resize action with @@
" nnoremap @@ @e
" vim's normal mode ! just accepts a motion and opens ex-command input with
" the selection appended by '!', which is easily done with V (visual mode) :
" then type '!'; so override that
nnoremap ! @e
" delete a bookmark - see custom function below
nnoremap m- :<c-u>call DeleteMarksOnCurrentLine()<CR>
" repeatable window resize:
" use \n instead of \r, because \r moves the cursor one line down for some
" reason other than executing the command
nnoremap <C-w>- :resize -10<CR>:let @e=":resize-10\n"<CR>
nnoremap <C-w>+ :resize +10<CR>:let @e=":resize+10\n"<CR>
nnoremap <C-w>< :vertical resize -10<CR>:let @e=":vertical resize-10\n"<CR>
nnoremap <C-w>> :vertical resize +10<CR>:let @e=":vertical resize+10\n"<CR>
" jump to a line that isn't empty and doesn't start with white-space:
" Top-level line (especially for python where [m doesn't work)
nnoremap [t ?^\S<CR>
nnoremap ]t /^\S<CR>
xnoremap [t ?^\S<CR>
xnoremap ]t /^\S<CR>
onoremap [t ?^\S<CR>
onoremap ]t /^\S<CR>
" 'Q' in normal mode enters Ex mode. You almost never want this.
nmap Q <Nop>
" to pair up with control W / U / H, and also stay consistent with Mac's default forward delete:
inoremap <C-d> <Del>
" escapes
inoremap jk <Esc>
inoremap kj <Esc>
cnoremap jk <C-C>
cnoremap kj <C-C>
" uncomment to always start (ex-command) search with `very magic` setting enabled: consistent regex
" (disabled now because it causes the ex-command line input dialog to show up with a significant delay)
nnoremap / /\v
vnoremap / /\v
onoremap / /\v
" cnoremap %s/ %smagic/
" cnoremap \>s/ \>smagic/
" nnoremap :g/ :g/\v
" map \(backslash: the default leader key) and shift-\ to jump through change list
nnoremap \ g;
" the first backslash is to escape the | char.
nnoremap \| g,
" Try to prevent bad habits like using the arrow keys for movement.
" use `echo` instead of `echoe` for compatibility issues with intelliJ
nnoremap <Left> :echo "Use h"<CR>
nnoremap <Right> :echo "Use l"<CR>
nnoremap <Up> :echo "Use k"<CR>
nnoremap <Down> :echo "Use j"<CR>
inoremap <Left> <ESC>:echo "Use ^O-h"<CR>
inoremap <Right> <ESC>:echo "Use ^O-l"<CR>
inoremap <Up> <ESC>:echo "Use ^O-k"<CR>
inoremap <Down> <ESC>:echo "Use ^O-j"<CR>
" (Control L) -> initially clears/redraws screen: map to :nohlsearch
" also do leader (space) - h
" for normal mode
nnoremap <C-l> :nohlsearch<cr>
nnoremap <leader>h :nohlsearch<cr>
" for visual / select mode: <C-u> to remove the range automatically added to command line
vnoremap <C-l> :<C-u>nohlsearch<cr>
" note: only macvim recognizes D and M as command and option key;terminal vim doesn't
" also these mappings just won't happen automatically so needs to be called as a function; see notion map keys page for the MacVim GitHub open issue.
function! MapMacModifierShortcuts()
inoremap <D-Left> <ESC>:echo "use jkI"<CR>
inoremap <D-Right> <ESC>:echo "use jkA"<CR>
inoremap <M-Left> <ESC>:echo "use jkbi"<CR>
inoremap <M-Right> <ESC>:echo "use jkea"<CR>
nnoremap <D-Left> <ESC>:echo "use 0"<CR>
nnoremap <D-Right> <ESC>:echo "use $"<CR>
nnoremap <M-Left> <ESC>:echo "use B"<CR>
nnoremap <M-Right> <ESC>:echo "use W"<CR>
endfunction
autocmd VimEnter * call MapMacModifierShortcuts()
" https://stackoverflow.com/a/13097329 : go to next error
nnoremap ]e :lnext
nnoremap [e :lprevious
" chrome vimium style tab switching;
" bumps the original J (do :join) instead, since it's rarer
" J for next, because j is down in vim
" note: gt supports count
nnoremap J gt
nnoremap K gT
"}}}
" other recommended settings (mostly "set"s and "let"s{{{
" be iMproved
set nocompatible
" (uncomment to) Enable mouse support. You should avoid relying on this too much, but it can
" sometimes be convenient.
" set mouse+=a
" Turn on syntax highlighting.
syntax on
" Disable the default Vim startup message.
set shortmess+=I
" Show line numbers.
" experiment to replace line motions with easymotion -
" better because that would count as a jump and saved to jump list, but doing
" count + j / k doesn't.
set number
set relativenumber
"
" status line at the bottom, even if you only have one window open.
set laststatus=2
" backspace over anything.
set backspace=indent,eol,start
" See `:help hidden` for more information on this. (uncomment to disable
" protection against unsaved buffer )
" set hidden
" case-insensitive search when entering all lower-case pattern.
" search becomes case-sensitive if it contains any capital letters.
set ignorecase
set smartcase
" enable highlight search to show all matches,
" `:noh` to turn off the hilighting until next search (but a hassle if you want to use search to navigate within a line)
" mapped control-l to :nol - see the keymap section
set hlsearch
" Enable searching as you type, rather than waiting till you press enter.
set incsearch
" Disable audible bell because it's annoying.
set noerrorbells visualbell t_vb=
" auto-indent tells vim to apply the indentation of the current line to the next
set autoindent
set smartindent
" set tab size to 4;
" meaning that 1 `\t` character will be displayed as 4 columns on the screen.
" so that's what you get when pressisng the tab key in insert mode
set tabstop=4
" set shift size to 4 too;
" meaning the indent level will be 4 columns wide.
" so that's what you get when you do '>>' in normal mode.
" but there's no `\t` character when you do this. right?
set shiftwidth=4
" }}}
" ian's own preferences - mostly graphical {{{
let &t_SI="\033[5 q" " start insert mode, vertical cursor
let &t_EI="\033[1 q" " end insert mode, blinking block
let &t_SR.="\e[4 q" "SR = REPLACE mode
" show "c" on the bottom right for operator-pending mode
set showcmd
colorscheme industry
" transparency variable only works for MacVim
" if has("gui_running")
" set transparency=18
" endif
" hide terminal Vim's background, effectively making it transparent if you have the terminal background set as transparent.
" but enabling it reduces the contrast
hi Normal guibg=NONE ctermbg=NONE
" highlight status bar of active window
" must be placed after colorscheme setting, otherwise overriden
highlight StatusLine ctermfg=black guifg=#ffffff ctermbg=green guibg=#4e4e4e
set guifont=MesloLGS-NF-Regular:h13
set linespace=3
"default split position:
set splitbelow
set splitright
" customize tab completion behavior - to like zsh ( practical vim tip 32 )
" provides a navigatable list of suggestions. ( tab, C-n, right to scroll forward
set wildmenu
set wildmode=full
" status line:
" display window number - then <window number> - C-w w: switch to that window
set statusline=win-
set statusline+=%{winnr()}\
" display file full path
set statusline+=%F
"}}}
"ideaVim ignore
" ideavim can't parse function and emojis (and plugins?)
" functions {{{
" other functions {{{
function! DeleteMarksOnCurrentLine()
let l:m = join(filter(
\ map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)'),
\ 'line("''".v:val) == line(".")'))
if !empty(l:m)
exe 'delmarks' l:m
" to remove the gutter bookmark icon displayed by
" vim-signature plugin
SignatureRefresh
endif
endfunction
" mapped to m- in keymap section
" }}}
" function to call when pasting from Algorithm course's PDF slides.
function! A()
" delete the weird dot symbol for dotted lines.
%s/\v[\n・]{2,}/
" put each sentence ending with . period in a new line
s/\v([^.\d]\. )/\1
/g
" turn each line into numbered list
g/\v^[^ 1]/norm I1.
" insert empty lines
g!/\v(^\s*$)|(\n\s*\n)/norm o
endfunction
" this stuff is for method declarations / errors thrown copied from Oracle docs to Notion to Vim
function! Oracle()
" if the first line (method declaration) doesn't end with ), then join from first line to the next line that does end with ) - this happens when the method has multiple parameters.
/\%1l\v[^)]$/,/\v\)$/j
" proper in-line code with embeded links:
%s/\v`\[(.{-})\]\((.{-})\)`/[`\1`](\2)/g
" change notion's code fences to in-line code.
%s/\v\n\n```\n/ `
%s/\v\n```\n\n/`
" inserts empty lines before each bold words. (Paramteters,Returns,Throws), then make it a numbered list
%s/\v([^:])\*\*/\1
1. **/g
" find all lines that aren't numbered or indented, them number it.
g/\v^[^ 1]/norm I1.
" the See Also section:
%s/\v • //g
" put each throw into a new line
g/\v\*\*Throws:/s/\v(\S)(\[`.{-}`\]\(https:.{-}\))/\1
1. \2/g
"" put the text following the bold words into new indented lines, and make it a numbered list
%s/\v:\*\*/:\*\*
1. /g
"" delete all lines that's only numbered but has no content.
g/\v^\s?1\. $/d
endfunction
" the function to call if editing notes pasted from Mooc.fi
function! Mooc()
" convert mooc.fi's in-line code to code fence
" the back-slash is unnecessary within the [\/*] bracket, but without it the syntax highlighting would be thrown off, so
:g/\v^`(\/[\/*]|.+[{;]$)/norm :s/`/
O```c#
:g/\v(^}`$|;`$)/norm :s/`/
o```
" when pasted in from notion: change java fences to c# fences to avoid the unpredictable markdown anchor disabling code highlight.
:g/\v^\s*```java$/s/java/c#
" match and select whole code block, then sub out all new line characters
" `\S` in the first pattern can't be changed to `c#`: cases where notion's java block is pasted in
:g/\v^\s*```\S\_.{-}```/,/\v^\s*```$/s/\n/NEWLINE
" insert lines after, exclude (empty or white-space only lines), or those that already have a (empty or white-space only line) below.
:g!/\v(^\s*$)|(\n\s*\n)/norm ox
" sub the 1-line code fences back to what they should be
:g/\v^\s*```(\s|\S)+```/s/NEWLINE/
/g
" remove the last newline after the end of each code fence: with the join `:j` command
:g/\v^\s*```$/j
endfunction
"ideaVim ignore end