rwxrob-dot/vim/.vimrc

387 lines
12 KiB
VimL
Raw Normal View History

2022-02-09 07:29:05 +00:00
" designed for vim 8+
if has("eval") " vim-tiny lacks 'eval'
let skip_defaults_vim = 1
endif
set nocompatible
"####################### Vi Compatible (~/.exrc) #######################
" automatically indent new lines
set autoindent
" automatically write files when changing when multiple files open
set autowrite
" activate line numbers
set number
" turn col and row position on in bottom right
set ruler " see ruf for formatting
" show command and insert mode
set showmode
set tabstop=2
"#######################################################################
2022-02-20 00:07:36 +00:00
" disable visual bell (also disable in .inputrc)
set t_vb=
2022-02-18 01:03:01 +00:00
let mapleader=","
2022-02-09 07:29:05 +00:00
set softtabstop=2
" mostly used with >> and <<
set shiftwidth=2
set smartindent
set smarttab
if v:version >= 800
" stop vim from silently messing with files that it shouldn't
set nofixendofline
" better ascii friendly listchars
set listchars=space:*,trail:*,nbsp:*,extends:>,precedes:<,tab:\|>
" i hate automatic folding
set foldmethod=manual
set nofoldenable
endif
" mark trailing spaces as errors
if has("match")
match ErrorMsg '\s\+$'
endif
" enough for line numbers + gutter within 80 standard
set textwidth=72
" replace tabs with spaces automatically
set expandtab
" disable relative line numbers, remove no to sample it
set norelativenumber
" makes ~ effectively invisible
"highlight NonText guifg=bg
" turn on default spell checking
"set spell
" more risky, but cleaner
set nobackup
set noswapfile
set nowritebackup
set icon
" center the cursor always on the screen
"set scrolloff=999
" highlight search hits
set hlsearch
set incsearch
set linebreak
" avoid most of the 'Hit Enter ...' messages
set shortmess=aoOtTI
" prevents truncated yanks, deletes, etc.
set viminfo='20,<1000,s1000
" not a fan of bracket matching or folding
if has("eval") " vim-tiny detection
let g:loaded_matchparen=1
endif
set noshowmatch
" wrap around when searching
set wrapscan
" Just the defaults, these are changed per filetype by plugins.
" Most of the utility of all of this has been superceded by the use of
" modern simplified pandoc for capturing knowledge source instead of
" arbitrary raw text files.
set fo-=t " don't auto-wrap text using text width
set fo+=c " autowrap comments using textwidth with leader
set fo-=r " don't auto-insert comment leader on enter in insert
set fo-=o " don't auto-insert comment leader on o/O in normal
set fo+=q " allow formatting of comments with gq
set fo-=w " don't use trailing whitespace for paragraphs
set fo-=a " disable auto-formatting of paragraph changes
set fo-=n " don't recognized numbered lists
set fo+=j " delete comment prefix when joining
set fo-=2 " don't use the indent of second paragraph line
set fo-=v " don't use broken 'vi-compatible auto-wrapping'
set fo-=b " don't use broken 'vi-compatible auto-wrapping'
set fo+=l " long lines not broken in insert mode
set fo+=m " multi-byte character line break support
set fo+=M " don't add space before or after multi-byte char
set fo-=B " don't add space between two multi-byte chars
set fo+=1 " don't break a line after a one-letter word
" requires PLATFORM env variable set (in ~/.bashrc)
if $PLATFORM == 'mac'
" required for mac delete to work
set backspace=indent,eol,start
endif
" stop complaints about switching buffer with changes
set hidden
" command history
set history=100
" here because plugins and stuff need it
if has("syntax")
syntax enable
endif
" faster scrolling
set ttyfast
" allow sensing the filetype
filetype plugin on
" high contrast for streaming, etc.
set background=dark
" base default color changes (gruvbox dark friendly)
hi StatusLine ctermfg=black ctermbg=NONE
hi StatusLineNC ctermfg=black ctermbg=NONE
hi Normal ctermbg=NONE
hi Special ctermfg=cyan
hi LineNr ctermfg=black ctermbg=NONE
hi SpecialKey ctermfg=black ctermbg=NONE
hi ModeMsg ctermfg=black cterm=NONE ctermbg=NONE
hi MoreMsg ctermfg=black ctermbg=NONE
hi NonText ctermfg=black ctermbg=NONE
hi vimGlobal ctermfg=black ctermbg=NONE
hi ErrorMsg ctermbg=234 ctermfg=darkred cterm=NONE
hi Error ctermbg=234 ctermfg=darkred cterm=NONE
hi SpellBad ctermbg=234 ctermfg=darkred cterm=NONE
hi SpellRare ctermbg=234 ctermfg=darkred cterm=NONE
hi Search ctermbg=236 ctermfg=darkred
hi vimTodo ctermbg=236 ctermfg=darkred
hi Todo ctermbg=236 ctermfg=darkred
hi IncSearch ctermbg=236 cterm=NONE ctermfg=darkred
hi MatchParen ctermbg=236 ctermfg=darkred
" color overrides
au FileType * hi StatusLine ctermfg=black ctermbg=NONE
au FileType * hi StatusLineNC ctermfg=black ctermbg=NONE
au FileType * hi Normal ctermbg=NONE
au FileType * hi Special ctermfg=cyan
au FileType * hi LineNr ctermfg=black ctermbg=NONE
au FileType * hi SpecialKey ctermfg=black ctermbg=NONE
au FileType * hi ModeMsg ctermfg=black cterm=NONE ctermbg=NONE
au FileType * hi MoreMsg ctermfg=black ctermbg=NONE
au FileType * hi NonText ctermfg=black ctermbg=NONE
au FileType * hi vimGlobal ctermfg=black ctermbg=NONE
2022-02-17 18:42:03 +00:00
au FileType * hi goComment ctermfg=black ctermbg=NONE
2022-02-09 07:29:05 +00:00
au FileType * hi ErrorMsg ctermbg=234 ctermfg=darkred cterm=NONE
au FileType * hi Error ctermbg=234 ctermfg=darkred cterm=NONE
au FileType * hi SpellBad ctermbg=234 ctermfg=darkred cterm=NONE
au FileType * hi SpellRare ctermbg=234 ctermfg=darkred cterm=NONE
au FileType * hi Search ctermbg=236 ctermfg=darkred
au FileType * hi vimTodo ctermbg=236 ctermfg=darkred
au FileType * hi Todo ctermbg=236 ctermfg=darkred
au FileType * hi IncSearch ctermbg=236 cterm=NONE ctermfg=darkred
au FileType * hi MatchParen ctermbg=236 ctermfg=darkred
au FileType markdown,pandoc hi Title ctermfg=yellow ctermbg=NONE
au FileType markdown,pandoc hi Operator ctermfg=yellow ctermbg=NONE
au FileType bash set sw=2
au FileType c set sw=8
set cinoptions+=:0
" Edit/Reload vimr configuration file
nnoremap confe :e $HOME/.vimrc<CR>
nnoremap confr :source $HOME/.vimrc<CR>
set ruf=%30(%=%#LineNr#%.50F\ [%{strlen(&ft)?&ft:'none'}]\ %l:%c\ %p%%%)
" only load plugins if Plug detected
if filereadable(expand("~/.vim/autoload/plug.vim"))
" github.com/junegunn/vim-plug
call plug#begin('~/.local/share/vim/plugins')
"Plug 'sheerun/vim-polyglot'
2022-02-09 07:29:05 +00:00
Plug 'vim-pandoc/vim-pandoc'
Plug 'pegn/pegn-syntax'
2022-02-09 07:29:05 +00:00
Plug 'rwxrob/vim-pandoc-syntax-simple'
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
Plug 'tpope/vim-fugitive'
Plug 'hashivim/vim-terraform'
Plug 'morhetz/gruvbox'
call plug#end()
" terraform
let g:terraform_fmt_on_save = 1
" pandoc
let g:pandoc#formatting#mode = 'h' " A'
let g:pandoc#formatting#textwidth = 72
" golang
let g:go_fmt_fail_silently = 0
let g:go_fmt_command = 'goimports'
let g:go_fmt_autosave = 1
let g:go_gopls_enabled = 1
let g:go_highlight_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_operators = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_variable_declarations = 1
let g:go_highlight_variable_assignments = 1
let g:go_highlight_build_constraints = 1
let g:go_highlight_diagnostic_errors = 1
let g:go_highlight_diagnostic_warnings = 1
"let g:go_auto_type_info = 1 " forces 'Press ENTER' too much
let g:go_auto_sameids = 0
"let g:go_metalinter_command='golangci-lint'
"let g:go_metalinter_command='golint'
"let g:go_metalinter_autosave=1
set updatetime=100
"let g:go_gopls_analyses = { 'composites' : v:false }
au FileType go nmap <leader>t :GoTest!<CR>
au FileType go nmap <leader>v :GoVet!<CR>
au FileType go nmap <leader>b :GoBuild!<CR>
au FileType go nmap <leader>c :GoCoverageToggle<CR>
au FileType go nmap <leader>i :GoInfo<CR>
au FileType go nmap <leader>l :GoMetaLinter!<CR>
2022-02-18 01:03:01 +00:00
au FileType go nmap <leader>m ilog.Print("made")<CR><ESC>
2022-02-09 07:29:05 +00:00
else
autocmd vimleavepre *.go !gofmt -w % " backup if fatih fails
endif
" format perl on save
if has("eval") " vim-tiny detection
fun! s:Perltidy()
let l:pos = getcurpos()
silent execute '%!perltidy -i=2'
call setpos('.', l:pos)
endfun
"autocmd FileType perl autocmd BufWritePre <buffer> call s:Perltidy()
endif
"autocmd vimleavepre *.md !perl -p -i -e 's,(?<!\[)my `(\w+)` (package|module|repo|command|utility),[my `\1` \2](https://gitlab.com/rwxrob/\1),g' %
" fill in empty markdown links with duck.com search
" [some thing]() -> [some thing](https://duck.com/lite?kae=t&q=some thing)
" s,/foo,/bar,g
"autocmd vimleavepre *.md !perl -p -i -e 's,\[([^\]]+)\]\(\),[\1](https://duck.com/lite?kd=-1&kp=-1&q=\1),g' %
autocmd BufWritePost *.md silent !toemoji %
autocmd BufWritePost *.md silent !toduck %
" fill in anything beginning with @ with a link to twitch to it
" autocmd vimleavepre *.md !perl -p -i -e 's, @(\w+), [\\@\1](https://twitch.tv/\1),g' %
" make Y consitent with D and C (yank til end)
map Y y$
" better command-line completion
set wildmenu
" disable search highlighting with <C-L> when refreshing screen
nnoremap <C-L> :nohl<CR><C-L>
" enable omni-completion
set omnifunc=syntaxcomplete#Complete
" force some files to be specific file type
au bufnewfile,bufRead $SNIPPETS/md/* set ft=pandoc
au bufnewfile,bufRead $SNIPPETS/sh/* set ft=sh
au bufnewfile,bufRead $SNIPPETS/bash/* set ft=bash
au bufnewfile,bufRead $SNIPPETS/go/* set ft=go
au bufnewfile,bufRead $SNIPPETS/c/* set ft=c
au bufnewfile,bufRead $SNIPPETS/html/* set ft=html
au bufnewfile,bufRead $SNIPPETS/css/* set ft=css
au bufnewfile,bufRead $SNIPPETS/js/* set ft=javascript
au bufnewfile,bufRead $SNIPPETS/python/* set ft=python
au bufnewfile,bufRead $SNIPPETS/perl/* set ft=perl
au bufnewfile,bufRead user-data set ft=yaml
au bufnewfile,bufRead meta-data set ft=yaml
au bufnewfile,bufRead *.bash* set ft=bash
au bufnewfile,bufRead *.{peg,pegn} set ft=config
au bufnewfile,bufRead *.profile set filetype=sh
au bufnewfile,bufRead *.crontab set filetype=crontab
au bufnewfile,bufRead *ssh/config set filetype=sshconfig
au bufnewfile,bufRead .dockerignore set filetype=gitignore
au bufnewfile,bufRead *gitconfig set filetype=gitconfig
au bufnewfile,bufRead /tmp/psql.edit.* set syntax=sql
au bufnewfile,bufRead *.go set spell
"fix bork bash detection
if has("eval") " vim-tiny detection
fun! s:DetectBash()
if getline(1) == '#!/usr/bin/bash' || getline(1) == '#!/bin/bash'
set ft=bash
set shiftwidth=2
endif
endfun
autocmd BufNewFile,BufRead * call s:DetectBash()
endif
" displays all the syntax rules for current position, useful
" when writing vimscript syntax plugins
if has("syntax")
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
endif
" start at last place you were editing
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"au BufWritePost ~/.vimrc so ~/.vimrc
" functions keys
map <F1> :set number!<CR> :set relativenumber!<CR>
nmap <F2> :call <SID>SynStack()<CR>
set pastetoggle=<F3>
map <F4> :set list!<CR>
map <F5> :set cursorline!<CR>
map <F7> :set spell!<CR>
map <F12> :set fdm=indent<CR>
nmap <leader>2 :set paste<CR>i
" disable arrow keys (vi muscle memory)
"noremap <up> :echoerr "Umm, use k instead"<CR>
"noremap <down> :echoerr "Umm, use j instead"<CR>
"noremap <left> :echoerr "Umm, use h instead"<CR>
" noremap <right> :echoerr "Umm, use l instead"<CR>
" inoremap <up> <NOP>
" inoremap <down> <NOP>
" inoremap <left> <NOP>
" inoremap <right> <NOP>
"
" better use of arrow keys, number increment/decrement
nnoremap <up> <C-a>
nnoremap <down> <C-x>
" Better page down and page up
noremap <C-n> <C-d>
noremap <C-p> <C-b>
" Set TMUX window name to name of file
"au fileopened * !tmux rename-window TESTING
" read personal/private vim configuration (keep last to override)
set rtp^=~/.vimpersonal
set rtp^=~/.vimprivate
set rtp^=~/.vimwork