Clean up vim globals and make sure vimrc.private can set them

This commit is contained in:
Michael Campagnaro 2021-12-01 13:59:45 -05:00
parent 90df6cd8fb
commit c9a5e1c936

175
vimrc
View File

@ -12,7 +12,6 @@
" #3 PLUGIN CONFIGS " #3 PLUGIN CONFIGS
" #4 VISUALS " #4 VISUALS
" #5 CUSTOM FUNCTIONS / COMMANDS " #5 CUSTOM FUNCTIONS / COMMANDS
" #6 PERSONAL
" "
"################################################################################################### "###################################################################################################
@ -34,9 +33,6 @@ function! IsWindows()
return 0 return 0
endfunction endfunction
"--------------------------------------------
" Colors
"--------------------------------------------
if has('termguicolors') if has('termguicolors')
set termguicolors set termguicolors
" Set Vim-specific sequences for RGB colors " Set Vim-specific sequences for RGB colors
@ -44,23 +40,12 @@ if has('termguicolors')
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif endif
let g:campo_dark_theme = 'campo-dark-simple' function! PrintError(msg) abort
"let g:campo_dark_theme = 'campo-dark-blue' exec 'normal! \<Esc>'
"let g:campo_dark_theme = 'campo-dark-grey-blue' echohl ErrorMsg
"let g:campo_dark_theme = 'campo-dark-greyscale' echomsg a:msg
echohl None
let g:campo_light_theme = 'campo-light-simple' endfunction
"let g:campo_light_theme = 'campo-light-greyscale'
"let g:campo_light_theme = 'campo-light'
let g:campo_theme_use_rainbow_parens = 1
"--------------------------------------------
" You can further customize things in a private vimrc. I use this for things
" that I don't want included in my public dotfiles repo such as temp file settings.
if filereadable($HOME . "/.vimrc.private")
source $HOME/.vimrc.private
endif
"################################################################ "################################################################
"################################################################ "################################################################
@ -70,40 +55,58 @@ endif
"################################################################ "################################################################
"################################################################ "################################################################
let s:max_line_length = 100 " Display a vertical bar at x=<n>. " @note The following globals can be used to customize various functions in
" this file. The easiest way to set them is in ~/.vimrc.private or an .lvimrc
" file in the root folder that you want it applied to.
"
" Some variables cannot be customized in an .lvimrc because their value is used
" by settings in this file when its sourced. These have been flagged with a note.
"
" Also take note that an .lvimrc has precedence because it's loaded after this
" and the private vimrc.
" Set the row height of the quickfix pane, which is used to display results from various plugins (like ctrl-p, ripgrep, compilation errors, etc), in rows " --------------------------------------------------------------------------------------------------
" @note unsupported in lvimrc
let g:campo_max_line_length = 100 " Display a vertical bar at x=<n>.
" Set the row height of the quickfix pane, which is used to display results
" from various plugins (like ctrl-p, ripgrep, compilation errors, etc), in rows
let g:quickfix_pane_height = 20 let g:quickfix_pane_height = 20
" Start vim with the dark theme. Set to 'light' for the light theme. """"""""""""""
" To change the themes see `g:campo_dark_theme` and `g:campo_light_theme`. " COLORS
let s:default_bg = 'dark' """"""""""""""
let s:rainbow_theme = s:default_bg let g:campo_default_bg_mode = 'dark' " Start vim with the dark theme. Set to 'light' for the light theme.
let g:campo_dark_theme = 'campo-dark-simple' "'campo-dark-blue'
" --------------------------------------------------------------------------- let g:campo_light_theme = 'campo-light-simple' "'campo-light'
" @note The following globals can be used to customize various functions in let g:campo_theme_use_rainbow_parens = 1
" this file. The easiest way to set them is in an .lvimrc file in the root
" folder that you want it applied to.
""""""""""""""
" FORMATTING
""""""""""""""
" When set to 1, all files will be stripped of trailing whitespace when the " When set to 1, all files will be stripped of trailing whitespace when the
" file is saved. Set to 0 to disable. You can customize which files are " file is saved. Set to 0 to disable. You can customize which files are
" ignored or always stripped; see below. " ignored or always stripped; see below.
let g:campo_strip_trailing_whitespace = 1 let g:campo_strip_trailing_whitespace = 1
" If g:campo_strip_trailing_whitespace is 1 then you can stop stripping " If g:campo_strip_trailing_whitespace is 1 then you can stop stripping in
" in specific files by setting this to a list of filenames. This has no " specific files by setting this to a list of filenames. This has no effect
" effect when g:campo_strip_trailing_whitespace is 0. " when g:campo_strip_trailing_whitespace is 0.
" "
" e.g. let g:campo_files_to_ignore_when_stripping_trailing_whitespace = ['app.h', 'config.h'] " e.g. let g:campo_files_to_ignore_when_stripping_trailing_whitespace = ['app.h', 'config.h']
let g:campo_files_to_ignore_when_stripping_trailing_whitespace = [] let g:campo_files_to_ignore_when_stripping_trailing_whitespace = []
" If g:campo_strip_trailing_whitespace is 0 then you can force whitespace " If g:campo_strip_trailing_whitespace is 0 then you can force whitespace
" stripping in specific files by setting this to a list of filenames. This " stripping in specific files by setting this to a list of filenames. This has
" has no effect when g:campo_strip_trailing_whitespace is 1. " no effect when g:campo_strip_trailing_whitespace is 1.
" e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['app.h', 'config.h'] " e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['app.h', 'config.h']
let g:campo_files_to_force_stripping_trailing_whitespace = [] let g:campo_files_to_force_stripping_trailing_whitespace = []
""""""""""""""
" SEARCH
""""""""""""""
" This is included in the ripgrep args. You can use this to do things like " This is included in the ripgrep args. You can use this to do things like
" ignore folders in your project or limit the search to specific file types. " ignore folders in your project or limit the search to specific file types.
" For example, if you want to ignore the 3rd_party dir and only search C files " For example, if you want to ignore the 3rd_party dir and only search C files
@ -112,17 +115,22 @@ let g:campo_files_to_force_stripping_trailing_whitespace = []
" let g:campo_custom_search_args = \"-g \"!3rd_party/*\" -tc" " let g:campo_custom_search_args = \"-g \"!3rd_party/*\" -tc"
let g:campo_custom_search_args = "" let g:campo_custom_search_args = ""
""""""""""""""
" CTAGS
""""""""""""""
" If one of these file types are saved then the ctags creation function will be called.
let g:campo_extensions_that_run_ctags = "*.{cs,js,py,h,hpp,c,cpp,inc,asm}"
" Default files and directories that ctags should ignore.
let g:default_ctags_exclude_args = "--exclude=.git --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.cache"
" This is included in the ctags autocmd args. You can use this to customize " This is included in the ctags autocmd args. You can use this to customize
" how ctags are built. For example, if you want to ignore the 3rd_party dir " how ctags are built. For example, you can exclude a directory that's not in
" (remove the backslash from the first quote as that's just here to escape it " g:default_ctags_exclude_args like so (remove the backslash from the first
" in this comment string) " quote as that's just here to escape it in this comment string)
" let g:campo_custom_ctags_args = \"--exclude=3rd_party" " let g:campo_custom_ctags_args = \"--exclude=3rd_party"
let g:campo_custom_ctags_args = "" let g:campo_custom_ctags_args = ""
" Default files and directories that ctags should ignore.
let s:default_ctags_exclude_args = "--exclude=.git --exclude=*.md --exclude=*.txt --exclude=*.config --exclude=*.css --exclude=*.html --exclude=*.htm --exclude=*.json --exclude=node_modules --exclude=.cache"
" ---------------------------------------------------------------------------
"################################################################ "################################################################
"################################################################ "################################################################
@ -278,10 +286,10 @@ set scrolloff=3 " keep more context when scrolling off the end
set cursorline set cursorline
set cursorcolumn set cursorcolumn
" Store swap, backup and undo files in a central spot. I have my settings in "
" a `vimrc.private` file that is sourced near the top of this file so " Store swap, backup and undo files in a central spot. I have my settings in a
" that my drive paths aren't in this config. If you want to set them " `vimrc.private` so that my drive paths aren't in this config. If you want to
" here then add: " set them here then add:
" "
" set directory=<dir path for swap files> " set directory=<dir path for swap files>
" set backupdir=<dir path for backup files> " set backupdir=<dir path for backup files>
@ -290,6 +298,7 @@ set cursorcolumn
" endif " endif
" "
" And make sure those directories exist before opening vim. " And make sure those directories exist before opening vim.
"
set backup set backup
set backupcopy=yes set backupcopy=yes
augroup backupCmds augroup backupCmds
@ -298,9 +307,11 @@ augroup backupCmds
augroup END augroup END
set writebackup " Make buckup before overwriting the current buffer. set writebackup " Make buckup before overwriting the current buffer.
" Keep undo history across sessions by storing it in a file. The undo save "
" location is set in the vimrc.private file that is sourced near the top of " Keep undo history across sessions by storing it in a file. The undo save
" this file. Alternatively, you can set it here with `set undodir=<path>` " location is set in the vimrc.private file. You can also set it here with:
" set undodir=<path>
"
set undolevels=1000 " Allow undo when going back into a closed file set undolevels=1000 " Allow undo when going back into a closed file
set undoreload=10000 set undoreload=10000
if has('persistent_undo') if has('persistent_undo')
@ -318,7 +329,6 @@ syntax on " Enable highlighting for syntax
set wildmenu set wildmenu
set wildmode=longest,list,full set wildmode=longest,list,full
set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/* set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/*
let &colorcolumn=s:max_line_length
set grepprg=rg\ --vimgrep " Requires ripgrep to be installed. set grepprg=rg\ --vimgrep " Requires ripgrep to be installed.
@ -350,6 +360,20 @@ imap <down> <nop>
imap <left> <nop> imap <left> <nop>
imap <right> <nop> imap <right> <nop>
"---------------------------------------------------------------
" Load vimrc.private
" This should be done after above base settings that don't use the global
" campo variables.
"
" You can further customize things in a private vimrc. I use this for things
" that I don't want included in my public dotfiles repo such as temp file settings.
if filereadable($HOME . "/.vimrc.private")
source $HOME/.vimrc.private
endif
" Settings that use the global campo variables.
let &colorcolumn=g:campo_max_line_length
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS " CUSTOM AUTOCMDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -468,7 +492,7 @@ augroup campoCmds
" Automatically wrap at N characters. " Automatically wrap at N characters.
autocmd FileType gitcommit setlocal colorcolumn=72 autocmd FileType gitcommit setlocal colorcolumn=72
autocmd BufRead,BufNewFile *.{md,txt,plan} exec "setlocal textwidth=" .s:max_line_length autocmd BufRead,BufNewFile *.{md,txt,plan} exec "setlocal textwidth=".g:campo_max_line_length
" Spell checking. " Spell checking.
autocmd FileType gitcommit,markdown,text setlocal spell autocmd FileType gitcommit,markdown,text setlocal spell
@ -500,16 +524,16 @@ augroup campoCmds
let l:lock_file = "ctags.lock" let l:lock_file = "ctags.lock"
if !filereadable(l:lock_file) && !filereadable("newtags") if !filereadable(l:lock_file) && !filereadable("newtags")
" Will include local variables for C-like languages. " Will include local variables for C-like languages.
let l:ctags_cmd = "!(touch ".l:lock_file."; ctags --c-types=+l --c++-types=+l ".s:default_ctags_exclude_args." ". g:campo_custom_ctags_args." --recurse=yes -o newtags; mv newtags tags; rm ".l:lock_file.") &" let l:ctags_cmd = "!(touch ".l:lock_file."; ctags --c-types=+l --c++-types=+l ".g:default_ctags_exclude_args." ". g:campo_custom_ctags_args." --recurse=yes -o newtags; mv newtags tags; rm ".l:lock_file.") &"
silent! exec l:ctags_cmd | redraw! silent! exec l:ctags_cmd | redraw!
else else
PrintError "ctags already running (found ".l:lock_file.")" call PrintError("ctags already running (found ".l:lock_file.")")
endif endif
endfun endfun
" Generate ctags on save. " Generate ctags on save. In order to use the variable we have to put the
" Also Include local variables for C-like languages. " autocmd in an exec statement.
autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h,*.asm silent! call s:RunCtags() exec "autocmd BufWritePost ".g:campo_extensions_that_run_ctags." call s:RunCtags()"
" Remove trailing whitespace when saving any file. " Remove trailing whitespace when saving any file.
function! s:StripTrailingWhitespaces() function! s:StripTrailingWhitespaces()
@ -714,7 +738,6 @@ inoremap <s-tab> <c-n>
"################################################################ "################################################################
"################################################################ "################################################################
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LOCAL VIMRC " LOCAL VIMRC
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -844,6 +867,7 @@ let g:clojure_fuzzy_indent_blacklist = ['-fn$', '\v^with-%(meta|out-str|loading-
let g:rainbow_active = 1 " Always on let g:rainbow_active = 1 " Always on
let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gray', 'blue'] let s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gray', 'blue']
let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray'] let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray']
let s:rainbow_theme = g:campo_default_bg_mode
function! UpdateRainbowConf() function! UpdateRainbowConf()
let g:rainbow_conf = { let g:rainbow_conf = {
@ -928,7 +952,6 @@ set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLORS " COLORS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()" exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()"
exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()" exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()"
@ -957,7 +980,7 @@ function! ChangeBgTheme(bg, onlySetTheme)
endif endif
endfunction endfunction
if s:default_bg =~ 'light' if g:campo_default_bg_mode =~ 'light'
call ChangeBgTheme('light', 1) call ChangeBgTheme('light', 1)
else else
call ChangeBgTheme('dark', 1) call ChangeBgTheme('dark', 1)
@ -1019,13 +1042,6 @@ augroup END
"################################################################ "################################################################
"################################################################ "################################################################
function! PrintError(msg) abort
exec 'normal! \<Esc>'
echohl ErrorMsg
echomsg a:msg
echohl None
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BUILD COMMANDS " BUILD COMMANDS
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
@ -1189,10 +1205,9 @@ function! GlobalReplaceIt(confirm_replacement)
exec 'Ggrep '.l:term exec 'Ggrep '.l:term
exec 'Qargs | Argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt exec 'Qargs | Argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt
" Regen ctags. call s:RunCtags() " Regen ctags.
call s:RunCtags()
else else
PrintError "Unable to search since you're not in a git repo!" call PrintError("Unable to search since you're not in a git repo!")
endif endif
endfunction endfunction
map <leader>r :call GlobalReplaceIt(0)<cr> map <leader>r :call GlobalReplaceIt(0)<cr>
@ -1213,23 +1228,5 @@ function! RenameFile()
endfunction endfunction
map <leader>n :call RenameFile()<cr> map <leader>n :call RenameFile()<cr>
"--------------------------------------------------------------------------------------------------- "---------------------------------------------------------------------------------------------------
"################################################################
"################################################################
"################################################################
"#6 PERSONAL
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FILE MAPPINGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Notes and other helpers
map <leader>pn :sp ~/.dev-scratchpad.md<cr>
"let g:autotagStopAt = "$HOME"