2020-01-06 18:07:39 +00:00
" @incomplete Move all leader definitions to the bottom , so that it 's easier to see them .
2019-05-24 17:24:38 +00:00
" @incomplete Add setup steps (plugins, cache setup, search tool, etc).
2019-12-31 05:37:09 +00:00
"###################################################################################################
"
" The config is chopped up into sections. These are the headings, which you
" can use to quickly jump to a particular section:
2021-02-08 20:40:32 +00:00
" #0 GLOBALS
" #1 PLUGINS
" #2 BASE CONFIG
" #3 PLUGIN CONFIGS
" #4 VISUALS
" #5 CUSTOM FUNCTIONS / COMMANDS
" #6 PERSONAL
2019-12-31 05:37:09 +00:00
"
"###################################################################################################
2016-04-11 00:42:09 +00:00
scriptencoding utf -8
2017-03-27 18:39:07 +00:00
set encoding = utf -8 fileencoding = utf -8 fileencodings = ucs - bom , utf8 , prc
2017-07-28 15:20:08 +00:00
set nocompatible
filetype off
2016-04-11 00:59:36 +00:00
" Store the current system name so that we can conditionally set configs for
" different platforms
let s :uname = system ( "echo -n \"$(uname)\"" )
2016-12-12 05:00:37 +00:00
let s :vim_dir = $HOME . "/.vim"
2020-06-10 15:40:12 +00:00
let mapleader = ","
2016-04-11 00:59:36 +00:00
function ! IsWindows ( )
2019-09-12 03:12:10 +00:00
if s :uname = ~ "mingw" | | s :uname = ~ "msys"
2019-12-31 05:37:09 +00:00
return 1
endif
return 0
2016-04-11 00:59:36 +00:00
endfunction
2020-06-10 15:40:12 +00:00
"--------------------------------------------
" Colors
"--------------------------------------------
2020-07-25 20:38:58 +00:00
if has ( 'termguicolors' )
set termguicolors
" Set Vim-specific sequences for RGB colors
let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
2021-05-27 21:39:42 +00:00
let g :campo_dark_theme = 'campo-dark-simple'
2020-06-10 15:40:12 +00:00
"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'
2021-05-27 21:39:42 +00:00
let g :campo_light_theme = 'campo-light-simple'
"let g:campo_light_theme = 'campo-light-greyscale'
2020-06-10 15:40:12 +00:00
"let g:campo_light_theme = 'campo-light'
let g :campo_theme_use_rainbow_parens = 1
"--------------------------------------------
2012-11-16 06:05:17 +00:00
2021-07-14 15:16:23 +00:00
" 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
2020-01-06 18:07:39 +00:00
2017-07-18 15:21:03 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#0 GLOBALS
2017-07-18 15:21:03 +00:00
"################################################################
"################################################################
"################################################################
2021-10-14 18:20:40 +00:00
let s :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
2020-01-06 18:07:39 +00:00
" Start vim with the dark theme. Set to 'light' for the light theme.
2020-06-10 15:40:12 +00:00
" To change the themes see `g:campo_dark_theme` and `g:campo_light_theme`.
2017-07-18 15:21:03 +00:00
let s :default_bg = 'dark'
let s :rainbow_theme = s :default_bg
2020-01-08 15:54:01 +00:00
" ---------------------------------------------------------------------------
" @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.
2021-07-15 15:55:29 +00:00
" 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.
2020-01-08 15:54:01 +00:00
let g :campo_strip_trailing_whitespace = 1
2021-07-15 15:55:29 +00:00
" 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.
"
2020-10-26 03:39:08 +00:00
" 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 = []
2021-07-15 15:55:29 +00:00
" 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.
" e.g. let g:campo_files_to_force_stripping_trailing_whitespace = ['app.h', 'config.h']
let g :campo_files_to_force_stripping_trailing_whitespace = []
2020-01-08 15:54:01 +00:00
" 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
" (remove the backslash from the first quote as that's just here to escape it
" in this comment string)
" let g:campo_custom_search_args = \"-g \"!3rd_party/*\" -tc"
let g :campo_custom_search_args = ""
" 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)
" let g:campo_custom_ctags_args = \"--exclude=3rd_party"
let g :campo_custom_ctags_args = ""
2021-12-01 18:57:38 +00:00
" 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"
2020-01-08 15:54:01 +00:00
" ---------------------------------------------------------------------------
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#1 PLUGINS
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2015-11-29 19:41:56 +00:00
call plug #begin ( '~/.vim/plugged' )
2015-02-24 04:34:00 +00:00
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" MISC
"////////////////////////////////////////////////////////////////
2017-04-27 22:39:58 +00:00
2019-12-31 05:37:09 +00:00
Plug 'bling/vim-airline' " Enhanced status/tabline.
Plug 'embear/vim-localvimrc' " Add a .lvimrc to a folder to override .vimrc config.
Plug 'tpope/vim-obsession' " Continuously updated session files (tracks window positions, open folds, etc).
Plug 'tpope/vim-fugitive' " Git wrapper (I particularly like :Gblame, which I've wrapped as :Blame)
Plug 'junegunn/goyo.vim' " Distraction-free mode with centered buffer.
Plug 'sir-pinecone/vim-ripgrep' " Fast grep-like search. Requires ripgrep; install Rust package: `cargo install ripgrep`.
Plug 'itchyny/vim-cursorword' " Underlines all instances of the symbol under the cursor.
Plug 'airblade/vim-gitgutter' " Displays a git diff in the vim gutter and allows staging/unstaging of hunks.
Plug 'ctrlpvim/ctrlp.vim' " Fuzzy file, buffer, mru, tag, etc finder.
Plug 'majutsushi/tagbar' " Display ctags in a window, ordered by scope.
Plug 'tommcdo/vim-lion' " For text alignment, use gl= and gL=
Plug 'tpope/tpope-vim-abolish' " Easily search for, substitute, and abbreviate multiple variants of a word. Add them to `vim/after/plugin/abolish.vim`
Plug 'vim-scripts/AnsiEsc.vim' " Ansi escape sequences concealed, but highlighted as specified.
Plug 'tommcdo/vim-kangaroo' " Maintain a manually-defined jump stack. Set with zp or <leader>a and pop with zP or <leader>aa.
Plug 'mh21/errormarker.vim' " Build error highlighting (requires skywind3000/asyncrun.vim).
Plug 'skywind3000/asyncrun.vim' " Async commands.
Plug 'nelstrom/vim-qargs' " For the GlobalReplaceIt function (i.e. search and replace).
2018-06-11 17:39:04 +00:00
2019-03-28 00:15:55 +00:00
if IsWindows ( )
2019-12-31 05:37:09 +00:00
Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so).
2017-11-15 16:30:09 +00:00
endif
2017-06-16 20:51:40 +00:00
2019-03-28 00:15:55 +00:00
"///////////////////
" MAYBE SOME DAY
"///////////////////
2019-12-31 05:37:09 +00:00
"Plug 'shougo/unite.vim' " Create user interfaces. Not currently needed.
"Plug 'itchyny/vim-winfix' " Fix the focus and the size of windows in Vim.
"Plug 'scrooloose/nerdcommenter' " Better commenting.
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" COLORS
"////////////////////////////////////////////////////////////////
2017-04-27 22:39:58 +00:00
2019-09-09 19:39:07 +00:00
Plug 'luochen1990/rainbow' , { 'commit' : '1c45e0f' } " Rainbow parens. Locked to an older commit that still works fine on my PC.
2019-12-31 05:37:09 +00:00
"Plug 'flazz/vim-colorschemes' " @warning: Has a lot of themes, but they break the other themes listed below
2021-12-01 04:04:27 +00:00
Plug 'sir-pinecone/vim-elixir'
2017-04-27 20:22:32 +00:00
Plug 'vim-airline/vim-airline-themes'
2015-03-24 21:55:35 +00:00
2020-07-26 17:11:49 +00:00
if IsWindows ( )
Plug 'godlygeek/csapprox' " Try to make gvim themes look decent on Windows.
endif
2017-04-27 22:39:58 +00:00
" Light Themes
2020-07-26 17:11:49 +00:00
Plug 'raggi/vim-color-raggi' " @note No Windows support, unless using gvim.
Plug 'LanFly/vim-colors' " @note No Windows support, unless using gvim.
2017-04-27 22:39:58 +00:00
" Dark Themes
2020-07-26 17:11:49 +00:00
Plug 'rhysd/vim-color-spring-night' " @note No Windows support, unless using gvim.
2017-04-27 22:39:58 +00:00
Plug 'nanotech/jellybeans.vim'
Plug 'zcodes/vim-colors-basic'
" Hybrid Themes
Plug 'sickill/vim-monokai'
2020-07-26 17:11:49 +00:00
Plug 'chmllr/elrodeo-vim-colorscheme' " A little dark on Windows.
Plug 'reedes/vim-colors-pencil' " High-contrast.
2017-07-10 15:08:49 +00:00
" Seabird themes
" High contrast: seagull (light), petrel (dark)
" Low contrast: greygull (light), stormpetrel (dark)
2020-07-26 17:11:49 +00:00
Plug 'nightsense/seabird' " @note No Windows support, unless using gvim.
2017-04-27 22:39:58 +00:00
2019-12-31 05:37:09 +00:00
"//////////////////////////////
" SYNTAX HIGHLIGHTING
"//////////////////////////////
2017-04-27 22:39:58 +00:00
2019-12-31 05:37:09 +00:00
Plug 'tpope/vim-markdown' " Markdown
Plug 'octol/vim-cpp-enhanced-highlight' " C/C++
Plug 'vim-ruby/vim-ruby' " Ruby
Plug 'fatih/vim-go' " Go
Plug 'rust-lang/rust.vim' " Rust
Plug 'jdonaldson/vaxe' " Haxe
2020-09-29 19:43:08 +00:00
Plug 'pprovost/vim-ps1' " PowerShell
2020-10-09 15:54:01 +00:00
Plug 'fedorenchik/fasm.vim' " Flat Assembler
2019-12-31 05:37:09 +00:00
" Clojure -- Disabled since I'm not doing any Clojure work atm.
2018-06-11 17:39:04 +00:00
"Plug 'tpope/vim-classpath' " For Java
"Plug 'guns/vim-clojure-highlight'
"Plug 'guns/vim-clojure-static'
"Plug 'tpope/vim-fireplace', { 'for': 'clojure' }
2015-11-29 19:41:56 +00:00
2019-12-31 05:37:09 +00:00
"//////////////////////////////
2017-08-10 15:48:12 +00:00
2015-11-29 19:41:56 +00:00
call plug #end ( )
2015-03-21 19:13:17 +00:00
filetype plugin indent on
2015-02-24 04:34:00 +00:00
2019-12-31 05:37:09 +00:00
"---------------------------------------------------------------------------------------------------
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#2 BASE CONFIG
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2012-04-19 14:23:13 +00:00
" BASIC EDITING CONFIGURATION
2017-07-10 15:08:49 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2012-04-19 14:23:13 +00:00
set hidden
set history = 10000
set expandtab
2019-05-15 18:00:25 +00:00
set tabstop = 4
set shiftwidth = 4
set softtabstop = 4
2011-04-15 18:44:28 +00:00
set autoindent
2012-04-19 14:23:13 +00:00
set laststatus = 2
2019-12-31 05:37:09 +00:00
set showcmd " Display incomplete commands.
2012-04-19 14:23:13 +00:00
set showmatch
2019-12-31 05:37:09 +00:00
set incsearch " Highlight matches as you type.
set hlsearch " Highlight matches.
2013-04-20 18:00:26 +00:00
set dictionary + = /usr/ share /dict/ words
2019-12-31 05:37:09 +00:00
"set clipboard=unnamed " Yank and paste with the system clipboard.
2018-03-15 18:39:50 +00:00
set number
2019-12-31 05:37:09 +00:00
set ignorecase smartcase " Make searches case-sensitive only if they contain upper-case characters.
set visualbell " No bell sounds.
2017-07-28 15:20:08 +00:00
set ttyfast
2012-04-19 14:23:13 +00:00
set cmdheight = 2
2017-06-09 22:48:02 +00:00
set switchbuf = useopen , split
2012-04-19 14:23:13 +00:00
set numberwidth = 5
set showtabline = 2
set winwidth = 79
2016-04-11 00:59:36 +00:00
2020-06-10 15:40:12 +00:00
" Remove gvim Menubar and Toolbar
"set guioptions -=m
"set guioptions -=T
2019-12-31 05:37:09 +00:00
" @warning: This must come AFTER `set ignorecase smartcase` otherwise vim spews out a ton of errors. No idea why!
2016-04-11 00:59:36 +00:00
if IsWindows ( )
" Just assume we don't have a zsh shell
set shell = bash
else
2020-03-15 18:44:36 +00:00
"set shell=zsh
set shell = bash
2016-04-11 00:59:36 +00:00
endif
2019-12-31 05:37:09 +00:00
set t_ti = t_te = " Prevent Vim from clobbering the scrollback buffer. See http://www.shallowsky.com/linux/noaltscreen.html
set scrolloff = 3 " keep more context when scrolling off the end of a buffer
2019-07-17 16:00:31 +00:00
set cursorline
set cursorcolumn
2020-06-25 17:30:08 +00:00
" 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:
"
" set directory=<dir path for swap files>
" set backupdir=<dir path for backup files>
" if has('persistent_undo')
" set undodir=<dir path for undo files>
" endif
"
" And make sure those directories exist before opening vim.
2012-04-19 14:23:13 +00:00
set backup
2018-03-15 18:39:50 +00:00
set backupcopy = yes
2021-03-05 19:58:38 +00:00
augroup backupCmds
autocmd !
autocmd BufWritePre * let &bex = '.' . strftime ( "%Y-%m-%d-%T" ) . '.bak'
augroup END
2020-01-06 18:07:39 +00:00
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=<path>`
set undolevels = 1000 " Allow undo when going back into a closed file
set undoreload = 10000
if has ( 'persistent_undo' )
set undofile
endif
2017-07-17 16:38:17 +00:00
2019-12-31 05:37:09 +00:00
set backspace = indent , eol , start " Allow backspacing over everything in insert mode.
set complete + = kspell " Spell checking autocomplete.
set complete - = i " Don't scan all included files since it's really slow.
2019-03-28 00:15:55 +00:00
2020-07-25 20:38:58 +00:00
set termguicolors
2019-12-31 05:37:09 +00:00
syntax on " Enable highlighting for syntax
2019-03-28 00:15:55 +00:00
2013-08-30 17:11:59 +00:00
set wildmenu
set wildmode = longest , list , full
2019-03-28 00:15:55 +00:00
set wildignore + = */log/ *, *.so , *.swp , *.zip , */rdoc/ *
2019-05-15 18:00:25 +00:00
let &colorcolumn = s :max_line_length
2019-03-28 00:15:55 +00:00
2019-12-31 05:37:09 +00:00
set grepprg = rg \ - - vimgrep " Requires ripgrep to be installed.
2019-03-28 00:15:55 +00:00
2019-12-31 05:37:09 +00:00
set list listchars = tab :»·, trail :· " Show trailing whitespace.
2019-03-28 00:15:55 +00:00
2019-12-31 05:37:09 +00:00
set timeoutlen = 300 ttimeoutlen = 0 " Adding this since the esc remap on the 'i' key had a long delay when pressed.
2011-04-15 18:44:28 +00:00
2019-09-09 19:44:02 +00:00
" @fixme might be broken if lowered to 100 from original value of 4000. Will
" first try 500 and tweak from there.
2019-09-30 20:51:10 +00:00
" UPDATE: I lowered this to 250 and eventually started seeing some plugin
" errors related to paren formatting. I think 800 might be the sweet spot.
set updatetime = 800 " I lowered this to make git-gutter updates faster.
2019-12-31 05:37:09 +00:00
2013-05-01 13:48:08 +00:00
" Fix vim's background colour erase - http://snk.tuxfamily.org/log/vim-256color-bce.html
if &term = ~ '256color'
2019-12-31 05:37:09 +00:00
" Disable Background Color Erase (BCE) so that color schemes
" work properly when Vim is used inside tmux and GNU screen.
" See also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut =
2013-05-01 13:48:08 +00:00
endif
2019-12-31 05:37:09 +00:00
" Disable arrow keys.
2013-08-16 20:50:47 +00:00
map < up > < nop >
map < down > < nop >
map < left > < nop >
map < right > < nop >
imap < up > < nop >
imap < down > < nop >
imap < left > < nop >
imap < right > < nop >
2012-04-19 14:23:13 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2018-03-15 18:39:50 +00:00
2021-03-05 19:58:51 +00:00
" C/C++ template.
function ! s :CFileTemplate ( )
let s :env = {
\ 'filename' : expand ( '%:t' ) ,
\ 'creation_date' : strftime ( '%Y-%m-%d' ) ,
\ 'year' : strftime ( '%Y' ) ,
\ 'copyright_owner' : 'Jelly Pixel, Inc. All Rights Reserved.'
\}
let l :template = < < trim EOS
/*= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
File : ${filename }
Creation Date : ${creation_date }
Creator : Michael Campagnaro
Notice ! : ( C ) Copyright ${year } by ${copyright_owner }
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Defines
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Globals
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Structs
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Macros
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Private API
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
// # Public API
// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //
EOS
return map ( l :template , { _ , line - > substitute ( line , '${\(.\{-}\)}' , '\=get(s:env, submatch(1), submatch(1))' , 'g' ) } )
endfunction
function ! s :InsertCHeaderGates ( )
let l :gatename = substitute ( toupper ( expand ( "%:t" ) ) , "\\." , "_" , "g" )
call append ( 0 , '#ifndef ' . l :gatename )
call append ( line ( '$' ) , '#define ' . l :gatename )
call append ( line ( '$' ) , '#endif' )
endfunction
" sh template
function ! s :ShellScriptTemplate ( )
let l :template = < < trim EOS
#! /usr/ bin /env bash
if which tput > /dev/ null 2 > &1 ; then
ncolors = $( tput colors )
fi
if [ - t 1 ] && [ - n "$ncolors" ] && [ "$ncolors" - ge 8 ]; then
RED = "$(tput setaf 1)"
GREEN = "$(tput setaf 2)"
YELLOW = "$(tput setaf 3)"
BLUE = "$(tput setaf 4)"
MAGENTA = "$(tput setaf 5)"
CYAN = "$(tput setaf 6)"
BOLD = "$(tput bold)"
DIM = "\e[2m"
NORMAL = "$(tput sgr0)"
else
RED = ""
GREEN = ""
YELLOW = ""
BLUE = ""
MAGENTA = ""
CYAN = ""
BOLD = ""
NORMAL = ""
fi
error ( ) {
printf "${BOLD}${RED}$1${NORMAL}\n"
}
abort ( ) {
error "\nAborting..."
exit 1
}
set - e
cwd = $PWD
uname_s = "$(uname -s)"
case "${uname_s}" in
Linux *) machine = Linux ;;
Darwin *) machine = MacOS ;;
CYGWIN *) machine = Cygwin ;;
MINGW *) machine = MinGw ;;
*) machine = "UNKNOWN:${uname_s}"
esac
printf "${YELLOW}Platform: $machine${NORMAL}\n"
EOS
return l :template
endfunction
2017-07-26 16:06:00 +00:00
augroup campoCmds
2020-07-25 23:39:09 +00:00
" Clear all autocmds in the group.
autocmd !
" Automatically wrap at N characters.
autocmd FileType gitcommit setlocal colorcolumn = 72
2021-12-01 18:57:38 +00:00
autocmd BufRead , BufNewFile *.{md , txt , plan } exec "setlocal textwidth=" .s :max_line_length
2020-07-25 23:39:09 +00:00
" Spell checking.
autocmd FileType gitcommit , markdown , text setlocal spell
" Jump to last cursor position unless it's invalid or in an event handler.
autocmd BufReadPost * if line ( "'\"" ) > 1 && line ( "'\"" ) < = line ( "$" ) | exe "normal! g`\"" | endif
" Indent HTML <p> tags.
autocmd FileType html , eruby if g :html_indent_tags ! ~ '\\|p\>' | let g :html_indent_tags .= '\|p\|li\|dt\|dd' | endif
" Properly indent schemes (scheme, racket, etc).
2021-03-05 19:58:51 +00:00
autocmd BufRead , BufNewFile *.{lisp , scm , rkt } setlocal equalprg = scmindent .rkt
2020-07-25 23:39:09 +00:00
2020-10-09 15:54:01 +00:00
" Fasm indent; uses the fedorenchik/fasm.vim plugin.
autocmd BufReadPre *.asm let g :asmsyntax = "fasm"
2020-07-25 23:39:09 +00:00
" Auto reload VIM when settings changed.
2021-07-14 15:16:23 +00:00
" @fixme Reload lvimrc after sourcing this file on a save. I tried calling
" a function that does the source and a call to lvimrc's API but got an
" error complaining that the function cannot be created while it's in use.
autocmd BufWritePost .vimrc source $MYVIMRC
autocmd BufWritePost *.vim source $MYVIMRC
autocmd BufWritePost ~ /.vimrc .private source $MYVIMRC
2020-07-25 23:39:09 +00:00
function ! s :RunCtags ( )
" The ampersand at the end is to make this run in the background. I had to
" group the commands in parens to make the chained commands run in the
" background.
2021-12-01 18:57:38 +00:00
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 .") &"
silent ! exec l :ctags_cmd | redraw !
else
PrintError "ctags already running (found " .l :lock_file .")"
endif
2020-07-25 23:39:09 +00:00
endfun
2020-10-26 03:39:08 +00:00
2020-07-25 23:39:09 +00:00
" Generate ctags on save.
" Also Include local variables for C-like languages.
2021-03-05 19:58:51 +00:00
autocmd BufWritePost *.cs , *.js , *.py , *.c , *.cpp , *.h , *.asm silent ! call s :RunCtags ( )
2020-07-25 23:39:09 +00:00
" Remove trailing whitespace when saving any file.
function ! s :StripTrailingWhitespaces ( )
2021-07-15 15:55:29 +00:00
let l :filename = expand ( '%:t' )
if g :campo_strip_trailing_whitespace = = 1
if len ( g :campo_files_to_ignore_when_stripping_trailing_whitespace )
for ignore in g :campo_files_to_ignore_when_stripping_trailing_whitespace
if ignore = = l :filename
return
endif
endfor
endif
else
if len ( g :campo_files_to_force_stripping_trailing_whitespace )
let l :found_match = 0
for name in g :campo_files_to_force_stripping_trailing_whitespace
if name = = l :filename
let l :found_match = 1
break
endif
endfor
if l :found_match = = 0
2020-10-26 03:39:08 +00:00
return
endif
2021-12-01 18:58:20 +00:00
else
return
2021-07-15 15:55:29 +00:00
endif
2020-07-25 23:39:09 +00:00
endif
2020-10-26 03:39:08 +00:00
let l = line ( "." )
let c = col ( "." )
%s /\s\+$/ /e
call cursor ( l , c )
2020-07-25 23:39:09 +00:00
endfun
2021-03-05 19:58:51 +00:00
autocmd BufWritePre * call s :StripTrailingWhitespaces ( )
2020-07-25 23:39:09 +00:00
"////////////////////////////////////////////////////////////////
" FILE TEMPLATES
"////////////////////////////////////////////////////////////////
" Shell script template.
2021-03-05 19:58:51 +00:00
autocmd BufNewFile *.sh call append ( 0 , s :ShellScriptTemplate ( ) )
" C/C++ file.
autocmd BufNewFile *.{c , cc , cpp , h , hpp } call append ( 0 , s :CFileTemplate ( ) )
autocmd BufNewFile *.{h , hpp } call s :InsertCHeaderGates ( )
2017-07-26 16:06:00 +00:00
augroup END
2015-03-21 19:13:17 +00:00
2012-04-19 14:23:13 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC KEY MAPS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2019-12-31 05:37:09 +00:00
" Mapping ESC in insert mode and command mode to double i.
2018-06-11 17:39:04 +00:00
imap jj < Esc >
"cmap ii <Esc>
2011-04-15 18:44:28 +00:00
2019-12-31 05:37:09 +00:00
" Suspend vim process and return to the shell. Can return to vim with `fg`.
2012-11-17 02:52:40 +00:00
nmap < leader > z < c - z >
2012-11-16 05:14:27 +00:00
2019-12-31 05:37:09 +00:00
" Open the vimrc file for editing / reload vimrc file.
2013-07-10 16:13:13 +00:00
nmap < silent > < leader > ev :vsp $MYVIMRC < cr >
2020-06-10 15:40:12 +00:00
nmap < silent > < leader > pv :vsp ~ /.vimrc .private < cr >
2021-07-14 15:16:23 +00:00
nmap < silent > < leader > rv :source $MYVIMRC < cr >
2012-11-16 05:14:27 +00:00
2019-12-31 05:37:09 +00:00
" Type %/ in the command bar to have it replaced with the current buffer's
" path if the file is on disk. One thing I noticed is that you have to type
" the full %/ quickly otherwise it won't replace it.
2017-10-10 23:50:00 +00:00
: cmap %/ %:p:h/
2019-12-31 05:37:09 +00:00
" Remap saving and quiting.
2019-03-28 00:15:55 +00:00
nmap < leader > w :w ! < cr >
2012-11-16 05:14:27 +00:00
nmap < leader > q :q < cr >
2015-10-16 05:10:05 +00:00
nmap < leader > qq :q ! < cr >
2012-11-16 05:14:27 +00:00
nmap < leader > x :x < cr >
2019-03-28 00:15:55 +00:00
: ca Wa wa !
: ca WA wa !
2012-11-16 05:14:27 +00:00
: ca WQ wq
: ca Wq wq
2019-03-28 00:15:55 +00:00
: ca W w !
2012-11-16 05:14:27 +00:00
: ca Q q
2019-12-31 05:37:09 +00:00
" Lowercase the e (have a habit of making it uppercase).
2017-07-13 20:03:28 +00:00
: ca E e
2013-07-10 16:13:13 +00:00
command ! Q q " Bind :Q to :q
command ! Qall qall
2018-06-11 17:39:04 +00:00
command ! Qa qall
2019-12-31 05:37:09 +00:00
" Disable Ex mode.
2013-07-10 16:13:13 +00:00
map Q < Nop >
2019-12-31 05:37:09 +00:00
" Open a terminal within vim. Use `exit` to close it.
2015-12-02 15:21:05 +00:00
if exists ( ':terminal' )
2020-07-25 23:39:09 +00:00
map < leader > t :terminal < cr >
tnoremap < leader > e < C - \> < C - n >
tnoremap < A - h > < C - \> < C - n > < C - w > h
tnoremap < A - j > < C - \> < C - n > < C - w > j
tnoremap < A - k > < C - \> < C - n > < C - w > k
tnoremap < A - l > < C - \> < C - n > < C - w > l
nnoremap < A - h > < C - w > h
nnoremap < A - j > < C - w > j
nnoremap < A - k > < C - w > k
nnoremap < A - l > < C - w > l
2015-12-02 15:21:05 +00:00
endif
2015-11-29 23:25:02 +00:00
2019-12-31 05:37:09 +00:00
" Jump to other buffers.
2012-11-16 06:05:17 +00:00
map < c - k > < c - w > < Up >
map < c - j > < c - w > < Down >
map < c - l > < c - w > < Right >
map < c - h > < c - w > < Left >
2015-11-29 23:25:02 +00:00
" Make it easier to jump around the command line. The default behaviour is
2019-12-31 05:37:09 +00:00
" using the arrow keys with or without shift.
2015-11-29 23:25:02 +00:00
: cnoremap < C - J > < S - Left >
: cnoremap < C - K > < S - Right >
2015-11-29 21:57:35 +00:00
2013-04-20 18:00:26 +00:00
" Window splitting - couldn't figure out how to remap <c-w>v & <c-w>n to <c-m>
" & <c-n>
map < leader > m :vsplit < cr >
map < leader > mm :split < cr >
2019-12-31 05:37:09 +00:00
" Forward delete and replace a word.
2016-08-06 14:16:10 +00:00
map < leader > d ciw
2020-02-03 23:03:31 +00:00
" Allow fast pasting by accessing the system clipboard register.
map < leader > p "+p
" Likely won't need to use this if pasting with <leader>p, but just in case
" here ya go.
map < leader > pp :set paste ! paste ?< cr >
2014-02-17 07:00:21 +00:00
map < leader > o :set number ! number ?< cr >
2019-12-31 05:37:09 +00:00
" Show spell checking.
" @note: you can add new entries to the dict by moving the cursor over the
" word and pressing `zg`.
2016-08-06 14:16:10 +00:00
map < leader > j :exec &spell = = &spell ? "se spell! spelllang=en_us" : "se spell!" < cr >
2015-10-16 05:10:05 +00:00
map < leader > = z =
2015-02-28 19:28:13 +00:00
2019-12-31 05:37:09 +00:00
" Clear the search buffer (highlighting) when hitting return.
2012-11-04 23:22:31 +00:00
function ! MapCR ( )
2020-07-25 23:39:09 +00:00
nnoremap < cr > :nohlsearch < cr >
2012-11-04 23:22:31 +00:00
endfunction
call MapCR ( )
2012-04-19 14:23:13 +00:00
nnoremap < leader > < leader > < c - ^>
2011-04-15 18:44:28 +00:00
2019-12-31 05:37:09 +00:00
" Replace currently selected text with default register without yanking it.
2016-08-06 14:16:10 +00:00
vnoremap p "_dP
2019-12-31 05:37:09 +00:00
" Switch between C++ source and header files.
2018-03-15 18:39:50 +00:00
map < leader > v :e %:p :s , .h $, .X123X , :s , .cpp $, .h , :s , .X123X $, .cpp , < CR >
"map <leader>vv :e %:p:s,.h$,.X123X,:s,.c$,.h,:s,.X123X$,.c,<CR>
"map <leader>vvv :e %:p:s,.h$,.X123X,:s,.cc$,.h,:s,.X123X$,.cc,<CR>
2017-06-16 20:16:34 +00:00
2019-04-02 15:57:52 +00:00
" Replace all instances of the highlighted text with whatever you enter.
2019-04-27 15:42:58 +00:00
nnoremap < c - g > :%s // /g < left > < left >
2019-04-02 15:57:52 +00:00
2017-07-13 20:03:28 +00:00
"////////////////////////////////////////////////////////////////
" QUICKLY OPEN C++ SOURCE OR HEADER FILE
"////////////////////////////////////////////////////////////////
function ! s :CompleteFilenameWithoutExtension ( ArgLead , CmdLine , CursorPos )
2020-07-25 23:39:09 +00:00
" Returns a matching filename without the period that separates the name
" from the extension.
let l :file = substitute ( glob ( a :ArgLead .'*' , 0 , 0 ) , "[\.].*" , "" , "*" )
return l :file
2017-07-13 20:03:28 +00:00
endfunction
" Custom command to open cpp and h files without typing an extension
2021-12-01 18:59:03 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSource exec ':e <args>.cpp'
2019-03-28 01:35:59 +00:00
":ca c OpenCppSource
":ca C OpenCppSource
2017-07-13 20:03:28 +00:00
2021-12-01 18:59:03 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppHeader exec ':e <args>.h'
2019-03-28 00:15:55 +00:00
":ca h OpenCppHeader
":ca H OpenCppHeader
2017-07-13 20:03:28 +00:00
2021-12-01 18:59:03 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension "OpenCppSourceAndHeader exec ':vsp | :e <args>.h | :sp <args>.cpp'
2019-03-28 01:35:59 +00:00
":ca b OpenCppSourceAndHeader
":ca B OpenCppSourceAndHeader
2017-07-13 20:03:28 +00:00
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
2012-04-19 14:23:13 +00:00
" MULTIPURPOSE TAB KEY
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
2012-04-19 14:23:13 +00:00
function ! InsertTabWrapper ( )
2016-08-03 04:28:39 +00:00
let l :col = col ( '.' ) - 1
if ! l :col | | getline ( '.' ) [l :col - 1 ] ! ~ '\k'
2012-04-19 14:23:13 +00:00
return "\<tab>"
else
return "\<c-p>"
2011-04-15 18:44:28 +00:00
endif
2012-04-19 14:23:13 +00:00
endfunction
inoremap < tab > < c - r > = InsertTabWrapper ( ) < cr >
inoremap < s - tab > < c - n >
2019-12-31 05:37:09 +00:00
"---------------------------------------------------------------------------------------------------
2012-04-19 14:23:13 +00:00
2013-08-16 20:50:47 +00:00
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#3 PLUGIN CONFIGS
2017-07-18 15:21:03 +00:00
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LOCAL VIMRC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g :localvimrc_sandbox = 0
let g :localvimrc_ask = 0
2017-08-10 15:48:12 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TAGBAR
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2017-09-22 21:16:30 +00:00
noremap < F12 > :TagbarToggle < cr >
2017-08-10 15:48:12 +00:00
2019-12-31 05:37:09 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" KANGAROO
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap < leader > a zp
nmap < leader > aa zP
2017-11-15 16:30:09 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2018-06-11 17:39:04 +00:00
" GITGUTTER
2017-11-15 16:30:09 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2019-12-31 05:37:09 +00:00
let g :gitgutter_enabled = 1
let g :gitgutter_highlight_lines = 0
2018-10-05 17:38:00 +00:00
nmap < leader > ha < Plug > GitGutterStageHunk
2019-12-31 05:37:09 +00:00
nmap < leader > hh :GitGutterToggle < cr >
2018-06-11 17:39:04 +00:00
nmap [h < Plug > GitGutterNextHunk
nmap ]h < Plug > GitGutterPrevHunk
2021-03-05 19:58:38 +00:00
augroup gitGutterPluginCmds
autocmd !
" Update marks on save
autocmd BufWritePost * GitGutter
augroup END
2017-11-15 16:30:09 +00:00
2017-07-18 15:21:03 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SYNTASTIC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NOTE: there is a status line config in the status line section
let g :syntastic_always_populate_loc_list = 1
let g :syntastic_auto_loc_list = 1
let g :syntastic_check_on_open = 0
let g :syntastic_check_on_wq = 0
" Customize Rust
" https://github.com/rust-lang/rust.vim/issues/130
" Can remove once this Syntastic PR is merged https://github.com/rust-lang/rust.vim/pull/132
"let g:syntastic_rust_rustc_exe = 'cargo check'
"let g:syntastic_rust_rustc_fname = ''
"let g:syntastic_rust_checkers = ['rustc']
2019-03-28 00:15:55 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RIPGREP
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g :rg_highlight = 1
2021-10-14 18:20:40 +00:00
let g :rg_window_height = g :quickfix_pane_height
2017-07-18 15:21:03 +00:00
2019-03-28 01:35:59 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTRL-P
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" keybindings:
"
" leader-f = open CtrlP in tag searching mode.
" leader-g = open CtrlP in file searching mode.
" ctrl-f = toggle search mode
" enter = open result in a current buffer or in an already open buffer for that file.
" ctrl-v = open result in a vertically-split buffer.
" ctrl-h = open result in a horizontally-split buffer.
" ctrl-t = open result in a new tab.
" ctrl-j | ctrl-k = move up and down the search results.
" ctrl-y = create file and open it.
" ctrl-z = mark multiple file search results to open (I think you can only use ctrl-v or ctrl-x and not enter).
" ctrl-o = ask how to open a file search result.
" ctrl-o = ask how to open a file search result.
" ctrl-p | ctrl-n = traverse search history.
map < leader > g :CtrlP < cr >
let g :ctrlp_map = '<leader>f'
let g :ctrlp_cmd = 'CtrlPTag' " Search tags by default.
let g :ctrlp_by_filename = 1 " File search by filename as opposed to full path.
2021-10-14 18:20:40 +00:00
let g :ctrlp_match_window = 'bottom,order:ttb,min:10,max:' .g :quickfix_pane_height .',results:' .g :quickfix_pane_height
let g :ctrlp_use_caching = 1
2019-03-28 01:35:59 +00:00
let g :ctrlp_clear_cache_on_exit = 1 " No need to keep cache for now since I mostly work in git repos. Press F5 inside CtrlP to rebuild the cache.
2021-10-14 18:20:40 +00:00
let g :ctrlp_working_path_mode = 'ra' " Search from nearest ancestor of the current file that contains .git OR directory of the current file unless it's a subdirectory of the cwd
let g :ctrlp_switch_buffer = 'et' " If a file is already open, open it again in a new pane instead of switching to the existing pane
let g :ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g :ctrlp_user_command = ['.git' , 'cd %s && git ls-files -co --exclude-standard' ] " If a git repo, use checked in files (ignore things in .gitignore); fallback to globpath()
2019-03-28 01:35:59 +00:00
" @fixme Not sure why I can't get these new mappings (c-m, c-cr) to register...
"let g:ctrlp_prompt_mappings = {
" \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>'],
" \ 'AcceptSelection("v")': ['<c-v>', '<c-m>'],
" \ }
2017-07-18 15:21:03 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIT
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2021-02-08 20:40:32 +00:00
2021-10-22 00:06:44 +00:00
map < leader > gb :Git blame - w < cr >
2018-03-15 18:39:50 +00:00
" Ignore whitespace changes; follow renames and copies.
2021-10-22 00:06:44 +00:00
command ! - bar - bang - nargs = * Blame :Git blame < bang > - wCM < args >
command ! - bar - bang - nargs = * Gblame :Git blame < bang > - wCM < args >
2017-07-18 15:21:03 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIST VIM
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g :gist_detect_filetype = 1
let g :gist_open_browser_after_post = 1
let g :gist_show_privates = 1
let g :gist_post_private = 1
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" VIM-CLOJURE-STATIC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Default
let g :clojure_fuzzy_indent = 1
let g :clojure_align_multiline_strings = 1
let g :clojure_fuzzy_indent_patterns = ['^match' , '^with' , '^def' , '^let' ]
let g :clojure_fuzzy_indent_blacklist = ['-fn$' , '\v^with-%(meta|out-str|loading-context)$' ]
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RUST.VIM
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"let g:rustfmt_autosave = 1 " auto run rust formatter when saving
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RAINBOW
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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' ]
function ! UpdateRainbowConf ( )
2020-07-25 23:39:09 +00:00
let g :rainbow_conf = {
2017-07-18 15:21:03 +00:00
\ 'ctermfgs' : ( s :rainbow_theme = = "light" ? s :dark_rainbow : s :light_rainbow )
2020-07-25 23:39:09 +00:00
\}
2017-07-18 15:21:03 +00:00
"\ 'separately': {
"\ '*': 0, " Disable all
"\ 'c++': {} " Only enable c++
"\ }
endfunction
call UpdateRainbowConf ( )
function ! ReloadRainbow ( )
2020-07-25 23:39:09 +00:00
if g :campo_theme_use_rainbow_parens
if exists ( ':RainbowToggle' )
call UpdateRainbowConf ( )
call rainbow #clear ( ) | call rainbow #hook ( )
endif
else
let g :rainbow_active = 0
if exists ( ':RainbowToggle' )
call UpdateRainbowConf ( )
call rainbow #clear ( )
endif
2017-10-29 20:35:44 +00:00
endif
2017-07-18 15:21:03 +00:00
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" C-TAGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tags + = tags ;$HOME
2019-12-31 05:37:09 +00:00
"---------------------------------------------------------------------------------------------------
2017-07-18 15:21:03 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#4 VISUALS
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LAYOUT
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2017-07-10 15:11:32 +00:00
"////////////////////////////////////////////////////////////////
" CENTER THE BUFFER
"////////////////////////////////////////////////////////////////
2020-07-25 23:39:09 +00:00
function ! CenterPane ( )
" centers the current pane as the middle 2 of 4 imaginary columns
" should be called in a window with a single pane
" Taken from https://dev.to/vinneycavallo/easily-center-content-in-vim
lefta vnew
wincmd w
exec 'vertical resize ' . string ( &columns * 0 .75 )
endfunction
2017-07-10 15:11:32 +00:00
nnoremap < leader > c :call CenterPane ( ) < cr >
function ! RemoveCenterPane ( )
2020-07-25 23:39:09 +00:00
wincmd w
close
2017-07-10 15:11:32 +00:00
endfunction
nnoremap < leader > cw :call RemoveCenterPane ( ) < cr >
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" TEXT ALIGNMENT PLUGIN
"////////////////////////////////////////////////////////////////
let b :lion_squeeze_spaces = 1
2017-07-10 15:11:32 +00:00
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" STATUS LINE
"////////////////////////////////////////////////////////////////
set statusline = %< %f \ ( %{&ft }) \ %-4 ( %m %) %= %-19 ( %3 l, %02 c%03 V%)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLORS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2017-10-29 20:35:44 +00:00
2021-12-01 18:59:03 +00:00
exec "autocmd ColorScheme " . g :campo_dark_theme . " call ReloadRainbow()"
exec "autocmd ColorScheme " . g :campo_light_theme . " call ReloadRainbow()"
2017-07-18 15:21:03 +00:00
2020-01-06 18:07:39 +00:00
" Switch between light and dark themes.
2017-07-10 15:08:49 +00:00
map < leader > l :call ChangeBgTheme ( 'light' , 0 ) < cr >
map < leader > ll :call ChangeBgTheme ( 'dark' , 0 ) < cr >
function ! ChangeBgTheme ( bg , onlySetTheme )
2020-07-25 23:39:09 +00:00
if a :bg = ~ 'light'
let s :rainbow_theme = 'light'
let s :theme = g :campo_light_theme
exe 'colorscheme ' . s :theme
set background = light
else
let s :rainbow_theme = 'dark'
let s :theme = g :campo_dark_theme
" We have to set the theme twice in order to get its correct dark-theme colors.
" Weird stuff.
exe 'colorscheme ' . s :theme
set background = dark
exe 'colorscheme ' . s :theme
endif
if ! a :onlySetTheme
exec ':AirlineTheme ' . a :bg
endif
2017-07-10 15:08:49 +00:00
endfunction
if s :default_bg = ~ 'light'
call ChangeBgTheme ( 'light' , 1 )
else
call ChangeBgTheme ( 'dark' , 1 )
endif
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" HIGHLIGHTS - TODO, NOTE, FIXME, etc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" NOTE: These depend on custom color names (Bugs, Notes and Notices) defined
" in the campo color themes. Since most themes won't define these, you can
" use WildMenu as substitution.
"
" FIXME: the custom Bugs, Notes and Notices highlighting for campo-light isn't
" working...
augroup vimrc_bugs
2021-03-05 19:58:38 +00:00
autocmd !
autocmd Syntax * syn match MyBugs /\v<(FIXME|BUG|DEPRECATED):/
2017-07-10 15:08:49 +00:00
\ containedin = .*Comment , vimCommentTitle
augroup END
hi def link MyBugs Bugs
augroup vimrc_notes
2021-03-05 19:58:38 +00:00
autocmd !
autocmd Syntax * syn match MyNotes /\v<(IDEA|NOTE|QUESTION|WARNING|IMPORTANT):/
2017-07-10 15:08:49 +00:00
\ containedin = .*Comment , vimCommentTitle
augroup END
hi def link MyNotes Notes
augroup vimrc_notices
au !
2021-03-05 19:58:38 +00:00
autocmd Syntax * syn match MyNotices /\v<(WARNING|IMPORTANT):/
2017-07-10 15:08:49 +00:00
\ containedin = .*Comment , vimCommentTitle
augroup END
hi def link MyNotices Notices
2017-11-15 16:30:09 +00:00
augroup vimrc_annotated_todo
2021-03-05 19:58:38 +00:00
autocmd !
2017-11-15 16:30:09 +00:00
" This was a major pain in the ass to get working...
2021-03-05 19:58:38 +00:00
autocmd Syntax * syn match cTodo /@\S\+/
2017-11-15 16:30:09 +00:00
\ containedin = .*Comment , vimCommentTitle
augroup END
augroup vimrc_annotated_notes
2021-03-05 19:58:38 +00:00
autocmd !
autocmd Syntax * syn match cTodo /#\+ .\+$/
2017-11-15 16:30:09 +00:00
\ containedin = .*Comment , vimCommentTitle
augroup END
2017-07-10 15:08:49 +00:00
2019-12-31 05:37:09 +00:00
"---------------------------------------------------------------------------------------------------
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#5 CUSTOM FUNCTIONS / COMMANDS
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
function ! PrintError ( msg ) abort
2021-12-01 18:59:03 +00:00
exec 'normal! \<Esc>'
2021-02-08 20:40:32 +00:00
echohl ErrorMsg
echomsg a :msg
echohl None
endfunction
2017-07-10 15:08:49 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" BUILD COMMANDS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" AsyncRun status line
let g :airline_section_error = airline #section #create_right ( ['%{g:asyncrun_status}' ])
" Display error highlighting in source after running GCC with AsyncRun
" NOTE: error results can be cleared with <leader>cr or by hiding the build
" result window.
let g :asyncrun_auto = "make"
let errormarker_errortext = "E"
let errormarker_warningtext = "W"
" Thanks to https://forums.handmadehero.org/index.php/forum?view=topic&catid=4&id=704#3982
" for the error message formats
2021-02-08 20:40:32 +00:00
"
2017-07-10 15:08:49 +00:00
" Microsoft MSBuild errors
set errorformat + = \\\ %#%f ( %l \\\, %c ) :\ %m
" Microsoft compiler: cl.exe
set errorformat + = \\\ %#%f ( %l ) \ :\ %#%t %[A - z ]%#\ %m
" Microsoft HLSL compiler: fxc.exe
set errorformat + = \\\ %#%f ( %l \\\, %c - %*[0 -9 ]) :\ %#%t %[A - z ]%#\ %m
function ! HideBuildResultsAndClearErrors ( )
2020-07-25 23:39:09 +00:00
RemoveErrorMarkers
2021-10-14 18:20:40 +00:00
call asyncrun #quickfix_toggle ( g :quickfix_pane_height , 0 )
2017-07-10 15:08:49 +00:00
endfunction
2017-08-21 18:26:22 +00:00
function ! HideAsyncResults ( )
2021-10-14 18:20:40 +00:00
call asyncrun #quickfix_toggle ( g :quickfix_pane_height , 0 )
2017-08-21 18:26:22 +00:00
endfunction
2017-07-10 15:08:49 +00:00
function ! ToggleBuildResults ( )
2021-10-14 18:20:40 +00:00
call asyncrun #quickfix_toggle ( g :quickfix_pane_height )
2017-07-10 15:08:49 +00:00
endfunction
function ! StopRunTask ( )
2020-07-25 23:39:09 +00:00
AsyncStop
call HideAsyncResults ( )
2017-07-10 15:08:49 +00:00
endfunction
function ! ExecuteRunScript ( )
2020-07-25 23:39:09 +00:00
exec "AsyncRun! -post=call\\ StopRunTask() ./run %"
2017-07-10 15:08:49 +00:00
endfunction
2017-08-21 18:26:22 +00:00
function ! SilentBuild ( )
2020-07-25 23:39:09 +00:00
AsyncStop
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build* %"
2017-08-21 18:26:22 +00:00
endfunction
2017-07-10 15:08:49 +00:00
" Show results window the moment the async job starts
2021-03-05 19:58:38 +00:00
augroup asyncPluginCmds
autocmd !
2021-10-14 18:20:40 +00:00
autocmd User AsyncRunStart call asyncrun #quickfix_toggle ( g :quickfix_pane_height , 1 )
2017-07-10 15:08:49 +00:00
augroup END
" Toggle build results
2017-09-22 21:16:30 +00:00
noremap < F11 > :call ToggleBuildResults ( ) < cr >
2017-10-25 15:01:42 +00:00
nnoremap < leader > bc :call ToggleBuildResults ( ) < cr >
2017-07-10 15:08:49 +00:00
" Hide build results and clear errors
noremap < F10 > :call HideBuildResultsAndClearErrors ( ) < cr >
" Execute build script
2020-05-04 17:35:53 +00:00
nnoremap < leader > b :AsyncRun ! - save = 2 ./build * %< cr >
2017-08-21 18:26:22 +00:00
nnoremap < F8 > :call SilentBuild ( ) < cr >
2017-07-10 15:08:49 +00:00
" Execute run script
nnoremap < leader > br :call ExecuteRunScript ( ) < cr >
2017-09-22 21:16:30 +00:00
nnoremap < F9 > :call ExecuteRunScript ( ) < cr >
2017-07-10 15:08:49 +00:00
nnoremap < leader > bs :AsyncStop < cr >
"Go to next build error
nnoremap < F7 > :cn < CR >
nnoremap < C - n > :cn < CR >
2015-03-21 19:13:17 +00:00
2017-07-10 15:08:49 +00:00
"Go to previous build error
nnoremap < F6 > :cp < CR >
nnoremap < C - p > :cp < CR >
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2019-09-09 19:31:47 +00:00
" SEARCH
2017-07-10 15:08:49 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2019-03-28 00:15:55 +00:00
2020-01-08 15:54:01 +00:00
" Search using ripgrep (first install with Rust: cargo install ripgrep).
2021-07-14 15:16:23 +00:00
function ! Search ( case_sensitive , search_args )
let l :helper = "Search [" . a :search_args . " | " . ( a :case_sensitive ? "case-sensitive" : "case-insensitive" ) . "]: "
2020-07-25 23:39:09 +00:00
let l :term = input ( l :helper )
if empty ( l :term )
return
endif
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
"quickfix window doesn't seem to parse the ansi color codes.
2021-07-14 15:16:23 +00:00
let l :rg_args = "--column --line-number --no-heading --fixed-strings --no-ignore --hidden --follow --trim -g \"!tags\" " . a :search_args
2020-07-25 23:39:09 +00:00
if ! a :case_sensitive
let l :rg_args .= " --ignore-case"
endif
exec 'Rg ' . l :rg_args . ' "' . l :term . '"'
2019-09-09 19:31:47 +00:00
endfunction
2021-07-14 15:16:23 +00:00
" Case insensitive
map < leader > s :call Search ( 0 , g :campo_custom_search_args ) < cr >
noremap < F2 > :call Search ( 0 , g :campo_custom_search_args_2 ) < cr >
" Case sensitive
map < leader > ss :call Search ( 1 , g :campo_custom_search_args ) < cr >
noremap < F3 > :call Search ( 1 , g :campo_custom_search_args_2 ) < cr >
2019-09-09 19:31:47 +00:00
" Navigation for the vim-ripgrep search results.
" Hit o on a result line to open the file at that line.
" Hit p on a result line to open the file at that line and return to the results pane.
nnoremap < expr > o ( &buftype is # "quickfix" ? "<CR>\|:lopen<CR>" : "o" )
nnoremap < expr > p ( &buftype is # "quickfix" ? "<CR>\|:copen<CR>" : "p" )
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SEARCH & REPLACE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2021-12-01 18:59:03 +00:00
" argdo wrapper that will disable all events for read/save. This significantly
" speeds up GlobalReplaceIt().
command ! - nargs = ? Argdo call Argdo ( < q - args > )
function ! Argdo ( command )
set eventignore = all
exec 'noautocmd argdo ' . a :command . ' | update'
set eventignore =
endfunction
2019-09-09 19:31:47 +00:00
" Replace the selected text in all files within the repo.
2017-07-10 15:08:49 +00:00
function ! GlobalReplaceIt ( confirm_replacement )
2020-07-25 23:39:09 +00:00
if exists ( ':Ggrep' )
call inputsave ( )
if a :confirm_replacement
let l :term = input ( 'Enter search term (w/ confirmation): ' )
else
let l :term = input ( 'Enter search term (no confirmation): ' )
endif
call inputrestore ( )
if empty ( l :term )
return
endif
call inputsave ( )
let l :replacement = input ( 'Enter replacement: ' )
call inputrestore ( )
if empty ( l :replacement )
return
endif
if a :confirm_replacement
let l :confirm_opt = 'c'
else
let l :confirm_opt = 'e'
endif
2021-12-01 18:59:03 +00:00
exec 'Ggrep ' .l :term
exec 'Qargs | Argdo %s/' .l :term .'/' .l :replacement .'/g' .l :confirm_opt
" Regen ctags.
call s :RunCtags ( )
2017-07-10 15:08:49 +00:00
else
2021-02-08 20:40:32 +00:00
PrintError "Unable to search since you're not in a git repo!"
2017-07-10 15:08:49 +00:00
endif
endfunction
2020-04-20 16:41:58 +00:00
map < leader > r :call GlobalReplaceIt ( 0 ) < cr >
map < leader > rr :call GlobalReplaceIt ( 1 ) < cr >
2017-07-10 15:08:49 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function ! RenameFile ( )
let l :old_name = expand ( '%' )
let l :new_name = input ( 'New file name: ' , expand ( '%' ) , 'file' )
if l :new_name ! = '' && l :new_name ! = l :old_name
exec ':saveas ' . l :new_name
exec ':silent !rm ' . l :old_name
redraw !
endif
endfunction
map < leader > n :call RenameFile ( ) < cr >
2015-03-21 19:13:17 +00:00
2019-12-31 05:37:09 +00:00
"---------------------------------------------------------------------------------------------------
2015-03-21 19:13:17 +00:00
2017-03-02 15:37:55 +00:00
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
2021-02-08 20:40:32 +00:00
"#6 PERSONAL
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FILE MAPPINGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Notes and other helpers
2019-12-31 05:37:09 +00:00
map < leader > pn :sp ~ /.dev - scratchpad .md < cr >
2017-07-10 15:08:49 +00:00
2018-06-11 17:39:04 +00:00
"let g:autotagStopAt = "$HOME"
2020-10-26 03:39:08 +00:00