Vim Update Complete

This commit is contained in:
Bill Niblock 2024-12-29 12:22:09 -05:00
parent 5fc7c37c3d
commit 3810359e1b
12 changed files with 682 additions and 1498 deletions

173
vim/vimrc
View file

@ -1,7 +1,6 @@
" ==============================================================================
" vimrc file for niblock :: Use `:so %` to re-source after changes
" ==============================================================================
" ==============================================================================
" General Settings
" ==============================================================================
@ -45,95 +44,43 @@ set nohlsearch " Disable search highlighting
let g:netrw_liststyle=3 " Netrw Tree list style
let g:netrw_banner=0 " Disable the netrw banner
augroup ruby_settings " Custom settings: Ruby{-like}
autocmd!
autocmd FileType ruby,eruby,yaml
\ setlocal makeprg=rubocop
augroup END
augroup python_settings " Custom settings: Python-like
autocmd!
autocmd FileType py
\ setlocal shiftwidth=4
\ softtabstop=4
augroup END
augroup shell_settings " Custom settings: Shell-like
autocmd!
autocmd FileType sh
\ setlocal makeprg=shellcheck
augroup END
augroup spellcheckr " Spelling, for some files...
autocmd!
autocmd BufNewFile,BufRead *.md,*.rdoc,*.txt,*.wiki
\ setlocal spell
augroup END
augroup lintr " Linting, based on :make!
autocmd!
autocmd BufWritePost *.rb,*.sh
\ silent make! <afile> | silent redraw!
autocmd QuickFixCmdPost [^l]* cwindow
augroup END
" ==============================================================================
" Colors
" Colors [VIM Only]
" ==============================================================================
augroup user_stl_colors " Custom status-line colors
autocmd!
autocmd ColorScheme *
\ hi User1 term=bold cterm=bold ctermfg=Red ctermbg=DarkGrey |
\ hi User2 term=bold cterm=bold ctermfg=Cyan ctermbg=DarkGrey |
\ hi User3 term=bold cterm=bold ctermfg=White ctermbg=DarkGrey |
\ hi User4 ctermfg=White ctermbg=Black |
\ hi User5 ctermfg=150 ctermbg=Black |
\ hi User6 ctermfg=Grey ctermbg=Black
augroup END
if !has('nvim')
set termguicolors " Enable fancy colors
if filereadable(expand('~/.vim/colors/minimalist.vim'))
colorscheme minimalist " Set colorscheme
if filereadable(expand('~/.config/vim/colors/catppuccin_frappe.vim'))
colorscheme catppuccin_frappe " Set colorscheme, if available
endif
hi link User1 Directory " Set User statusline colors
hi link User2 Title " Used as '%n*', n = 1..6
hi link User3 SpellBad " See :hi for colors
hi link User4 Added
hi link User5 Changed
hi link User6 Removed
endif
" ==============================================================================
" Status Line
" Status Line [VIM Only]
" ==============================================================================
set laststatus=2 " Enable the statusline
set statusline=%!ActiveStatus() " Style it
if !has('nvim')
set laststatus=2 " Enable the statusline
set statusline=%!SLine() " Style it
function! ActiveStatus() abort " When in the active window
let statusline="" " Initialize it
let statusline.="%3*%m" " Modified flag
let statusline.="%6*%{expand('%:p:h')}/" " Full-path to current buffer
let statusline.="%4*%t" " File name
let statusline.="%5*%{GitBranch()}" " Show Git branch, if applicable
let statusline.="%=" " Switch to right-side
let statusline.="%4*%y\ " " Filetype
let statusline.="%3*" " Color change (see :hi)
let statusline.="\|%4l\:%2c\|" " Line and column
let statusline.="%2*%{&spell?'[SPELL]':''}" " Spell flag
let statusline.="%1*%r%0*" " Read-only flag
return statusline
endfunction
function! PassiveStatus() abort " When in a non-active window
let statusline="" " Initialize it
let statusline.="%6*%m" " Modified flag
let statusline.="%{expand('%:p:h')}/" " Full-path to current buffer
let statusline.="%t" " File name
let statusline.="%{GitBranch()}" " Show Git branch, if applicable
let statusline.="%=" " Switch to right-side
let statusline.="%y\ " " Filetype
let statusline.="\|%4l\:%2c\|" " Line and column
let statusline.="%{&spell?'[SPELL]':''}" " Spell flag
let statusline.="%r%0*" " Read-only flag
return statusline
endfunction
augroup user_statusline " Change based on active window
autocmd!
autocmd WinEnter * setlocal statusline=%!ActiveStatus()
autocmd WinLeave * setlocal statusline=%!PassiveStatus()
augroup END
function! SLine() abort
let sline="" " Initialize it
let sline.="%3*%m" " Modified flag
let sline.="%1*%{expand('%:p:h')}/" " Full-path to current buffer
let sline.="%2*%t" " File name
let sline.="%=" " Switch to right-side
let sline.="%4*%y\ " " Filetype
let sline.="%5*%{&spell?'[SPELL]':''}" " Spell flag
let sline.="%6*%r" " Read-only flag
let sline.="%1*\|%4l\:%2c\|" " Line and column
return sline
endfunction
endif
" ==============================================================================
" Mappings
" ==============================================================================
@ -143,70 +90,10 @@ nnoremap <silent> j gj
nnoremap <silent> k gk
nnoremap <silent> ^ g^
nnoremap <silent> $ g$
" Toggle fold with space if we're in a fold, otherwise just space
nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
" Remove Trailing Whitespaace
nnoremap <silent> <leader>rtw :<C-u>%s/\s\+$//e<CR>
" Open help topic in a full new tab
command! -nargs=1 -complete=help H :tabnew | :set buftype=help | :h <args>
" Simple mapping to dotfiles directory (f = current tab; F = new tab)
nnoremap <silent> <leader>f :<C-u>edit ~/.dotfiles/<CR>
nnoremap <silent> <leader>F :<C-u>tabnew ~/.dotfiles/<CR>
" Emulate vim-vinegar
nnoremap <silent> - :silent edit <C-R>=empty(expand('%')) ? '.' :
\ expand('%:p:h')<CR><CR>
" Send the select range to the specified pane
command! -nargs=? -range Twrite execute TmuxWrite(<q-args>, <line1>, <line2>)
" Some notes/wiki shortcuts
nnoremap <silent> <leader>ww :<C-u>edit ~/Documents/Wiki/index.md<CR>
nnoremap <silent> <leader>ws :<C-u>vsplit ~/Documents/Wiki/scratchpad.md<CR>
nnoremap <silent> <leader>wt :<C-u>vsplit ~/Documents/Wiki/to-do.md<CR>
nnoremap <silent> <leader>wd :<C-u>edit ~/Documents/Wiki/diary/diary.wiki<CR>
nnoremap <silent> <leader>tj :call NewJournal()<CR>
nnoremap <silent> <leader><Space> :<C-u>execute "normal! f(gf"<CR>
" ==============================================================================
" Functions
" ==============================================================================
" Read from the journal template, and replace 'Date' with today's date
function! NewJournal() abort
.-1read ~/.vim/templates/journal
s/Date/\=strftime("%A, %B %d")/
endfunction
" Fetch the git branch of the current file, if applicable
function! GitBranch() abort
let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null
\ | tr -d '\n'")
return strlen(l:branchname) > 0 ? '#'.l:branchname : ''
endfunction
" Simple tmux send-keys functionality
function! TmuxWrite(pane, line1, line2) abort
let l:val = join(filter(map(getline(a:line1, a:line2),
\ 'substitute(v:val, "^\\s*", "", "")'),
\ "!empty(v:val)"),
\ "\r")
try
if empty(a:pane)
throw 'Twrite Failed: No pane provided'
endif
let l:panes = systemlist('tmux list-panes -t '.a:pane.' -F "#D
\ #{pane_active}"')
let l:target = substitute(
\join(filter(l:panes, 'match(v:val, ''%\d 1'') == 0'), ""),
\'\(%\d\) 1', '\1', "")
if l:target ==# $TMUX_PANE
throw 'Twrite Failed: Not writing self'
endif
let l:out = system('tmux send-keys -t'.l:target.' "" '
\.shellescape(l:val))
if v:shell_error
throw 'Twrite Failed: '.l:out[0:-2]
endif
echo len(l:val).' keys sent to '.a:pane
return ''
catch /.*/
return 'echoerr '.string(v:exception)
endtry
endfunction