diff --git a/vimrc b/vimrc index 50a52d5..db2f294 100644 --- a/vimrc +++ b/vimrc @@ -12,7 +12,6 @@ " #3 PLUGIN CONFIGS " #4 VISUALS " #5 CUSTOM FUNCTIONS / COMMANDS -" #6 PERSONAL " "################################################################################################### @@ -34,9 +33,6 @@ function! IsWindows() return 0 endfunction -"-------------------------------------------- -" Colors -"-------------------------------------------- if has('termguicolors') set termguicolors " Set Vim-specific sequences for RGB colors @@ -44,23 +40,12 @@ if has('termguicolors') let &t_8b = "\[48;2;%lu;%lu;%lum" endif -let g:campo_dark_theme = 'campo-dark-simple' -"let g:campo_dark_theme = 'campo-dark-blue' -"let g:campo_dark_theme = 'campo-dark-grey-blue' -"let g:campo_dark_theme = 'campo-dark-greyscale' - -let g:campo_light_theme = 'campo-light-simple' -"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 +function! PrintError(msg) abort + exec 'normal! \' + echohl ErrorMsg + echomsg a:msg + echohl None +endfunction "################################################################ "################################################################ @@ -70,40 +55,58 @@ endif "################################################################ "################################################################ -let s:max_line_length = 100 " Display a vertical bar at x=. +" @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=. + +" 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 -" 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`. -let s:default_bg = 'dark' -let s:rainbow_theme = s:default_bg - -" --------------------------------------------------------------------------- -" @note The following globals can be used to customize various functions in -" this file. The easiest way to set them is in an .lvimrc file in the root -" folder that you want it applied to. +"""""""""""""" +" COLORS +"""""""""""""" +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' +let g:campo_theme_use_rainbow_parens = 1 +"""""""""""""" +" FORMATTING +"""""""""""""" " 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 " ignored or always stripped; see below. let g:campo_strip_trailing_whitespace = 1 -" If g:campo_strip_trailing_whitespace is 1 then you can stop stripping -" in specific files by setting this to a list of filenames. This has no -" effect when g:campo_strip_trailing_whitespace is 0. +" If g:campo_strip_trailing_whitespace is 1 then you can stop stripping in +" specific files by setting this to a list of filenames. This has no effect +" when g:campo_strip_trailing_whitespace is 0. " " 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 = [] " 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 -" has no effect when g:campo_strip_trailing_whitespace is 1. +" stripping in specific files by setting this to a list of filenames. This has +" 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'] 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 " 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 @@ -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 = "" +"""""""""""""" +" 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 -" how ctags are built. For example, if you want to ignore the 3rd_party dir -" (remove the backslash from the first quote as that's just here to escape it -" in this comment string) +" how ctags are built. For example, you can exclude a directory that's not in +" g:default_ctags_exclude_args like so (remove the backslash from the first +" 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 = "" -" 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 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 -" that my drive paths aren't in this config. If you want to set them -" here then add: +" +" Store swap, backup and undo files in a central spot. I have my settings in a +" `vimrc.private` so that my drive paths aren't in this config. If you want to +" set them here then add: " " set directory= " set backupdir= @@ -290,6 +298,7 @@ set cursorcolumn " endif " " And make sure those directories exist before opening vim. +" set backup set backupcopy=yes augroup backupCmds @@ -298,9 +307,11 @@ augroup backupCmds augroup END 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 -" this file. Alternatively, you can set it here with `set undodir=` +" +" Keep undo history across sessions by storing it in a file. The undo save +" location is set in the vimrc.private file. You can also set it here with: +" set undodir= +" set undolevels=1000 " Allow undo when going back into a closed file set undoreload=10000 if has('persistent_undo') @@ -318,7 +329,6 @@ syntax on " Enable highlighting for syntax set wildmenu set wildmode=longest,list,full set wildignore+=*/log/*,*.so,*.swp,*.zip,*/rdoc/* -let &colorcolumn=s:max_line_length set grepprg=rg\ --vimgrep " Requires ripgrep to be installed. @@ -350,6 +360,20 @@ imap imap imap +"--------------------------------------------------------------- +" 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 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -468,7 +492,7 @@ augroup campoCmds " Automatically wrap at N characters. 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. autocmd FileType gitcommit,markdown,text setlocal spell @@ -500,16 +524,16 @@ augroup campoCmds let l:lock_file = "ctags.lock" if !filereadable(l:lock_file) && !filereadable("newtags") " 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! else - PrintError "ctags already running (found ".l:lock_file.")" + call PrintError("ctags already running (found ".l:lock_file.")") endif endfun - " Generate ctags on save. - " Also Include local variables for C-like languages. - autocmd BufWritePost *.cs,*.js,*.py,*.c,*.cpp,*.h,*.asm silent! call s:RunCtags() + " Generate ctags on save. In order to use the variable we have to put the + " autocmd in an exec statement. + exec "autocmd BufWritePost ".g:campo_extensions_that_run_ctags." call s:RunCtags()" " Remove trailing whitespace when saving any file. function! s:StripTrailingWhitespaces() @@ -714,7 +738,6 @@ inoremap "################################################################ "################################################################ - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 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 s:light_rainbow = ['red', 'green', 'magenta', 'cyan', 'yellow', 'white', 'gray', 'blue'] let s:dark_rainbow = ['darkblue', 'red', 'black', 'darkgreen', 'darkyellow', 'darkred', 'darkgray'] +let s:rainbow_theme = g:campo_default_bg_mode function! UpdateRainbowConf() let g:rainbow_conf = { @@ -928,7 +952,6 @@ set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " COLORS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" - exec "autocmd ColorScheme " . g:campo_dark_theme . " call ReloadRainbow()" exec "autocmd ColorScheme " . g:campo_light_theme . " call ReloadRainbow()" @@ -957,7 +980,7 @@ function! ChangeBgTheme(bg, onlySetTheme) endif endfunction -if s:default_bg =~ 'light' +if g:campo_default_bg_mode =~ 'light' call ChangeBgTheme('light', 1) else call ChangeBgTheme('dark', 1) @@ -1019,13 +1042,6 @@ augroup END "################################################################ "################################################################ -function! PrintError(msg) abort - exec 'normal! \' - echohl ErrorMsg - echomsg a:msg - echohl None -endfunction - """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " BUILD COMMANDS """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" @@ -1189,10 +1205,9 @@ function! GlobalReplaceIt(confirm_replacement) exec 'Ggrep '.l:term exec 'Qargs | Argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt - " Regen ctags. - call s:RunCtags() + call s:RunCtags() " Regen ctags. 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 endfunction map r :call GlobalReplaceIt(0) @@ -1213,23 +1228,5 @@ function! RenameFile() endfunction map n :call RenameFile() - "--------------------------------------------------------------------------------------------------- - -"################################################################ -"################################################################ -"################################################################ -"#6 PERSONAL -"################################################################ -"################################################################ -"################################################################ - -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" FILE MAPPINGS -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Notes and other helpers -map pn :sp ~/.dev-scratchpad.md - -"let g:autotagStopAt = "$HOME" -