scripts/vim/vimrc

540 lines
12 KiB
VimL
Raw Normal View History

2019-04-27 06:33:34 -07:00
" Settings -------------------------------------------------------------------|
2019-04-30 21:57:45 -07:00
" general settings (use :help for these)
set confirm
set wildmenu
set autochdir
set laststatus=2
" visuals
2019-07-27 11:35:51 -07:00
set statusline=%{StatuslinePrelude()}
set statusline+=%{ModePrint()}
set statusline+=\ %r
set statusline+=\ %{&filetype}
set statusline+=\ %f
set statusline+=%=
set statusline+=\ %m
2019-04-30 21:57:45 -07:00
set statusline+=\ %{FileSize()}
2019-07-27 11:35:51 -07:00
set statusline+=\ ↑%4l→%-3c
set statusline+=\ ↓%5L
2019-04-30 21:57:45 -07:00
set statusline+=\ %3p%%
set ruler
set showcmd
2019-07-09 13:32:05 -07:00
set noshowmode
2019-04-30 21:57:45 -07:00
2019-07-27 11:35:51 -07:00
set numberwidth=2
set relativenumber
2019-04-30 21:57:45 -07:00
2019-07-27 11:35:51 -07:00
set colorcolumn=80
2019-04-30 21:57:45 -07:00
set conceallevel=1
set belloff=all
2019-07-07 12:50:38 -07:00
set list
set listchars=tab:»—,eol,space,trail:∴,extends:>,precedes:<
2019-04-30 21:57:45 -07:00
" general movement and ergonomics
set linebreak
set showbreak=
set virtualedit=onemore
set backspace=indent,eol,start
set textwidth=80
set comments=s0:/*!
set comments+=mb:*
set comments+=ex:*/
set comments+=s1:/*
set comments+=mb:*
set comments+=ex:*/
set comments+=:///
set comments+=://!
set comments+=://
set comments+=b:#
set comments+=b:%
2019-04-30 21:57:45 -07:00
set formatoptions=tcrqnolj
set nojoinspaces
let mapleader="\<Tab>"
2019-04-27 06:33:34 -07:00
2019-04-30 21:57:45 -07:00
" snappier responses
set ttimeoutlen=0
set lazyredraw
" searching options (highlight, smart casing)
set showmatch
set hlsearch
set smartcase
set ignorecase
set incsearch
2019-07-07 12:50:28 -07:00
" tabulation (3 space hard tabs, auto-indent when my muscle memory demands it)
2019-04-30 21:57:45 -07:00
set autoindent
set smarttab
2019-07-07 12:50:28 -07:00
set noexpandtab
set copyindent
set preserveindent
set softtabstop=0
2019-04-30 21:57:45 -07:00
set shiftwidth=3
2019-07-05 19:09:01 -07:00
set tabstop=3
2019-04-30 21:57:45 -07:00
" limits, what/when/how to save and encodings
set undolevels=10000
set tabpagemax=1000
set viminfo='100,/50,<50,s10,h,%
2019-06-10 19:16:50 -07:00
set viminfo+=n~/.vim/viminfo
2019-04-30 21:57:45 -07:00
set encoding=utf-8
set fileencodings=ucs_bom,utf_8,sjis
set fileformats=unix,dos,mac
set hidden
set updatetime=500
2019-04-27 06:33:34 -07:00
" bufexplorer
let g:bufExplorerDisableDefaultKeyMapping=1
2019-04-30 21:57:45 -07:00
" gutentags
2019-04-27 06:33:34 -07:00
let g:gutentags_project_root=['.git', 'Makefile']
" TwitVim
let twitvim_browser_cmd='palemoon'
" vim-markdown
let g:vim_markdown_folding_disabled=1
" rainbow
let g:rainbow_active=0
" netrw
let g:netrw_banner=0
let g:netrw_liststyle=3
let g:netrw_browse_split=4
let g:netrw_altv=1
let g:netrw_winsize=20
" buftabline
2019-07-09 13:32:05 -07:00
let g:buftabline_show=2
2019-04-27 06:33:34 -07:00
let g:buftabline_numbers=2
2019-07-09 13:32:05 -07:00
let g:buftabline_indicators=1
let g:buftabline_separators=0
let g:buftabline_plug_max=19
2019-04-27 06:33:34 -07:00
" TagBar
let g:tagbar_vertical=7
let g:tagbar_compact=1
let g:tagbar_show_linenumbers=1
let g:tagbar_iconchars=['»', '▼']
let g:tagbar_autoshowtag=1
" abolish
let g:abolish_no_mappings=1 " we set out own later
2019-05-01 08:46:58 -07:00
" zig.vim
let g:zig_fmt_autosave=0
" polyglot
let g:polyglot_disabled=['c++11']
2019-04-30 21:57:45 -07:00
" gui and terminal specific settings
if has('gui_running')
2019-07-05 19:09:01 -07:00
set guicursor+=i:hor10-Cursor
set guicursor+=a:blinkon0
set guioptions=agit
2019-07-09 13:32:05 -07:00
set guitablabel=%N.%t
2019-04-27 06:33:34 -07:00
set lines=24
2019-07-27 11:35:51 -07:00
set columns=83
2019-05-07 20:01:14 -07:00
else
" use high-color terminal capabilities
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
2019-07-05 19:09:01 -07:00
let base16colorspace=256
set termguicolors
endif
2019-04-30 21:57:45 -07:00
2019-07-04 00:45:26 -07:00
" GUI-specific settings
2019-04-27 06:33:34 -07:00
if has('gui_running')
2019-07-05 19:09:01 -07:00
if has('gui_win32')
set guifont=PxPlus_IBM_EGA8:h12:cDEFAULT:qDRAFT
elseif has('gui_gtk')
set guifont=IBM\ Plex\ Mono\ weight=453\ 10
set linespace=-2
elseif has('gui_macvim')
set guifont=IBMPlexMono-Text:h14
set linespace=-3
set blurradius=20
set macligatures
set macmeta
set transparency=10
endif
endif
2019-04-27 06:33:34 -07:00
2019-07-04 00:45:26 -07:00
" OS-specific settings
2019-04-27 06:33:34 -07:00
if has('win32')
2019-07-05 19:09:01 -07:00
" windows sucks
let $PATH='G:\msys64\usr\bin;'.$PATH
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
set shellslash
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
" netrw
let key='G:/msys64/home/marrub/.ssh/id_rsa'
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
let g:netrw_cygwin=0
let g:netrw_ignorenetrc=1
let g:netrw_list_cmd="ssh -i " . key . " USEPORT HOSTNAME ls -Fa "
let g:netrw_ssh_cmd="ssh -i " . key
let g:netrw_scp_cmd="scp -q -i " . key
let g:netrw_sftp_cmd="sftp -i " . key
let g:netrw_silent=1
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
" gutentags
let g:gutentags_cache_dir=$VIM.'/vimtags/'
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
" swap files
set directory=$VIM/vimtemp//
2019-05-07 20:01:14 -07:00
else
2019-07-05 19:09:01 -07:00
if has('mac')
set rubydll=/usr/local/opt/ruby/lib/libruby.dylib
endif
2019-07-04 00:45:45 -07:00
2019-07-05 19:09:01 -07:00
" gutentags
let g:gutentags_cache_dir=$HOME.'/.vim/tags/'
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
" searching
set grepprg=rg\ --vimgrep\ -n
2019-04-30 21:57:45 -07:00
2019-07-05 19:09:01 -07:00
" swap files
set directory=$HOME/.vim/temp//
endif
2019-04-27 06:33:34 -07:00
2019-04-30 21:57:45 -07:00
" set up colors and file types
2019-07-27 11:35:51 -07:00
let g:good_cr=[
\ 'base16-ashes',
\ 'base16-atelier-cave',
\ 'base16-atelier-forest',
\ 'base16-atelier-heath',
\ 'base16-circus',
\ 'base16-dracula',
\ 'base16-material-palenight',
\ 'base16-monokai',
\ 'base16-onedark',
\ 'base16-porple',
\ 'base16-unikitty-dark',
\]
let g:cr_scheme=-1 " -1 = random
2019-04-30 21:57:45 -07:00
syntax on
filetype on
filetype plugin on
filetype indent on
2019-04-27 06:33:34 -07:00
" Functions ------------------------------------------------------------------|
" Automatic headers
2019-04-30 21:22:48 -07:00
fu! <SID>FillLine()
ruby<<
2019-07-05 19:09:01 -07:00
tw = VIM::evaluate("&tw").to_i
tw = 80 if tw == 0
lin = $curbuf.line
rep = tw - lin.length - 3
if rep > 0
$curbuf.line += " " + "-" * rep + "|"
end
2019-04-30 21:22:48 -07:00
.
endfu
2019-04-27 06:33:34 -07:00
" File size
2019-04-30 21:22:48 -07:00
fu! FileSize()
2019-07-05 19:09:01 -07:00
let fs=line2byte(line('$')+1)-1
if fs < 0
return ""
else
return fs
endif
endfu
2019-04-27 06:33:34 -07:00
2019-07-27 11:35:51 -07:00
" Mode printer
fu! ModePrint()
let mode_map = {
\ 'n' : '~ ',
\ 'no' : 'n ',
\ 'nov' : 'n→',
\ 'noV' : 'n↓',
\ 'no' : 'n↔',
\ 'niI' : '←i',
\ 'niR' : '←R',
\ 'niV' : '←v',
\ 'v' : 'v→',
\ 'V' : 'v↓',
\ '' : 'v↔',
\ 's' : 's→',
\ 'S' : 's↓',
\ '' : 's↔',
\ 'i' : 'i ',
\ 'ic' : '↗c',
\ 'ix' : '↗x',
\ 'R' : 'R ',
\ 'Rc' : '↗r',
\ 'Rv' : "R'",
\ 'Rx' : '↗X',
\ 'c' : '% ',
\ 'cv' : ":'",
\ 'ce' : ': ',
\ 'r' : '↲ ',
\ 'rm' : '⎬ ',
\ 'r?' : "↲'",
\ '!' : '… ',
\ 't' : '…!',
\ }
return mode_map[mode()]
endfu
" Statusline prelude function
fu! StatuslinePrelude()
hi clear StatusLine
hi StatusLine guibg=#0a0a0a guifg=#92ebf0
return ''
endfu
2019-04-30 21:22:48 -07:00
" Strip whitespace on buffer write
fu! s:StripWhite()
ruby<<
2019-07-05 19:09:01 -07:00
for ln in 1..$curbuf.length
rs = $curbuf[ln].rstrip
if $curbuf[ln] != rs
$curbuf[ln] = rs
end
end
2019-04-30 21:22:48 -07:00
.
endfu
2019-04-30 21:22:48 -07:00
2019-04-27 06:33:34 -07:00
" Close empty buffers
2019-04-30 21:22:48 -07:00
fu! s:CloseEmptyBuffers()
2019-07-05 19:09:01 -07:00
let bufs = filter(range(1, bufnr('$')), 'buflisted(v:val) && empty(bufname(v:val)) && bufwinnr(v:val) < 0 && !getbufvar(v:val, "&modified")')
if !empty(bufs)
execute 'bdelete' join(bufs, ' ')
endif
endfu
2019-04-27 06:33:34 -07:00
2019-05-07 20:01:14 -07:00
" Commands -------------------------------------------------------------------|
2019-04-30 21:23:05 -07:00
" Find
2019-06-25 16:13:40 -07:00
com -nargs=+ -complete=file -bar Gr silent! grep! "<Args>" | cwindow
" Write (sudo)
com W execute 'w !sudo tee > /dev/null %' | edit!
2019-04-30 21:23:05 -07:00
2019-04-27 06:33:34 -07:00
" Autocommands ---------------------------------------------------------------|
" Strip whitespace
2019-05-07 20:01:14 -07:00
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,markdown au BufWritePre <buffer> call s:StripWhite()
2019-04-27 06:33:34 -07:00
" Enable rainbow braces
2019-06-17 20:04:36 -07:00
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,html,scheme,racket,lisp,json au BufEnter <buffer> RainbowToggleOn
2019-04-27 06:33:34 -07:00
" markdown sucks
au FileType markdown set comments+=fb:- comments-=b:- indentexpr=
2019-04-27 06:33:34 -07:00
" ASM options
2019-05-07 20:01:14 -07:00
au BufNewFile,BufRead *.s,*.inc setlocal shiftwidth=8 filetype=asm_ca65
2019-04-27 06:33:34 -07:00
" close empty buffers automatically
2019-05-07 20:01:14 -07:00
au BufEnter * call s:CloseEmptyBuffers()
2019-04-27 06:33:34 -07:00
2019-07-27 11:35:51 -07:00
" set color randomly on buffer enter
if g:cr_scheme == -1
au BufEnter * execute 'colorscheme' g:good_cr[localtime() % len(g:good_cr)]
endif
2019-06-11 18:12:14 -07:00
" .rkt → Racket
au BufRead,BufNewFile *.rkt set syntax=racket
" .edf → conf
au BufRead,BufNewFile *.edf set syntax=conf
2019-04-27 06:33:34 -07:00
" disable most ftplugins
au BufReadPre * let b:did_ftplugin=1
au BufReadPre *.rkt unlet b:did_ftplugin
2019-04-27 06:33:34 -07:00
" enable tagbar
"au VimEnter * nested :TagbarOpen
2019-04-27 06:33:34 -07:00
" rust.vim sets Cargo.toml to use filetype `cfg` even though it shouldn't, to
" fix this we simply do the same thing before it has a chance to
au BufRead,BufNewFile Cargo.toml if &filetype == "" | set filetype=toml | endif
" vertical split on enter
"au VimEnter * vsplit
2019-04-27 06:33:34 -07:00
" suppress readonly warnings
au BufEnter * set noreadonly
2019-04-27 06:33:34 -07:00
" Mapping --------------------------------------------------------------------|
" Alignment mode
nm ga <Plug>(EasyAlign)
xm ga <Plug>(EasyAlign)
2019-05-07 20:01:14 -07:00
nn <Leader>e :call <SID>FillLine()<CR>
2019-04-27 06:33:34 -07:00
" TagBar
nm <F5> :TagbarToggle<CR>
" Copyright header
2019-05-07 20:01:14 -07:00
nn <Leader>C :0put=strftime('// Copyright © %Y ')<CR>A
2019-04-27 06:33:34 -07:00
" Align text
2019-05-07 20:01:14 -07:00
nn <Leader>c :center<CR>
nn <Leader>R :right<CR>
2019-04-27 06:33:34 -07:00
" Faux asterism
2019-05-07 20:01:14 -07:00
nn <Leader>A o<Esc>A*<CR>* *<Esc><Up>2:center<CR>
2019-04-27 06:33:34 -07:00
" Substitute word across file
2019-05-07 20:01:14 -07:00
nn <Leader>s :%s/\<<C-R><C-W>\>//g<Left><Left>
2019-04-27 06:33:34 -07:00
" Fuck off, highlighting
2019-05-07 20:01:14 -07:00
nn <silent> <Leader><Space> :nohlsearch\|:echo<CR>
2019-04-27 06:33:34 -07:00
" Block comments
2019-05-07 20:01:14 -07:00
nn <Leader>r O//<CR>//<CR>//<Up><End> <Esc>A
2019-04-27 06:33:34 -07:00
" Preview tag
2019-05-07 20:01:14 -07:00
nn <Leader>t :ptag <C-R><C-W><CR>
2019-04-27 06:33:34 -07:00
" Fold mark
nn <Leader>f zfa{
" Spellcheck toggle
2019-05-07 20:01:14 -07:00
nn <Leader>q :setlocal spell!<CR>
2019-04-27 06:33:34 -07:00
" Sort
nn <Leader>S vip:sort<CR>
vn <Leader>S :sort<CR>
" Tmux-like bindings
nn <silent> <Leader>bw :let g:netrw_chgwin = winnr()<CR>
2019-05-07 20:01:14 -07:00
nn <silent> <Leader>b" :new<CR>:wincmd x<CR>:wincmd j<CR>
nn <silent> <Leader>b% :vnew<CR>:wincmd x<CR>:wincmd l<CR>
2019-04-27 06:33:34 -07:00
" Buffer movement
2019-05-07 20:01:14 -07:00
nn <silent> <Leader>bn :bnext<CR>
nn <silent> <Leader>bv :bprevious<CR>
2019-04-27 06:33:34 -07:00
nn <silent> <Leader>be :BufExplorer<CR>
2019-05-07 20:01:14 -07:00
nn <silent> <Leader>bd :bprevious\|bdelete #<CR>
nn <silent> <Leader>bq :bufdo bdelete<CR>
2019-04-27 06:33:34 -07:00
nn <silent> <Leader>bs :new\|BufExplorer<CR>
2019-05-07 20:01:14 -07:00
nn <silent> <Leader>br :browse oldfiles<CR>
2019-04-27 06:33:34 -07:00
nm <Leader>1 <Plug>BufTabLine.Go(1)
nm <Leader>2 <Plug>BufTabLine.Go(2)
nm <Leader>3 <Plug>BufTabLine.Go(3)
nm <Leader>4 <Plug>BufTabLine.Go(4)
nm <Leader>5 <Plug>BufTabLine.Go(5)
nm <Leader>6 <Plug>BufTabLine.Go(6)
nm <Leader>7 <Plug>BufTabLine.Go(7)
nm <Leader>8 <Plug>BufTabLine.Go(8)
nm <Leader>9 <Plug>BufTabLine.Go(9)
" Copy whole file
nn <silent> <Leader>x gg"+yG``
" Mirror
2019-05-07 20:01:14 -07:00
vn <Leader>v c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR>
2019-04-27 06:33:34 -07:00
" Fix syntax
2019-05-07 20:01:14 -07:00
nn <silent> <F11> :syntax sync fromstart<CR>
nn <silent> <F12> :syntax off\|syntax on\|RainbowToggleOn<CR>
2019-04-27 06:33:34 -07:00
" Ctrl-Arrow movement
2019-05-07 20:01:14 -07:00
nn <silent> <C-K> <C-W>+
nn <silent> <C-J> <C-W>-
nn <silent> <C-H> b
nn <silent> <C-L> w
nn <silent> <C-Up> <C-W>+
nn <silent> <C-Down> <C-W>-
2019-04-27 06:33:34 -07:00
nn <silent> <C-Left> b
nn <silent> <C-Right> w
" Better movement
nn j gj
vn j gj
nn k gk
vn k gk
nn <Del> x
vn <Del> x
2019-05-07 20:01:14 -07:00
nn <Up> <NOp>
vn <Up> <NOp>
nn <Down> <NOp>
vn <Down> <NOp>
nn <Left> <NOp>
vn <Left> <NOp>
nn <Right> <NOp>
vn <Right> <NOp>
nn <End> <NOp>
vn <End> <NOp>
nn <Home> <NOp>
vn <Home> <NOp>
nn <PageDown> <NOp>
vn <PageDown> <NOp>
nn <PageUp> <NOp>
vn <PageUp> <NOp>
2019-04-27 06:33:34 -07:00
" abolish
nm cr <Plug>(abolish-coerce-word)
" find
nn KK :Gr \b<C-r><C-w>\b<CR>
nn Kk :Gr<Space>
2019-06-11 18:12:14 -07:00
" quick lambda
nn <Leader>l<Esc>
" auto format
nn Q gqap
2019-04-27 06:33:34 -07:00
" Rainbow Config -------------------------------------------------------------|
let g:rainbow_conf = {
\ 'guifgs': ['#ff533d', '#ff973d', '#ffe13d', '#91ff3d', '#3dffd8', '#3daeff', '#6a3dff', '#ee3dff'],
\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'],
\ 'operators': '_,_',
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
\ 'separately': {
\ '*': {},
\ 'haskell': {
\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'],
\ },
\ 'tex': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'],
\ },
\ 'vim': {
\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
\ },
\ 'xml': {
\ 'syn_name_prefix': 'xmlRainbow',
\ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=#</\z1># fold'],
\ },
\ 'xhtml': {
\ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=#</\z1># fold'],
\ },
\ 'html': {
\ 'parentheses': ['start=/\v\<((script|style|area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold'],
\ },
\ 'perl': {
\ 'syn_name_prefix': 'perlBlockFoldRainbow',
\ },
\ 'php': {
\ 'syn_name_prefix': 'phpBlockRainbow',
\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=#</\z1># fold', 'start=/(/ end=/)/ containedin=@htmlPreproc contains=@phpClTop', 'start=/\[/ end=/\]/ containedin=@htmlPreproc contains=@phpClTop', 'start=/{/ end=/}/ containedin=@htmlPreproc contains=@phpClTop'],
\ },
\ 'stylus': {
\ 'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'],
\ },
\ 'css': 0,
\ 'sh': 0,
\ }
\}
" EOF