dotfiles/vimrc

1064 lines
34 KiB
VimL
Raw Normal View History

"Remove Menubar and Toolbar from gvim
"set guioptions -=m
"set guioptions -=T
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
" 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"
function! IsWindows()
if s:uname =~ "mingw"
return 1
endif
return 0
endfunction
let mapleader=","
"################################################################
"################################################################
"################################################################
" 0. GLOBALS
"################################################################
"################################################################
"################################################################
2019-05-15 18:00:25 +00:00
let s:max_line_length = 100
let s:default_bg = 'dark'
let s:rainbow_theme = s:default_bg
2019-05-15 18:00:25 +00:00
let g:quickfix_window_height = 16 " in rows
2017-07-10 15:08:49 +00:00
"-----------------------------------------------------------------------------------------
"################################################################
"################################################################
"################################################################
" 1. PLUGINS
"################################################################
"################################################################
"################################################################
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
2015-11-29 19:41:56 +00:00
Plug 'bling/vim-airline'
Plug 'vim-scripts/AnsiEsc.vim'
2019-05-15 18:00:25 +00:00
Plug 'embear/vim-localvimrc' " Add a .lvimrc to a folder to override .vimrc config.
Plug 'tpope/vim-obsession' " Continuously updated session files
Plug 'tpope/vim-fugitive' " Git wrapper
Plug 'junegunn/goyo.vim' " Distraction-free mode with centered buffer
Plug 'sir-pinecone/vim-ripgrep' " Wrapper around ripgrep (must intall ripgrep first; use Rust: cargo install ripgrep)
Plug 'itchyny/vim-cursorword' " Underlines the word under the cursor
Plug 'airblade/vim-gitgutter' " See git diff in the gutter and stage/unstage hunks.
Plug 'ctrlpvim/ctrlp.vim' " Fuzzy file, buffer, mru, tag, etc finder
2018-06-11 17:39:04 +00:00
2019-03-28 00:15:55 +00:00
if IsWindows()
Plug 'suxpert/vimcaps' " Disable capslock (useful if the OS isn't configured to do so)
else
2017-11-15 16:30:09 +00:00
Plug 'Shougo/vimproc.vim', {'do' : 'make'}
Plug 'itchyny/dictionary.vim' " A way to query dictionary.com with :Dictionary
2019-03-28 00:15:55 +00:00
" Fuzzy search
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
2017-11-15 16:30:09 +00:00
endif
2017-06-16 20:51:40 +00:00
Plug 'majutsushi/tagbar'
Plug 'jeetsukumaran/vim-filesearch'
2015-11-29 19:41:56 +00:00
Plug 'rking/ag.vim'
2017-06-16 20:16:34 +00:00
Plug 'nelstrom/vim-qargs' " For search and replace
Plug 'tommcdo/vim-lion' " For text alignment, use gl= and gL=
2017-06-09 22:48:02 +00:00
2017-06-16 20:51:49 +00:00
" Easily search for, substitute, and abbreviate multiple variants of a word
Plug 'tpope/tpope-vim-abolish'
2017-06-16 20:28:10 +00:00
" Maintain a manually-defined jump stack. Set with zp and pop with zP
Plug 'tommcdo/vim-kangaroo'
2017-06-09 22:48:02 +00:00
" Async commands + build error highlighting
Plug 'skywind3000/asyncrun.vim'
Plug 'mh21/errormarker.vim'
2019-03-28 00:15:55 +00:00
"///////////////////
" MAYBE SOME DAY
"///////////////////
2019-03-28 01:35:59 +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
2015-03-24 21:55:35 +00:00
2019-03-28 00:15:55 +00:00
"///////////////////
" DISABLED
"///////////////////
" I don't think I need this anymore...
"Plug 'craigemery/vim-autotag' " Automatically discover and 'properly' update ctags files on save
" Doesn't do anything on my Windows desktop...
"Plug 'ervandew/supertab' " For autocompletion
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" COLORS
"////////////////////////////////////////////////////////////////
2017-04-27 22:39:58 +00:00
Plug 'godlygeek/csapprox' " Try to make gvim themes look decent in Windows
Plug 'sir-pinecone/rainbow'
2017-04-27 22:39:58 +00:00
" WARNING: Has a lot of themes, but they break the other themes listed below
"Plug 'flazz/vim-colorschemes'
2015-11-29 19:41:56 +00:00
Plug 'elixir-lang/vim-elixir'
2017-04-27 20:22:32 +00:00
Plug 'vim-airline/vim-airline-themes'
2015-03-24 21:55:35 +00:00
2017-04-27 22:39:58 +00:00
" Light Themes
Plug 'raggi/vim-color-raggi' " No Win support, unless using gvim
Plug 'LanFly/vim-colors' " No Win support, unless using gvim
" Dark Themes
Plug 'rhysd/vim-color-spring-night' " No Win support, unless using gvim
Plug 'nanotech/jellybeans.vim'
Plug 'zcodes/vim-colors-basic'
" Hybrid Themes
Plug 'sickill/vim-monokai'
Plug 'chmllr/elrodeo-vim-colorscheme' " A little dark on Windows, term
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)
Plug 'nightsense/seabird' " No Win support, unless using gvim
2017-04-27 22:39:58 +00:00
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" CLOJURE
"////////////////////////////////////////////////////////////////
2018-06-11 17:39:04 +00:00
" Temporarily disabled since I'm not doing any Clojure work atm.
"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
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" OTHER LANGUAGES
"////////////////////////////////////////////////////////////////
2017-03-02 15:37:55 +00:00
" Rust
Plug 'rust-lang/rust.vim'
2017-04-27 22:39:58 +00:00
" Ruby
Plug 'vim-ruby/vim-ruby'
2017-04-27 20:23:26 +00:00
" Go
Plug 'fatih/vim-go'
2017-03-21 13:42:04 +00:00
" QML
Plug 'peterhoeg/vim-qml'
2017-03-21 13:54:27 +00:00
" Markdown
Plug 'tpope/vim-markdown'
2018-03-15 18:39:50 +00:00
"Plug 'vim-pandoc/vim-pandoc-syntax'
2017-03-21 13:54:27 +00:00
2017-07-10 14:31:42 +00:00
" C++
2019-05-15 18:00:25 +00:00
Plug 'octol/vim-cpp-enhanced-highlight'
2017-07-10 14:31:42 +00:00
" Haxe
Plug 'jdonaldson/vaxe'
2015-11-29 19:41:56 +00:00
call plug#end()
2015-03-24 21:55:35 +00:00
2015-03-21 19:13:17 +00:00
filetype plugin indent on
2015-02-24 04:34:00 +00:00
2017-07-10 15:08:49 +00:00
"-----------------------------------------------------------------------------------------
"################################################################
"################################################################
"################################################################
" 2. BASE CONFIG
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
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
" allow unsaved background buffers and remember marks/undo for them
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
2017-07-28 15:20:08 +00:00
set showcmd " display incomplete commands
2012-04-19 14:23:13 +00:00
set showmatch
2017-07-28 15:20:08 +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
2015-11-29 21:24:53 +00:00
"set clipboard=unnamed " yank and paste with the system clipboard
2018-03-15 18:39:50 +00:00
set number
2012-04-19 14:23:13 +00:00
" make searches case-sensitive only if they contain upper-case characters
set ignorecase smartcase
2017-07-28 15:20:08 +00:00
set visualbell " No bell sounds
set ttyfast
2012-04-19 14:23:13 +00:00
" highlight current line
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
if IsWindows()
" Just assume we don't have a zsh shell
set shell=bash
else
set shell=zsh
endif
2012-04-19 14:23:13 +00:00
" Prevent Vim from clobbering the scrollback buffer. See
" http://www.shallowsky.com/linux/noaltscreen.html
set t_ti= t_te=
" keep more context when scrolling off the end of a buffer
set scrolloff=3
2017-07-17 16:38:17 +00:00
2012-04-19 14:23:13 +00:00
" Store temporary files in a central spot
set backup
2018-03-15 18:39:50 +00:00
set backupcopy=yes
set directory=X://tmp//vim// " For swap files
set backupdir=X://tmp//vim//
2017-07-17 16:38:17 +00:00
:au BufWritePre * let &bex = '.' . strftime("%Y-%m-%d-%T") . '.bak'
set writebackup
2017-07-17 16:38:17 +00:00
2012-04-19 14:23:13 +00:00
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
2019-03-28 00:15:55 +00:00
set complete+=kspell " Spell checking autocomplete.
set complete-=i " Don't scan all included files since it's really slow.
2012-04-19 14:23:13 +00:00
" Enable highlighting for syntax
2011-04-15 18:44:28 +00:00
syntax on
2012-04-19 14:23:13 +00:00
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
" use emacs-style tab completion when selecting files, etc
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
" Requires ripgrep to be installed.
set grepprg=rg\ --vimgrep
" Show trailing whitespace.
2013-04-21 23:36:08 +00:00
set list listchars=tab:»·,trail
2019-03-28 00:15:55 +00:00
" Adding this since the esc remap on the 'i' key had a long delay when pressed.
2013-05-08 02:34:57 +00:00
set timeoutlen=300 ttimeoutlen=0
2011-04-15 18:44:28 +00:00
2013-08-16 20:50:47 +00:00
" Allow undo when doing back into a closed file
set undolevels=1000
set undoreload=10000
2016-11-04 19:19:59 +00:00
" Keep undo history across sessions by storing it in a file
if has('persistent_undo')
let undo_dir = expand(s:vim_dir . '/undo')
" Create dirs
if IsWindows()
let mkdir = 'mkdir '
else
let mkdir = 'mkdir -p '
endif
:silent call system(mkdir . s:vim_dir)
:silent call system(mkdir . undo_dir)
let &undodir = undo_dir
" Persist undo
set undofile
endif
2013-08-16 20:50:47 +00:00
" Fix vim's background colour erase - http://snk.tuxfamily.org/log/vim-256color-bce.html
if &term =~ '256color'
" 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=
endif
2013-08-16 20:50:47 +00:00
" Disable arrow keys
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
2015-03-21 19:13:17 +00:00
2012-04-19 14:23:13 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CUSTOM AUTOCMDS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2018-03-15 18:39:50 +00:00
2017-07-26 16:06:00 +00:00
augroup campoCmds
2012-04-19 14:23:13 +00:00
" Clear all autocmds in the group
autocmd!
2017-07-26 16:07:31 +00:00
" Automatically wrap at N characters
autocmd FileType gitcommit setlocal colorcolumn=72
2019-05-15 18:00:25 +00:00
autocmd BufRead,BufNewFile *.{md,txt,plan} execute "setlocal textwidth=" .s:max_line_length
2017-07-26 16:07:31 +00:00
" Spell checking
2017-07-28 15:20:08 +00:00
autocmd FileType gitcommit,markdown,text setlocal spell
2012-04-19 14:23:13 +00:00
" 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
2011-04-15 18:44:28 +00:00
" Language identation
2017-04-27 20:23:26 +00:00
autocmd FileType ruby,haml,eruby,yaml,html,javascript,rust,go set ai sw=2 sts=2 et
2017-03-21 13:42:04 +00:00
autocmd FileType python,qml set sw=4 sts=4 et
2011-04-15 18:44:28 +00:00
2012-04-19 14:23:13 +00:00
" Indent p tags
2013-07-10 16:13:13 +00:00
autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
2011-04-15 18:44:28 +00:00
2017-07-26 16:07:31 +00:00
" Properly indent schemes (scheme, racket, etc)
autocmd bufread,bufnewfile *.{lisp,scm,rkt} setlocal equalprg=scmindent.rkt
" Auto reload VIM when settings changed
autocmd BufWritePost .vimrc so $MYVIMRC
autocmd BufWritePost *.vim so $MYVIMRC
autocmd BufWritePost vimrc.symlink so $MYVIMRC
2018-06-11 17:39:04 +00:00
" Generate ctags
2019-03-28 19:06:53 +00:00
" Include local variables for c languages.
2019-04-27 15:42:58 +00:00
au BufWritePost *.py,*.c,*.cpp,*.h silent! !eval 'ctags --c-types=+l --c++-types=+l --exclude=vendor -R -o newtags; mv newtags tags' &
2018-06-11 17:39:04 +00:00
" Remove trailing whitespace on save all files.
function! <SID>StripTrailingWhitespaces()
let l = line(".")
let c = col(".")
%s/\s\+$//e
call cursor(l, c)
endfun
autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
2017-07-26 16:06:00 +00:00
"////////////////////////////////////////////////////////////////
" FILE TEMPLATES
"////////////////////////////////////////////////////////////////
" Shell script template
autocmd BufNewFile *.sh 0r ~/.vim/templates/skeleton.sh
2017-10-25 15:01:42 +00:00
autocmd BufNewFile *.plan 0r ~/.vim/templates/skeleton.plan
2017-07-26 16:06:00 +00:00
" C/C++ template
autocmd bufnewfile *.{c,cc,cpp,h,hpp} 0r ~/.vim/templates/c_header_notice
2017-08-21 18:26:22 +00:00
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/File:.*/s//File: " .expand("%")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/Creation Date:.*/s//Creation Date: " .strftime("%Y-%m-%d")
autocmd bufnewfile *.{c,cc,cpp,h,hpp} exe "2," . 6 . "g/$year/s//" .strftime("%Y")
2017-07-26 16:06:00 +00:00
function! s:InsertHeaderGates()
let gatename = substitute(toupper(expand("%:t")), "\\.", "_", "g")
execute "normal! ggO#ifndef " . gatename
normal! Go
normal! Go
execute "normal! Go#define " . gatename . " "
execute "normal! o#endif"
normal! kkk
endfunction
autocmd bufnewfile *.{h,hpp} call <SID>InsertHeaderGates()
augroup END
2015-03-21 19:13:17 +00:00
2012-04-19 14:23:13 +00:00
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" MISC KEY MAPS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2013-04-20 18:00:26 +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
" suspend process
nmap <leader>z <c-z>
" Quickly edit/reload the vimrc file
2013-07-10 16:13:13 +00:00
nmap <silent> <leader>ev :vsp $MYVIMRC<cr>
nmap <silent> <leader>rv :so $MYVIMRC<cr>
2017-10-10 23:50:00 +00:00
" Easy way to open a file in the directory of the current file
:cmap %/ %:p:h/
2015-10-16 05:10:05 +00:00
" remap saving and quiting
2019-03-28 00:15:55 +00:00
nmap <leader>w :w!<cr>
nmap <leader>q :q<cr>
2015-10-16 05:10:05 +00:00
nmap <leader>qq :q!<cr>
nmap <leader>x :x<cr>
2019-03-28 00:15:55 +00:00
:ca Wa wa!
:ca WA wa!
:ca WQ wq
:ca Wq wq
2019-03-28 00:15:55 +00:00
:ca W w!
:ca Q q
" lowercase the e (have a habit of making it uppercase)
: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
2013-07-10 16:13:13 +00:00
" Disable Ex mode
map Q <Nop>
if exists(':terminal')
" Terminal mapping
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
endif
2015-11-29 23:25:02 +00:00
" Map ctrl-movement keys to window switching
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
" using the arrow keys with or without shift
: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>
" Delete a word forward and backward
map <leader>a daw
map <leader>d ciw
2014-02-17 07:00:21 +00:00
" Map paste and nonumber
map <leader>p :set paste! paste?<cr>
map <leader>o :set number! number?<cr>
2015-02-28 19:28:13 +00:00
" Spell checking
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=
2017-06-13 16:10:24 +00:00
" NOTE: you can add a new word to the dict with `zg`
2015-02-28 19:28:13 +00:00
2012-04-19 14:23:13 +00:00
" Clear the search buffer (highlighting) when hitting return
2012-11-04 23:22:31 +00:00
function! MapCR()
nnoremap <cr> :nohlsearch<cr>
endfunction
call MapCR()
2012-04-19 14:23:13 +00:00
nnoremap <leader><leader> <c-^>
2011-04-15 18:44:28 +00:00
" Replace currently selected text with default register without yanking it
vnoremap p "_dP
2017-07-10 15:08:49 +00:00
" Use Marked.app to preview Markdown files...
nnoremap <leader>pp :silent !open -a Marked.app '%:p'<cr>
2017-06-16 20:16:34 +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
"////////////////////////////////////////////////////////////////
" QUICKLY OPEN C++ SOURCE OR HEADER FILE
"////////////////////////////////////////////////////////////////
function! s:CompleteFilenameWithoutExtension(ArgLead, CmdLine, CursorPos)
" 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
endfunction
" Custom command to open cpp and h files without typing an extension
2019-03-28 01:35:59 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppSource execute ':e <args>.cpp'
":ca c OpenCppSource
":ca C OpenCppSource
2019-03-28 00:15:55 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppHeader execute ':e <args>.h'
":ca h OpenCppHeader
":ca H OpenCppHeader
2019-03-28 01:35:59 +00:00
"command! -nargs=+ -complete=custom,s:CompleteFilenameWithoutExtension OpenCppSourceAndHeader execute ':vsp | :e <args>.h | :sp <args>.cpp'
":ca b OpenCppSourceAndHeader
":ca B OpenCppSourceAndHeader
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>
2017-07-10 15:08:49 +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
"################################################################
"################################################################
"################################################################
" 3. PLUGIN CONFIGS
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LOCAL VIMRC
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:localvimrc_sandbox = 0
let g:localvimrc_ask = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" TAGBAR
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2017-09-22 21:16:30 +00:00
noremap <F12> :TagbarToggle<cr>
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
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2018-10-05 17:38:00 +00:00
let g:gitgutter_enabled = 0
2018-06-11 17:39:04 +00:00
let g:gitgutter_highlight_lines = 1
2018-10-05 17:38:00 +00:00
nmap <leader>ha <Plug>GitGutterStageHunk
nmap <leader>hh :GitGutterToggle
2018-06-11 17:39:04 +00:00
nmap [h <Plug>GitGutterNextHunk
nmap ]h <Plug>GitGutterPrevHunk
" Run on file save. Realtime update is disabled in after/plugins/gitgutter.vim
autocmd BufWritePost * GitGutter
2017-11-15 16:30:09 +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
2019-05-15 18:00:25 +00:00
let g:rg_window_height = g:quickfix_window_height
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.
let g:ctrlp_match_window = 'bottom,order:ttb,min:10,max:20,results:20' " Keep results synced with max height.
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files'] " If a git repo, use checked in files; fallback to globpath()
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.
" @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>'],
" \ }
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" GIT
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2018-03-15 18:39:50 +00:00
map <leader>gb :Gblame -w<cr>
" Ignore whitespace changes; follow renames and copies.
command! -bar -bang -nargs=* Blame :Gblame<bang> -wCM <args>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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 g:rainbow_conf = {
"\}
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()
let g:rainbow_conf = {
\ 'ctermfgs': (s:rainbow_theme == "light"? s:dark_rainbow : s:light_rainbow)
\}
"\ 'separately': {
"\ '*': 0, " Disable all
"\ 'c++': {} " Only enable c++
"\ }
endfunction
call UpdateRainbowConf()
function! ReloadRainbow()
2017-10-29 20:35:44 +00:00
if g:campo_theme_use_rainbow_parens
if exists('g:rainbow_loaded')
call UpdateRainbowConf()
call rainbow#clear() | call rainbow#hook()
endif
else
let g:rainbow_active = 0
if exists('g:rainbow_loaded')
call UpdateRainbowConf()
call rainbow#clear()
endif
endif
endfunction
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" C-TAGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set tags+=tags;$HOME
"-----------------------------------------------------------------------------------------
"################################################################
"################################################################
"################################################################
" 4. VISUALS
2017-07-10 15:08:49 +00:00
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" LAYOUT
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"////////////////////////////////////////////////////////////////
" CENTER THE BUFFER
"////////////////////////////////////////////////////////////////
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
nnoremap <leader>c :call CenterPane()<cr>
function! RemoveCenterPane()
wincmd w
close
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:08:49 +00:00
"////////////////////////////////////////////////////////////////
" STATUS LINE
"////////////////////////////////////////////////////////////////
set statusline=%<%f\ (%{&ft})\ %-4(%m%)%=%-19(%3l,%02c%03V%)
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" COLORS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2017-10-29 20:35:44 +00:00
let g:campo_theme_use_rainbow_parens = 1
2018-03-15 18:39:50 +00:00
"let s:dark_theme = 'campo-dark-green'
let s:dark_theme = 'campo-flux-dark-green'
"let s:dark_theme = 'campo-dark'
2017-07-10 15:08:49 +00:00
let s:light_theme = 'campo-light'
execute "autocmd ColorScheme " . s:dark_theme . " call ReloadRainbow()"
execute "autocmd ColorScheme " . s:light_theme . " call ReloadRainbow()"
2017-07-10 15:08:49 +00:00
" Switch between light and dark
map <leader>l :call ChangeBgTheme('light', 0)<cr>
map <leader>ll :call ChangeBgTheme('dark', 0)<cr>
function! ChangeBgTheme(bg, onlySetTheme)
if a:bg =~ 'light'
let s:rainbow_theme = 'light'
2017-07-10 15:08:49 +00:00
let s:theme = s:light_theme
exe 'colorscheme ' . s:theme
set background=light
else
let s:rainbow_theme = 'dark'
2017-07-10 15:08:49 +00:00
let s:theme = s: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
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
au!
au Syntax * syn match MyBugs /\v<(FIXME|BUG|DEPRECATED):/
\ containedin=.*Comment,vimCommentTitle
augroup END
hi def link MyBugs Bugs
augroup vimrc_notes
au!
au Syntax * syn match MyNotes /\v<(IDEA|NOTE|QUESTION|WARNING|IMPORTANT):/
\ containedin=.*Comment,vimCommentTitle
augroup END
hi def link MyNotes Notes
augroup vimrc_notices
au!
au Syntax * syn match MyNotices /\v<(WARNING|IMPORTANT):/
\ containedin=.*Comment,vimCommentTitle
augroup END
hi def link MyNotices Notices
2017-11-15 16:30:09 +00:00
augroup vimrc_annotated_todo
au!
" This was a major pain in the ass to get working...
au Syntax * syn match cTodo /@\S\+/
\ containedin=.*Comment,vimCommentTitle
augroup END
augroup vimrc_annotated_notes
au!
au Syntax * syn match cTodo /#\+ .\+$/
\ containedin=.*Comment,vimCommentTitle
augroup END
2017-07-10 15:08:49 +00:00
"-----------------------------------------------------------------------------------------
"################################################################
"################################################################
"################################################################
" 5. HELPER FUNCTIONS
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
" 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()
RemoveErrorMarkers
2019-05-15 18:00:25 +00:00
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
2017-07-10 15:08:49 +00:00
endfunction
2017-08-21 18:26:22 +00:00
function! HideAsyncResults()
2019-05-15 18:00:25 +00:00
call asyncrun#quickfix_toggle(g:quickfix_window_height, 0)
2017-08-21 18:26:22 +00:00
endfunction
2017-07-10 15:08:49 +00:00
function! ToggleBuildResults()
2019-05-15 18:00:25 +00:00
call asyncrun#quickfix_toggle(g:quickfix_window_height)
2017-07-10 15:08:49 +00:00
endfunction
function! StopRunTask()
AsyncStop
2017-08-21 18:26:22 +00:00
call HideAsyncResults()
2017-07-10 15:08:49 +00:00
endfunction
function! ExecuteRunScript()
exec "AsyncRun! -post=call\\ StopRunTask() ./run"
endfunction
2017-08-21 18:26:22 +00:00
function! SilentBuild()
AsyncStop
exec "AsyncRun! -save=2 -post=call\\ HideAsyncResults() ./build*"
endfunction
2017-07-10 15:08:49 +00:00
" Show results window the moment the async job starts
augroup vimrc
2019-05-15 18:00:25 +00:00
autocmd User AsyncRunStart call asyncrun#quickfix_toggle(g:quickfix_window_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
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>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SEARCHING
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
2019-03-28 00:15:55 +00:00
" Search using ripgrep (first install with Rust: cargo install ripgrep)
" Ignores vendor folder.
if !IsWindows()
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!vendor/*" --pretty "always" '.shellescape(<q-args>), 1, <bang>0)
endif
2017-07-10 15:08:49 +00:00
" TODO: Not sure if I still need this
map <leader>gs :let @/ = ""<CR>
" Replace the selected text in all files within the repo
function! GlobalReplaceIt(confirm_replacement)
if exists(':Ggrep')
call inputsave()
let l:term = input('Enter search term: ')
call inputrestore()
if empty(l:term)
return
endif
2017-07-10 15:08:49 +00:00
call inputsave()
let l:replacement = input('Enter replacement: ')
call inputrestore()
if empty(l:replacement)
return
endif
2017-07-10 15:08:49 +00:00
if a:confirm_replacement
let l:confirm_opt = 'c'
else
let l:confirm_opt = 'e'
endif
2017-07-10 15:08:49 +00:00
execute 'Ggrep '.l:term
execute 'Qargs | argdo %s/'.l:term.'/'.l:replacement.'/g'.l:confirm_opt.' | update'
else
echo "Unable to search since you're not in a git repo"
endif
endfunction
map <leader>gg :call GlobalReplaceIt(0)<cr>
map <leader>gr :call GlobalReplaceIt(1)<cr>
2019-05-15 18:00:25 +00:00
function! Search(case_sensitive)
let helper = "[" . (a:case_sensitive ? "case-sensitive" : "case-insensitive") . "] search: "
2019-04-27 15:42:58 +00:00
let term = input(helper)
if empty(term)
return
endif
2019-03-28 00:15:55 +00:00
2019-04-27 15:42:58 +00:00
"@note --pretty (i.e. colors) is not enabled in vim-ripgrep because the
"quickfix window doesn't seem to parse the ansi color codes.
let rg_args = "--trim -g \"!vendor/*\""
2019-05-15 18:00:25 +00:00
if !a:case_sensitive
2019-04-27 15:42:58 +00:00
let rg_args .= " --ignore-case"
endif
if IsWindows()
"@deprecated: Fsgrep is slow...."
"exec 'Fsgrep "' . term . '"'
exec 'Rg ' . rg_args . ' "' . term . '"'
else
2019-04-27 15:42:58 +00:00
"@deprecated: ripgrep is faster than Ag.
"exec 'Ag "' . term . '"'
" @incomplete pass case sensitivity toggle to Find.
execute 'Find ' . term
2017-07-10 15:08:49 +00:00
endif
endfunction
2019-05-15 18:00:25 +00:00
map <leader>s :call Search(0)<cr>
map <leader>ss :call Search(1)<cr>
2017-07-10 15:08:49 +00:00
2019-03-28 00:15:55 +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")
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
" FILESEARCH PLUGIN
"////////////////////////////////////////////////////////////////
let g:filesearch_viewport_split_policy = "B"
let g:filesearch_split_size = 10
let g:filesearch_autodismiss_on_select = 0
"////////////////////////////////////////////////////////////////
2015-03-21 19:13:17 +00:00
" SELECTA -- find files with fuzzy-search
2017-07-10 15:08:49 +00:00
"////////////////////////////////////////////////////////////////
2019-03-28 00:15:55 +00:00
2015-03-21 19:13:17 +00:00
" Run a given vim command on the results of fuzzy selecting from a given shell
" command. See usage below.
function! SelectaCommand(choice_command, selecta_args, vim_command)
if IsWindows()
let l:term = input('File name: ')
exec 'Fsfind "' . l:term . '"'
else
try
let l:selection = system(a:choice_command . " | selecta " . a:selecta_args)
catch /Vim:Interrupt/
" Swallow the ^C so that the redraw below happens; otherwise there will be
" leftovers from selecta on the screen
redraw!
return
endtry
2015-03-21 19:13:17 +00:00
redraw!
exec a:vim_command . " " . l:selection
endif
2015-03-21 19:13:17 +00:00
endfunction
" Find all files in all non-dot directories starting in the working directory.
" Fuzzy select one of those. Open the selected file with :e.
2019-03-28 01:35:59 +00:00
" DISABLED (2019-03) because I'm now using ctrl-p for fuzzy searching.
" nnoremap <leader>f :call SelectaCommand("find * -type f ! -path 'resources/public/js/*' ! -path 'resources/.sass-cache/*' ! -path 'target/*'", "", ":e")<cr>
2015-03-21 19:13:17 +00:00
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
2017-07-10 15:08:49 +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
"################################################################
"################################################################
"################################################################
" 6. PERSONAL
"################################################################
"################################################################
"################################################################
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FILE MAPPINGS
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Notes and other helpers
map <leader>pn :sp ~/.dev-scratchpad<cr>
2018-06-11 17:39:04 +00:00
"let g:autotagStopAt = "$HOME"