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
|
" Basic settings.
set nocompatible
set number
" showmode too often puts the cursor on the bottom line, this can make
" kitty's cursor_trail way too jumpy.
set noshowmode
"set signcolumn=yes
set updatetime=250
set scrolloff=5
"set lazyredraw
" Don't ask to save changes when switching buffers.
set hidden
" Use the last buffer instead of the right-most when opening from quickfix.
set switchbuf=uselast
" Show match count.
set shortmess-=S
" Old split defaults (I think).
set splitright
set splitbelow
" Stop buffers from jumping when opening buffer selection.
set splitkeep=screen
set termguicolors
colo lil_pablo
" Syntax and indent from filetype.
filetype plugin indent on
syntax on
" Search farther and longer to correctly highlight.
"au BufEnter * :syntax sync minlines=10
set redrawtime=3000
set maxmempattern=5000
" Highlight unwanted whitespace.
au BufEnter * match Error /\s\+$/
au InsertEnter * match Error /\s\+\%#\@<!$/
au InsertLeave * match Error /\s\+$/
" Check for SHIFT_JIS.
set fileencodings=ucs-bom,utf-8,sjis,default,latin1
" 4 spaces autoindent.
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
" C syntax preference.
let g:c_syntax_for_h=1
let g:c_no_curly_error=1
let g:c_function_pointers=1
set cinoptions=:0,=4,l1,g2,h2,(4,u4,+4,m1,j1,J1
set cindent
" Set different format for mail and text files.
set nowrap nolinebreak nolist formatoptions=l textwidth=0
au FileType mail,text setlocal wrap formatoptions=l textwidth=0
" Ex tab complete that makes sense to me.
set wildmode=longest,list,full
set wildmenu
" Set titlebar.
set title
au BufEnter * let &titlestring=expand("%:t")
" https://github.com/csdvrx/CuteVim/blob/main/.vimrc
" Allow distinguishing <C-i> from <Tab> in bindings.
" If using vim rather than neovim, this will disable the ability
" to map <C-h/j/k/l>. Apparently due to vim's lack of "CSI u"
" support, according to some issue reports.
" https://github.com/vim/vim/issues/10244
"let &t_TI = "\<Esc>[>4;2m"
"let &t_TE = "\<Esc>[>4;m"
" Treat shift + backspace as normal backspace.
"noremap <S-BS> <BS>
" System clipboard on linux.
set clipboard=unnamedplus
" Session options.
set ssop=curdir,skiprtp,blank,buffers,folds,winsize,terminal
set vop-=curdir
" Move ~/.viminfo.
set viminfo+=n~/.vim/viminfo
" Session auto save.
" https://vim.fandom.com/wiki/Go_away_and_come_back
function! SaveSession()
if v:this_session != ""
echo "Saving."
exe "mksession! " . v:this_session
else
echo "No Session."
endif
endfunction
au VimLeave * :call SaveSession()
if isdirectory(expand("~/c"))
" Swap file directory.
let swap_dir = expand("~/c/sessions/swaps//")
if !isdirectory(swap_dir)
call mkdir(swap_dir, "p", 0755)
endif
let &directory=swap_dir
if has("persistent_undo")
let undo_dir = expand("~/c/sessions/undo//")
if !isdirectory(undo_dir)
call mkdir(undo_dir, "p", 0755)
endif
let &undodir=undo_dir
set undofile
endif
" Staggered backups.
let backup_dir = "/mnt/store/backup/vim"
if !isdirectory(backup_dir)
let backup_dir = expand("~/c/sessions/backup//")
if !isdirectory(backup_dir)
call mkdir(backup_dir, "p", 0755)
endif
endif
let &backupdir=backup_dir
set backup
endif
set autocomplete
"set complete=.^4,w^3,b^2,u^2,i^2,d^2
set complete=.^4,w^3,b^2,u^2
set completeopt+=menu,popup
" Plugins.
let g:fugitive_no_maps = 1
set diffopt+=vertical
packadd vim-fugitive
packadd vim-gitbranch
packadd vim-asciidoc-folding
packadd Colorizer
"if !empty($NIX_SHELL)
"packadd lsp
"call LspAddServer([#{
"\ name: 'clangd',
"\ filetype: ['c', 'cpp'],
"\ path: 'clangd',
"\ args: ['--background-index']
"\}])
"endif
" Custom statusline.
function! StatuslineGit()
let l:branchname = gitbranch#name()
return strlen(l:branchname) > 0 ? " ".l:branchname." " : " "
endfunction
function! Statusline() abort
let focused = g:statusline_winid == win_getid(winnr())
let status = focused ? "%#StatusLine#" : "%#StatusLineNC#"
let status .= "%{StatuslineGit()}"
let status .= " %{expand('%:~:.')}" " Explicitly expand to relative file, %f was flaky.
let status .= " vim@%{hostname()}"
let status .= "%="
let status .= " %y"
let status .= " %{&fileencoding}"
let status .= "[%{&fileformat}]"
let status .= "%3p%%"
let status .= " %3l:%-3c"
return status
endfunction
set laststatus=2 " Always show statusline.
set statusline=%!Statusline()
" Make shift + nav keys no-ops.
nnoremap <S-h> <nop>
nnoremap <S-j> <nop>
nnoremap <S-k> <nop>
nnoremap <S-l> <nop>
" Normal mode tab no-op.
nmap <Tab> <nop>
" ctrl + c no-op.
nnoremap <C-c> <nop>
" shift + x delete no yank.
vnoremap X "_x
" Disable F1 for help.
nmap <F1> <nop>
" Disable q: for histroy.
nmap q: <nop>
" Simplify split movement.
nnoremap <silent> <C-h> :wincmd h<CR>
nnoremap <silent> <C-j> :wincmd j<CR>
nnoremap <silent> <C-k> :wincmd k<CR>
nnoremap <silent> <C-l> :wincmd l<CR>
" Make ctrl + "." and "," map to previous buffer.
nmap <C-,> <C-^>
nmap <C-.> <C-^>
" Personally intuitive pop-up menu binds.
inoremap <expr> <CR> pumvisible() ? "<C-y><CR>" : "<CR>"
inoremap <expr> <Up> pumvisible() ? "<C-p>" : "<Up>"
inoremap <expr> <Down> pumvisible() ? "<C-n>" : "<Down>"
" Ctags
nnoremap <C-d> <C-]>
" Toggle colorcolumn.
nmap <silent> C :exe "set colorcolumn=" . (&colorcolumn == "" ? "101" : "")<CR>
" Toggle css color highlighting.
noremap <silent> # :ColorToggle<CR>
" Buffer select.
nmap <silent> \ :call QNameInit(1)<CR>:~
" Git summary.
nmap <silent> Y :vertical G<CR>
" Relative :e, :vs, and :s.
fun OpenBasedOnRelativeArgument(A, CMD)
" https://stackoverflow.com/a/14348204
let arg = a:A
if arg != ""
let arg = (arg[0] == "/" ? arg : resolve(fnamemodify(expand("%:h")."/".arg, ":p")))
endif
if a:CMD == "EDIT"
exe "edit" arg
elseif a:CMD == "VERTICAL_SPLIT"
exe "vsplit" arg
elseif a:CMD == "SPLIT"
exe "split" arg
endif
endfun
command -nargs=* -complete=customlist,RelativeFileComplete E :call OpenBasedOnRelativeArgument("<args>", "EDIT")
command -nargs=* -complete=customlist,RelativeFileComplete VS :call OpenBasedOnRelativeArgument("<args>", "VERTICAL_SPLIT")
command -nargs=* -complete=customlist,RelativeFileComplete S :call OpenBasedOnRelativeArgument("<args>", "SPLIT")
fun RelativeFileComplete(A,L,P)
let argpath = fnamemodify(a:A, ":h")
if argpath[0] == "~" || argpath[0] == "/"
let curpath = ""
else
let curpath = expand("%:h")."/"
endif
let argfile = fnamemodify(a:A, ":t")
let files = globpath(curpath.argpath, argfile."*", 0, 1)
for i in range(0, len(files) - 1)
if isdirectory(files[i])
let files[i] = files[i]."/"
endif
if len(curpath) > 0
let files[i] = substitute(files[i], curpath, "", "")
let files[i] = substitute(files[i], "^./", "", "")
endif
endfor
return files
endfun
" https://stackoverflow.com/a/20564623
cnoreabbrev <expr> e getcmdtype() == ":" && getcmdline() == "e" ? "E" : "e"
cnoreabbrev <expr> vs getcmdtype() == ":" && getcmdline() == "vs" ? "VS" : "vs"
cnoreabbrev <expr> s getcmdtype() == ":" && getcmdline() == "s" ? "S" : "s"
" :no -> :nohlsearch instead of :noremap.
cnoreabbrev <expr> no getcmdtype() == ":" && getcmdline() == "no" ? "nohlsearch" : "no"
call Juliana#Init() " Custom insert mode tab behavior inherited from Emacs.
inoremap <silent> <Tab> <C-R>=Juliana#CompleteTab("START")<CR>
\<C-R>=Juliana#CompleteTab("TAB")<CR>
\<C-R>=Juliana#CompleteTab("ALIGN")<CR>
\<C-R>=Juliana#CompleteTab("NEXT")<CR>
inoremap <silent> <S-Tab> <C-R>=Juliana#CompleteSTab("PREV")<CR>
nnoremap <silent> <expr> <Tab> Juliana#CompleteNTab("FOLD")
command Tabify set noexpandtab | %retab! | set expandtab
command Untabify set expandtab | %retab!
" @TODO: noeol, nofixeol, binary
command Hex :%!xxd
command Unhex :%!xxd -r
" https://stackoverflow.com/a/27721306
"command -nargs=+ Ggr execute 'Ggrep! -q' <q-args>
command -nargs=+ Ggr execute "silent Ggrep!" <q-args> | botright cwindow | redraw!
" I had this mapped to <C-i> for the longest time. Sadly with OG vim
" (not neovim) the fix for mapping <Tab> and <C-i> seperately doesn't work.
" Changing this bind as the only concession to be compatible with vim
" seems well worth it.
nnoremap <C-o> :Ggr
"" https://stackoverflow.com/a/37040415
function! SyntaxGroup()
let l:s = synID(line("."), col("."), 1)
echo synIDattr(l:s, "name") . " -> " . synIDattr(synIDtrans(l:s), "name")
endfun
command Syn :call SyntaxGroup()
" https://vi.stackexchange.com/a/456
function! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
command Trim :call TrimWhitespace()
|