ftp -o - https://jcs.org/move_in | sh -
1" vim:ts=8
2"
3" vim 8 config
4" joshua stein <jcs@jcs.org>
5"
6
7" defaults for everything
8set backspace=indent,eol,start
9let c_minlines=500
10set encoding=utf-8
11" TODO: check for utf-8 term or this gives a warning
12set fillchars+=vert:│
13set hidden
14set ignorecase
15set incsearch
16set laststatus=2
17set modelines=5
18set nocompatible
19set nofoldenable
20set nohlsearch
21set nostartofline
22set ruler
23set scrolloff=10
24set shiftwidth=4
25set showcmd
26set showmatch
27set showmode
28set smartcase
29set smarttab
30set spellcapcheck=
31set spellfile=~/.vimspell.add
32set spelllang=en_us
33set tabstop=4
34set timeoutlen=0
35set wildmode=longest,list,full
36
37" required for vundle
38filetype off
39
40" don't pollute directories with swap files, keep them in one place
41silent !mkdir -p ~/.vim/{backup,swp}/
42set backupdir=~/.vim/backup//
43set directory=~/.vim/swp//
44" except crontab, which will complain that it can't see any changes
45au FileType crontab setlocal bkc=yes
46
47" minor color config
48set t_Co=256
49syntax on
50colorscheme jcs
51
52" highlight stray spaces and tabs when out of insert mode
53au BufWinEnter * match ExtraWhitespace /\(\s\+$\|\^\s* \+\)/
54au InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
55au InsertLeave * match ExtraWhitespace /\(\s\+$\|\^\s* \+\)/
56" performance hack
57if version >= 702
58 au BufWinLeave * call clearmatches()
59endif
60
61" try to detect xterm pasting to automatically disable autoindent and such
62if &term =~ "xterm.*"
63 let &t_ti = &t_ti . "\e[?2004h"
64 let &t_te = "\e[?2004l" . &t_te
65
66 function XTermPasteBegin(ret)
67 set pastetoggle=<Esc>[201~
68 set paste
69 return a:ret
70 endfunction
71
72 map <expr> <Esc>[200~ XTermPasteBegin("i")
73 imap <expr> <Esc>[200~ XTermPasteBegin("")
74 cmap <Esc>[200~ <nop>
75 cmap <Esc>[201~ <nop>
76endif
77
78" when writing new files, mkdir -p their paths
79augroup BWCCreateDir
80 au!
81 au BufWritePre * if expand("<afile>")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand('%:h'), 1) | redraw! | endif
82augroup END
83
84" init vim-plug (run "vim +PlugInstall +qall" after modifying)
85" these require apostrophes instead of quotes
86call plug#begin()
87Plug 'VundleVim/Vundle.vim'
88Plug 'ap/vim-buftabline'
89Plug 'ludovicchabant/vim-gutentags'
90Plug 'cespare/vim-sbd'
91Plug 'scrooloose/nerdtree'
92Plug 'wsdjeg/vim-fetch'
93Plug 'markonm/traces.vim'
94Plug 'tpope/vim-commentary'
95call plug#end()
96
97" disable plugin auto-indenting
98filetype indent off
99filetype plugin indent off
100
101" make buffer windows easier to navigate
102map <C-h> <C-w>h
103map <C-j> <C-w>j
104map <C-k> <C-w>k
105map <C-l> <C-w>l
106" control+n and +p for next and previous buffers, but only in normal mode
107nmap <C-n> :bn<CR>
108nmap <C-p> :bp<CR>
109" sbd plugin
110nmap <C-x> :Sbd<CR>
111" control+/
112noremap <C-_> :Commentary<CR>
113
114" prevent those from running the nerdtree
115autocmd FileType nerdtree noremap <buffer> <C-h> <nop>
116autocmd FileType nerdtree noremap <buffer> <C-j> <nop>
117autocmd FileType nerdtree noremap <buffer> <C-k> <nop>
118autocmd FileType nerdtree noremap <buffer> <C-l> <nop>
119autocmd FileType nerdtree noremap <buffer> <C-n> <nop>
120autocmd FileType nerdtree noremap <buffer> <C-p> <nop>
121
122" just highlight the line with the error, i don't need a column
123set signcolumn=no
124" disable previews of completions
125set completeopt-=preview
126
127" make < and > shifts retain selection
128vnoremap < <gv
129vnoremap > >gv
130
131" disable annoying behavior where starting an auto-indented line with a hash
132" makes it unindent and refuse to >>
133:inoremap # X#
134
135" per-file-type settings
136" tell vim what kinds of files these are based on extension
137au BufNewFile,BufRead *.phtml setlocal ft=php
138au BufNewFile,BufRead *.rake,*.mab setlocal ft=ruby
139au BufNewFile,BufRead *.erb setlocal ft=eruby
140au BufNewFile,BufRead *.pjs setlocal ft=php.javascript
141au BufRead,BufNewFile *.go setlocal ft=go
142au BufNewFile,BufRead *.dsl setlocal ft=
143
144" default to no color column
145au FileType * setlocal colorcolumn=0
146
147" all source code gets wrapped at <80 and auto-indented
148au FileType arduino,asm,c,cpp,go,java,javascript,php,html,make,objc,perl setlocal tw=79 autoindent colorcolumn=81
149
150" recognize crystal
151au BufNewFile,BufReadPost *.cr setlocal filetype=crystal
152au BufNewFile,BufReadPost *.ecr setlocal filetype=ecrystal
153au FileType crystal,ecrystal setlocal ts=2 sw=2 tw=79 et sts=2 autoindent colorcolumn=81
154
155" ruby and lua have soft tabs
156au FileType ruby,eruby,lua setlocal ts=2 sw=2 tw=79 et sts=2 autoindent colorcolumn=81
157au FileType ruby setlocal commentstring=#\ %s
158au FileType yaml setlocal ts=2 sw=2 et colorcolumn=81
159
160" makefiles and c have tabstops at 8 for portability
161au FileType arduino,asm,make,c,cpp setlocal ts=8 sw=8
162au FileType c setlocal commentstring=//\ %s
163
164" email and commit messages - expand tabs, wrap at 68 for future quoting, enable spelling
165au FileType cvs,gitcommit,mail setlocal tw=68 et spell colorcolumn=69
166
167" markdown files get hard tabs, wrapped at 79 and spell checking
168au FileType markdown setlocal tw=79 spell colorcolumn=81
169
170" and make sure cvs adds a blank line for me to start typing
171" (openbsd's cvs does this by default)
172au FileType cvs s/^CVS:/
173CVS:/|1
174
175" and for email, work properly with format=flowed
176au FileType mail setlocal formatoptions+=wq
177
178" website stuff
179au BufNewFile,BufRead *_posts/*.md setlocal tw=80 spell
180
181" z80 assembler syntax file is outdated
182au Syntax z8a syn match z8aPreProc "\.equ"
183au Syntax z8a syn match z8aPreProc "\.gblequ"
184au Syntax z8a syn match z8aPreProc "\.lclequ"
185
186augroup Binary
187 au!
188 au BufReadPre *.bin,*.pkt let &bin=1
189 au BufReadPost *.bin,*.pkt if &bin | %!xxd
190 au BufReadPost *.bin,*.pkt set ft=xxd | endif
191 au BufWritePre *.bin,*.pkt if &bin | %!xxd -r
192 au BufWritePre *.bin,*.pkt endif
193 au BufWritePost *.bin,*.pkt if &bin | %!xxd
194 au BufWritePost *.bin,*.pkt set nomod | endif
195augroup END
196
197" package configuration
198
199" gutentags
200let g:gutentags_cache_dir="~/.vim/gutentags"
201" use ectags
202if filereadable("/usr/local/bin/ectags")
203 let g:gutentags_ctags_executable="/usr/local/bin/ectags"
204elseif filereadable("/opt/homebrew/bin/ctags")
205 let g:gutentags_ctags_executable="/opt/homebrew/bin/ctags"
206endif
207let g:gutentags_ctags_executable_go="~/go/bin/gotags"
208let g:gutentags_project_root=[ "CVS", ".git", ".gutentags_stop" ]
209" i'll manually invoke :GutentagsUpdate when i need to
210let g:gutentags_generate_on_missing=0
211let g:gutentags_generate_on_new=0
212let g:gutentags_generate_on_write=0
213
214" only enable buftabline on multiple buffers
215let g:buftabline_show=1
216
217" nerdtree
218let g:NERDTreeDirArrowExpandable="+" " use normal ascii
219let g:NERDTreeDirArrowCollapsible="~"
220let NERDTreeMinimalUI=1
221" leave 80 chars for editing
222let NERDTreeWinSize=str2nr(system('expr $COLUMNS - 81'))
223let NERDTreeMapOpenRecursively="+"
224let NERDTreeMapCloseChildren="-" " easier to remember
225let NERDTreeIgnore = ['\.(o|pyc)$']
226
227" macros
228
229" control+d - delete the current line and all remaining text of an email up to
230" the line of my signature (or the rest of the file) - useful for deleting lots
231" of useless quoted text
232function KillToSig()
233 let curline = line(".")
234 if search("^-- ") > 0
235 exec curline
236 normal! ^d/^-- /
237O
238 exec curline
239 else
240 normal! dGo
241 endif
242endfunction
243map <Esc>:let curline=line(".")<CR>:exec KillToSig()<CR>:exec curline<CR>
244
245" a quick function to toggle color column on or off
246let s:cc = ""
247function ToggleColorColumn()
248 if &colorcolumn
249 let s:cc=&colorcolumn
250 set colorcolumn=0
251 echo s:cc
252 else
253 exec "set colorcolumn=" . s:cc
254 end
255endfunction
256command! ToggleColorColumn :call ToggleColorColumn()
257
258" i hold shift a lot, make :W work like :w and :Q like :q
259cabbr W w
260cabbr Q q
261cabbr E e
262
263" w! still failed? try w!! to write as root
264cmap w!! w !doas tee >/dev/null %
265
266" f will show the current function name
267fun! ShowFuncName()
268 let lnum = line(".")
269 let col = col(".")
270 echohl ModeMsg
271 echo getline(search("^[^ \t#/]\\{2}.*[^:]\s*$", 'bW'))
272 echohl None
273 call search("\\%" . lnum . "l" . "\\%" . col . "c")
274endfun
275map f :call ShowFuncName() <CR>
276
277
278" me fail english? that's unpossible!
279abbr seperate separate
280abbr furnature furniture
281abbr rediculous ridiculous
282abbr definetly definitely
283abbr shold should
284abbr appologize apologize
285abbr propogate propagate
286abbr eachother each other
287abbr occured occurred
288
289
290" when starting up, restore cursor position from viminfo
291au BufReadPost *
292 \ if line("'\"") >= 1 && line("'\"") <= line("$") |
293 \ exe "normal! g`\"" |
294 \ endif
295
296" but git re-uses the same filename all the time, so ignore viminfo
297au BufNewFile,BufRead *.git/* call setpos('.', [0, 1, 1, 0])