scripts/vimrc

417 lines
9.8 KiB
VimL

" Settings -------------------------------------------------------------------|
" general settings (use :help for these)
set confirm
set wildmenu
set autochdir
set laststatus=2
" visuals
set statusline=[%{&syntax}]\ %f
set statusline+=%r
set statusline+=%m
"set statusline+=\ %{tagbar#currenttag('←\ %s\ ','','f')}
set statusline+=\ %=
set statusline+=\ %{FileSize()}
set statusline+=\ %4l:%-3c
set statusline+=\ %4L
set statusline+=\ %3p%%
set ruler
set showcmd
set numberwidth=4
"set relativenumber
"set number
set colorcolumn=81
set conceallevel=1
set belloff=all
" general movement and ergonomics
set linebreak
set showbreak=
set virtualedit=onemore
set backspace=indent,eol,start
set textwidth=80
set comments=s0:/*!,m:\ ,ex:*/,s1:/*,mb:*,ex:*/,:///,://!,://
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 spaces, auto-indent when my muscle memory demands it)
set autoindent
set expandtab
set smarttab
set shiftwidth=3
set softtabstop=-1
" limits, what/when/how to save and encodings
set undolevels=10000
set tabpagemax=1000
set viminfo='100,/50,<50,s10,h,%
set encoding=utf-8
set fileencodings=ucs_bom,utf_8,sjis
set fileformats=unix,dos,mac
set hidden
set updatetime=500
" 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_indicators=1
let g:buftabline_numbers=2
" 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
" gui and terminal specific settings
if has('gui_running')
set guicursor+=i:hor10-Cursor
set guicursor+=a:blinkon0
set guioptions=agit
set lines=50
set columns=80
el
" use 256-color terminal capabilities
set t_Co=256
let base16colorspace=256
set termguicolors
en
" OS-specific settings
if has('gui_running')
if has('win32')
set guifont=PxPlus_IBM_EGA8:h12:cDEFAULT:qDRAFT
el
set guifont=PxPlus\ IBM\ EGA8\ 12
set linespace=-2
en
en
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//
el
" gutentags
let g:gutentags_cache_dir=$HOME.'/.vim/tags/'
" searching
set grepprg=rg\ --vimgrep\ -n
" swap files
set directory=$HOME/.vim/temp//
en
" set up colors and file types
colorscheme base16-porple
syntax on
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
.
endf
" File size
fu! FileSize()
let fs=line2byte(line('$')+1)-1
if fs < 0 | retu "" | else | retu fs | en
endf
" Strip whitespace on buffer write
fu! s:StripWhite()
ruby<<
for ln in 1..$curbuf.length
rs = $curbuf[ln].rstrip
if $curbuf[ln] != rs
$curbuf[ln] = rs
end
end
.
endf
" 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, "&mod")')
if !empty(bufs)
exe 'bd' join(bufs, ' ')
en
endf
" Find
com! -nargs=+ -complete=file -bar Gr sil! gr! "<Args>"|cw
" Autocommands ---------------------------------------------------------------|
" Strip whitespace
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,markdown au BufWritePre <buffer> cal s:StripWhite()
" Enable rainbow braces
au FileType c,cpp,cs,java,php,ruby,rust,python,go,zscript,html,scheme,racket,lisp au BufEnter <buffer> RainbowToggleOn
" ASM options
au BufNewFile,BufRead *.s,*.inc setl sw=8 ft=asm_ca65
" close empty buffers automatically
au BufEnter * cal s:CloseEmptyBuffers()
" EDF → conf
au FileType edif set syn=conf
" disable most ftplugins
au BufReadPre * let b:did_ftplugin=1
" au VimEnter * nested :TagbarOpen
" 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
"au VimEnter * vs
" Mapping --------------------------------------------------------------------|
" Alignment mode
nm ga <Plug>(EasyAlign)
xm ga <Plug>(EasyAlign)
nn <Leader>e :cal <SID>FillLine()<CR>
" TagBar
nm <F5> :TagbarToggle<CR>
" Copyright header
nn <Leader>C :0pu=strftime('// Copyright © %Y ')<CR>A
" Align text
nn <Leader>c :ce<CR>
nn <Leader>R :ri<CR>
" Faux asterism
nn <Leader>A o<ESC>A*<CR>* *<ESC><Up>2:ce<CR>
" Substitute word across file
nn <Leader>s :%s/\<<C-r><C-w>\>//g<Left><Left>
" Fuck off, highlighting
nn <silent> <Leader><Space> :noh<Bar>:ec<CR>
" Block comments
nn <Leader>r O//<CR>//<CR>//<Up><End> <ESC>A
" Preview tag
nn <Leader>t :pta <C-r><C-w><CR>
" Fold mark
nn <Leader>f zfa{
" Spellcheck toggle
nn <Leader>q :setl spell!<CR>
" Map emoji
nn <Leader>E :%s/:\([^:]\+\):/\=emoji#for(submatch(1), submatch(0))/g<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>:winc x<CR>:winc j<CR>
nn <silent> <Leader>b% :vne<CR>:winc x<CR>:winc l<CR>
" Buffer movement
nn <silent> <Leader>bn :bn<CR>
nn <silent> <Leader>bv :bp<CR>
nn <silent> <Leader>be :BufExplorer<CR>
nn <silent> <Leader>bd :bp\|bd #<CR>
nn <silent> <Leader>bq :bufdo bd<CR>
nn <silent> <Leader>bs :new\|BufExplorer<CR>
nn <silent> <Leader>br :bro ol<CR>
nn <silent> <Leader>bb b
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 ri<CR><C-R>"<Esc>:set nori<CR>
" Fix syntax
nn <silent> <F11> :sy sync fromstart<CR>
nn <silent> <F12> :sy off\|sy 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>
" 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