-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
301 lines (247 loc) · 6.02 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
"""blinking cursor fix:
"""autocmd VimEnter * silent !printf '\033[?12l'
filetype plugin on
let g:omni_sql_no_default_maps = 1
let g:csv_mode="off"
function CSV()
if g:csv_mode ==? "off"
set filetype="csv"
set syntax="csv"
runtime ftplugin/csv.vim
runtime csv-syntax.vim
%ArrangeColumn
let g:csv_mode="on"
else
%UnArrangeCol
let g:csv_mode="off"
set syntax=""
endif
endfunction
command CSV call CSV()
command Csv call CSV()
function LoadTemp()
LoadFileTemplate default
:normal! Gddgg
endfunction
autocmd! BufNewFile * call LoadTemp()
set hidden
set ofu=syntaxcomplete#Complete
set backspace=2
set uc=0 """no swapfile
set ic
set history=9000
set nocompatible
set nowrap
syntax on
set number
colorscheme solarized
set background=dark
hi Normal ctermfg=green ctermbg=none
hi LineNr ctermfg=blue ctermbg=darkgray
"""detect filetypes"""
au BufRead * call s:isHaskellScript()
function s:isHaskellScript()
if match(getline(1), '\v#!.*run(ghc|haskell)') >= 0
set filetype=haskell
endif
endfunction
" override default ftplugin for python
au BufRead,BufNewFile *.py set shiftwidth=2 tabstop=2 softtabstop=2
""""""
hi TrailingWhitespace ctermbg=red guibg=red
autocmd CursorMoved * match TrailingWhitespace /\%(\s\+\&\s*\%#\@!\)$/
autocmd CursorMovedI * match TrailingWhitespace /\%(\s\+\&\s*\%#\@!\)$/
set mouse=nicr
set hlsearch
set expandtab
set autoindent
set smarttab
set tabstop=2
set softtabstop=2
set shiftwidth=2
set list
set listchars=tab:››
let g:GPGUseAgent=0
"""keep cursor vertically centered while searching"""
nnoremap n nzz
nnoremap N Nzz
nnoremap * *zz
nnoremap # #zz
nnoremap g* g*zz
nnoremap g# g#zz
""""""
"""word wrap"""
map <C-w><C-w> :s/\v(.{70}[^ ]* *)/\1\r/g<CR>
map <C-w><C-h> :s/\v(.{70}[^ ]* *)/\1\r--/g<CR>
""""""
"""command repeat"""
nmap , @:
""""""
"""Quit"""
nmap <C-X><C-C> :qa!<CR>
imap <C-X><C-C> <Esc>:qa!<CR>
nmap <C-C> :q<CR>
imap <C-C> <Esc>:q<CR>
""""""
"""Next/Prev File"""
nmap <C-N> :n<CR>
imap <C-N> <Esc>:n<CR>
nmap <C-P> :N<CR>
imap <C-P> <Esc>:N<CR>
""""""
"""delete/paste"""
imap <C-D> <Esc>ddli
imap <C-P> <Esc>pli
xmap p "_dp
xmap P "_dP
""""""
"""Undo"""
nmap <C-U> u
imap <C-U> <Esc>uli
nmap <C-R> <C-R>
imap <C-R> <Esc><C-R>li
""""""
"""word wrap"""
map <C-w><C-w> :s/\v(.{80}[^ ]*)/\1\r/g<CR>
map <C-w><C-h> :s/\v(.{80}[^ ]*)/\1\r--/g<CR>
""""""
"""Write"""
nmap <F3> :w<CR>
imap <F3> <Esc>:w<CR>li
vmap <F3> :w<Del><CR>lv
""""""
"""meld"""
nmap <F2> :Exec cd %:p:h; meld %:p >/dev/null 2>/dev/null &<CR>
imap <F2> <Esc>:Exec cd %:p:h; meld %:p >/dev/null 2>/dev/null &<CR>
""""""
"""git"""
nmap <F4> :Exec cd %:p:h; term lazygit >/dev/null 2>/dev/null &<CR>
imap <F4> <Esc>:Exec cd %:p:h; term lazygit >/dev/null 2>/dev/null &<CR>
""""""
"""Run"""
nmap <F5> :1wincmd<space>w<CR>:w<CR>:Run<CR>
imap <F5> <ESC>:1wincmd<space>w<CR>:w<CR>:Run<CR>li
nmap <F6> :w<CR>:Run<Space>
imap <F6> <Esc>:w<CR>:Run<Space>li
""""""
"""Clipboard"""
nmap <F7> "+y
vmap <F7> "+y
nmap <F8> "+p
imap <F8> <ESC>"+pi
vmap <F8> "+p
""""""
"""Register l"""
nmap <F9> "ly
imap <F9> <ESC>"lyi
vmap <F9> "ly
nmap <F10> "lp
imap <F10> <ESC>"lpi
vmap <F10> "lp
""""""
"""Register r"""
nmap <F11> "ry
imap <F11> <ESC>"ryi
vmap <F11> "ry
nmap <F12> "rp
imap <F12> <ESC>"rpi
vmap <F12> "rp
""""""
nnoremap <C-S> :set spell!<CR>
inoremap <C-S> <ESC>:set spell!<CR>li
nnoremap <C-M> :call ToggleRelativeNumber()<CR>
command! -bar -range=% Reverse <line1>,<line2>g/^/m<line1>-1|nohl
" Disable readonly in vimdiff
if &diff
set noro
endif
""":Exec cmd arg arg ..
" run external commands quietly
command -nargs=1 Exec
\ execute 'silent ! ' . <q-args>
\ | execute 'redraw! '
""":Wc msg => save, git ci FILENAME -m msg
""":Wcq msg => save, git ci FILENAME -m msg, quit
command -nargs=1 Wc call Wc(<f-args>, "noquit")
command -nargs=1 Wcq call Wc(<f-args>, "quit")
cabbrev wc <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Wc' : 'wc' )<CR>
cabbrev wcq <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Wcq' : 'wcq')<CR>
function Wc(msg, maybeQuit)
w
let msg = "'" . substitute(a:msg, "'", "'\\\\''", "g") . "'"
let cmd = "! git ci % -m " . msg
execute cmd
if a:maybeQuit == "quit"
q
endif
endfunction
let s:RunHeight = 12
command -nargs=* Run call Run(<f-args>)
function Run(...)
1wincmd w
let interpreter = strpart(getline(1),2)
let abspath = expand("%:p")
let arguments = join(a:000, " ")
let call = interpreter . ' "' . abspath . '" ' . arguments
if winnr("$") == 1
below new
endif
2wincmd w
execute "resize " . s:RunHeight
let perlexp = 'print q(RunVimRun)x64 . <> . qq(\n);'
execute "%! eval \"(".call." | perl -0777 -e '".perlexp."')2>&1\""
let lines = getbufline(bufnr("%"),1,"$")
%s/\v\_.*(RunVimRun){64}//
if winnr("$") == 2
below vnew
endif
3wincmd w
let i = 1
for l in lines
call setline(i, l)
let i += 1
endfor
%s/\v(RunVimRun){64}\_.*//
1wincmd w
endfunction
command -nargs=* RunHeight call RunHeight(<f-args>)
function RunHeight(height, ...)
let s:RunHeight = a:height
call Run(a:000)
endfunction
function ToggleRelativeNumber()
if &relativenumber
set norelativenumber
set number
else
set nonumber
set relativenumber
endif
endfunction
command -nargs=* BandCampToMusicBrainz call BandCampToMusicBrainz(<f-args>)
function BandCampToMusicBrainz()
%s/\v^\s+\n//
%s/\v(\d+)\.\n/\1 /
%s/\v\s+$//
endfunction
function Inc(...)
let result = g:i
let g:i += a:0 > 0 ? a:1 : 1
return result
endfunction
command -range -nargs=* Num call Num(<line1>, <line2>, <f-args>)
cabbrev num <c-r>=(getcmdtype()==':' && getcmdpos()==1 ? 'Num' : 'num' )<CR>
function Num(...)
let startLine=a:1
let endLine=a:2
let numStart=a:0 > 2 ? a:3 : 1
if startLine == 1 && endLine == 1
let range = "%"
else
let range = startLine . "," . endLine
endif
let g:i = numStart
let fmt = "\\=printf('%04d', Inc())"
let cmd = range . "s/^/" . fmt . "/"
execute cmd
endfunction