scripts/vim/vimrc

574 lines
13 KiB
VimL
Raw Blame History

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

" Script Settings ------------------------------------------------------------|
let s:colors=[
\ '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 s:columns=80 " GUI columns
let s:rows=24 " GUI rows
let s:cr_scheme=-1 " color from s:colors, -1 = random
let s:number=1 " 0=no number, 1=enable relativenumber, 2=enable number
let s:enable_list=1 " enable whitespace visibility (2=also newlines)
let s:enable_tagbar=0 " enable tagbar addon
let s:enable_vsp=0 " enable vertical split on enter
" Settings -------------------------------------------------------------------|
" general settings (use :help for these)
set confirm
set wildmenu
set autochdir
set laststatus=2
" visuals
set statusline=%{StatuslinePrelude()}
set statusline+=%{ModePrint()}
set statusline+=\ %r
set statusline+=\ %{&filetype}
set statusline+=\ %f
set statusline+=%=
set statusline+=\ %m
set statusline+=\ %{FileSize()}
set statusline+=\ ↑%4l→%-3c
set statusline+=\ ↓%5L
set statusline+=\ %3p%%
set ruler
set showcmd
set noshowmode
if s:number == 1
set numberwidth=2
set relativenumber
let s:columns+=2
elseif s:number == 2
set numberwidth=4
set relativenumber
set number
let s:columns+=4
endif
set colorcolumn=80
set conceallevel=1
set belloff=all
if s:enable_list >= 1
set list
set listchars=tab:»—,space,trail:∴,extends:>,precedes:<
if s:enable_list >= 2
set listchars+=eol
endif
endif
" 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:%
set formatoptions=tcrqnolj
set nojoinspaces
let mapleader="\<Tab>"
" snappier responses
set ttimeoutlen=0
set lazyredraw
" searching options (highlight, smart casing)
set showmatch
set hlsearch
set smartcase
set ignorecase
set incsearch
" tabulation (3 space hard tabs, auto-indent when my muscle memory demands it)
set autoindent
set smarttab
set noexpandtab
set copyindent
set preserveindent
set softtabstop=0
set shiftwidth=3
set tabstop=3
" limits, what/when/how to save and encodings
set undolevels=10000
set tabpagemax=1000
set viminfo='100,/50,<50,s10,h,%
set viminfo+=n~/.vim/viminfo
set encoding=utf-8
set fileencodings=ucs_bom,utf_8,sjis
set fileformats=unix,dos,mac
set hidden
set updatetime=500
" Plugin Settings ------------------------------------------------------------|
" bufexplorer
let g:bufExplorerDisableDefaultKeyMapping=1
" gutentags
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
let g:buftabline_show=2
let g:buftabline_numbers=2
let g:buftabline_indicators=1
let g:buftabline_separators=0
let g:buftabline_plug_max=19
" 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
" zig.vim
let g:zig_fmt_autosave=0
" polyglot
let g:polyglot_disabled=['c++11']
" gui and terminal specific settings
if has('gui_running')
set guicursor+=i:hor10-Cursor
set guicursor+=a:blinkon0
set guioptions=agit
set guitablabel=%N.%t
let &lines=s:rows
let &columns=s:columns
else
" use high-color terminal capabilities
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
let base16colorspace=256
set termguicolors
endif
" GUI-specific settings
if has('gui_running')
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
" OS-specific settings
if has('win32')
" windows sucks
let $PATH='G:\msys64\usr\bin;'.$PATH
set shellslash
" netrw
let key='G:/msys64/home/marrub/.ssh/id_rsa'
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
" gutentags
let g:gutentags_cache_dir=$VIM.'/vimtags/'
" swap files
set directory=$VIM/vimtemp//
else
if has('mac')
set rubydll=/usr/local/opt/ruby/lib/libruby.dylib
endif
" gutentags
let g:gutentags_cache_dir=$HOME.'/.vim/tags/'
" searching
set grepprg=rg\ --vimgrep\ -n
" swap files
set directory=$HOME/.vim/temp//
endif
" Highlighting ---------------------------------------------------------------|
syntax on
if s:cr_scheme != -1
execute 'colorscheme' s:colors[s:cr_scheme]
endif
filetype on
filetype plugin on
filetype indent on
" Functions ------------------------------------------------------------------|
" Automatic headers
fu! <SID>FillLine()
ruby<<
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
.
endfu
" File size
fu! FileSize()
let fs=line2byte(line('$')+1)-1
if fs < 0
return ""
else
return fs
endif
endfu
" 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
" Strip whitespace on buffer write
fu! s:StripWhite()
ruby<<
for ln in 1..$curbuf.length
li = $curbuf[ln]
if li[-1] == ?\s
$curbuf[ln] = li.rstrip!
end
end
.
endfu
" Close empty buffers
fu! s:CloseEmptyBuffers()
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
" Commands -------------------------------------------------------------------|
" Find
com -nargs=+ -complete=file -bar Gr silent! grep! "<Args>" | cwindow
" Write (sudo)
com W execute 'w !sudo tee > /dev/null %' | edit!
" Autocommands ---------------------------------------------------------------|
" Strip whitespace
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,markdown au BufWritePre <buffer> call s:StripWhite()
" Enable rainbow braces
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,html,scheme,racket,lisp,json au BufEnter <buffer> RainbowToggleOn
" markdown sucks
au FileType markdown set comments+=fb:- comments-=b:- indentexpr=
" ASM options
au BufNewFile,BufRead *.s,*.inc setlocal shiftwidth=8 filetype=asm_ca65
" close empty buffers automatically
au BufEnter * call s:CloseEmptyBuffers()
" set color randomly on buffer enter
if s:cr_scheme == -1
au BufEnter * execute 'colorscheme' s:colors[localtime() % len(s:colors)]
endif
" .rkt → Racket
au BufRead,BufNewFile *.rkt set syntax=racket
" .edf → conf
au BufRead,BufNewFile *.edf set syntax=conf
" disable most ftplugins
au BufReadPre * let b:did_ftplugin=1
au BufReadPre *.rkt unlet b:did_ftplugin
" enable tagbar
if s:enable_tagbar == 1
au VimEnter * nested :TagbarOpen
endif
" 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
if s:enable_vsp == 1
au VimEnter * vsplit
endif
" suppress readonly warnings
au BufEnter * set noreadonly
" Mapping --------------------------------------------------------------------|
" Alignment mode
nm ga <Plug>(EasyAlign)
xm ga <Plug>(EasyAlign)
nn <Leader>e :call <SID>FillLine()<CR>
" TagBar
nm <F5> :TagbarToggle<CR>
" Copyright header
nn <Leader>C :0put=strftime('// Copyright © %Y ')<CR>A
" Align text
nn <Leader>c :center<CR>
nn <Leader>R :right<CR>
" Faux asterism
nn <Leader>A o<Esc>A*<CR>* *<Esc><Up>2:center<CR>
" Substitute word across file
nn <Leader>s :%s/\<<C-R><C-W>\>//g<Left><Left>
" Fuck off, highlighting
nn <silent> <Leader><Space> :nohlsearch\|:echo<CR>
" Block comments
nn <Leader>r O//<CR>//<CR>//<Up><End> <Esc>A
" Preview tag
nn <Leader>t :ptag <C-R><C-W><CR>
" Fold mark
nn <Leader>f zfa{
" Spellcheck toggle
nn <Leader>q :setlocal spell!<CR>
" 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>
nn <silent> <Leader>b" :new<CR>:wincmd x<CR>:wincmd j<CR>
nn <silent> <Leader>b% :vnew<CR>:wincmd x<CR>:wincmd l<CR>
" Buffer movement
nn <silent> <Leader>bn :bnext<CR>
nn <silent> <Leader>bv :bprevious<CR>
nn <silent> <Leader>be :BufExplorer<CR>
nn <silent> <Leader>bd :bprevious\|bdelete #<CR>
nn <silent> <Leader>bq :bufdo bdelete<CR>
nn <silent> <Leader>bs :new\|BufExplorer<CR>
nn <silent> <Leader>br :browse oldfiles<CR>
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
vn <Leader>v c<C-O>:set revins<CR><C-R>"<Esc>:set norevins<CR>
" Fix syntax
nn <silent> <F11> :syntax sync fromstart<CR>
nn <silent> <F12> :syntax off\|syntax on\|RainbowToggleOn<CR>
" Ctrl-Arrow movement
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>-
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
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>
" abolish
nm cr <Plug>(abolish-coerce-word)
" find
nn KK :Gr \b<C-r><C-w>\b<CR>
nn Kk :Gr<Space>
" quick lambda
nn <Leader>l<Esc>
" auto format
nn Q gqap
" 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