Created
September 11, 2016 12:57
-
-
Save kristopherjohnson/b031db9ca64329dce073c4026823b444 to your computer and use it in GitHub Desktop.
My .vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible | |
" Global variables {{{1 | |
" | |
let g:kj_foldcolumn=4 | |
let g:kj_quickfix_is_open = 0 | |
" Options {{{1 | |
set autochdir | |
set autoread | |
set backspace=indent,eol,start | |
set backup | |
set complete-=i | |
set display+=lastline | |
set expandtab | |
set history=50 | |
set ignorecase | |
set incsearch | |
set laststatus=2 | |
set number | |
set ruler | |
set shiftround | |
set shiftwidth=4 | |
set showcmd | |
set showmatch | |
set smartcase | |
set smarttab | |
try | |
let &softtabstop = -1 " use the value of 'shiftwidth' implicitly | |
catch /^Vim:\(\a+\):E487:/ " 'Argument must be positive' | |
let &softtabstop = &shiftwidth " use the value of 'shiftwidth' directly | |
endtry | |
set tags=tags; | |
set undofile | |
set visualbell | |
set wildcharm=<C-z> | |
set wildmenu | |
set wildmode=full | |
if has('win32') || has('win64') | |
set backupdir=~/AppData/Local/Temp/vimbak//,~/AppData/Local/Temp//,$TEMP | |
set directory=~/AppData/Local/Temp/vimswp//,~/AppData/Local/Temp//,$TEMP | |
if has('persistent_undo') | |
set undodir=~/AppData/Local/Temp/vimundo//,~/AppData/Local/Temp//,$TEMP | |
endif | |
else | |
set backupdir=~/.vimbak//,$TMPDIR,/tmp// | |
set directory=~/.vimswp//,$TMPDIR,/tmp// | |
if has('persistent_undo') | |
set undodir=~/.vimundo//,$TMPDIR,/tmp// | |
endif | |
endif | |
if !&scrolloff | |
set scrolloff=1 | |
endif | |
if !&sidescrolloff | |
set sidescrolloff=5 | |
endif | |
if &encoding ==# 'latin1' && has('gui_running') | |
set encoding=utf-8 | |
endif | |
if &listchars ==# 'eol:$' | |
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+ | |
endif | |
if v:version > 703 || v:version == 703 && has("patch541") | |
set formatoptions+=j " Delete comment character when joining commented lines | |
endif | |
if has('path_extra') | |
setglobal tags-=./tags tags-=./tags; tags^=./tags; | |
endif | |
if &shell =~# 'fish$' | |
set shell=/bin/bash | |
endif | |
if &history < 1000 | |
set history=1000 | |
endif | |
if &tabpagemax < 50 | |
set tabpagemax=50 | |
endif | |
if !empty(&viminfo) | |
set viminfo^=! | |
endif | |
set sessionoptions-=options | |
if has('mouse') | |
set mouse=a | |
endif | |
" Allow color schemes to do bright colors without forcing bold. | |
if &t_Co == 8 && $TERM !~# '^linux\|^Eterm' | |
set t_Co=16 | |
endif | |
" Load matchit.vim, but only if the user hasn't installed a newer version. | |
if !exists('g:loaded_matchit') && findfile('plugin/matchit.vim', &rtp) ==# '' | |
runtime! macros/matchit.vim | |
endif | |
if &t_Co > 2 || has("gui_running") | |
let g:zenburn_High_Contrast = 1 | |
let g:zenburn_old_Visual = 1 | |
try | |
colorscheme zenburn | |
catch | |
" Fall back to a built-in color scheme if Zenburn is not available | |
colorscheme desert | |
" colorscheme darkblue | |
" colorscheme evening | |
" colorscheme industry | |
" colorscheme koehler | |
" colorscheme murphy | |
" colorscheme pablo | |
" colorscheme torte | |
endtry | |
syntax on | |
set hlsearch | |
endif | |
if has('gui_running') && (&lines < 40 || &columns < 140) | |
" If OS gave us a small window, make it bigger. | |
set lines=40 columns=140 | |
endif | |
" Key mappings {{{1 | |
let mapleader = '\' | |
let maplocalleader = ',' | |
" Normal-mode key mappings {{{2 | |
" Use Space to scroll down a page, Delete to scroll up a page. | |
nnoremap <Space> <PageDown> | |
nnoremap <BS> <PageUp> | |
" Insert a space at current position. | |
nnoremap <Leader><Space> i<Space><Esc> | |
" Repeat editing commands on subsequent lines. | |
nnoremap <Leader>. mx.g`xj | |
nnoremap <Leader>, j^. | |
nnoremap <Leader>/ j$. | |
" Reindent the whole file. | |
nnoremap <Leader>= :keepjumps :normal mxgg=G`x<CR> | |
" Remove trailing whitespace. | |
nnoremap <silent> <Leader>$ :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR> | |
" Quickfix shortcuts | |
nnoremap <Leader>' :cnext<CR> | |
nnoremap <Leader>; :cprevious<CR> | |
nnoremap <leader>q :call <SID>KJQuickfixToggle()<CR> | |
" Fold shortcuts | |
nnoremap <Leader>zi :execute 'setlocal foldcolumn=' . g:kj_foldcolumn . ' foldmethod=indent'<CR> | |
nnoremap <Leader>zs :execute 'setlocal foldcolumn=' . g:kj_foldcolumn . ' foldmethod=syntax'<CR> | |
nnoremap <Leader>zm :execute 'setlocal foldcolumn=' . g:kj_foldcolumn . ' foldmethod=manual'<CR> | |
nnoremap <Leader>zk :execute 'setlocal foldcolumn=' . g:kj_foldcolumn . ' foldmethod=marker'<CR> | |
nnoremap <Leader>zf :call <SID>KJFoldColumnToggle()<CR> | |
" shiftwidth shortcuts | |
nnoremap <Leader>2 :setlocal shiftwidth=2<CR> | |
nnoremap <Leader>3 :setlocal shiftwidth=3<CR> | |
nnoremap <Leader>4 :setlocal shiftwidth=4<CR> | |
" Close all folds except at cursor location. | |
nnoremap Leader>zz zMzv | |
nnoremap <Leader>V :source ~/.vimrc<CR> | |
nnoremap <Leader>M :MRU<CR> | |
nnoremap <Leader>[ <C-o> | |
nnoremap <Leader>] <C-i> | |
nnoremap <Leader>- <C-^> | |
" Window shortcuts | |
nnoremap <Leader>w <C-w>w | |
nnoremap <Leader>p <C-w>p | |
nnoremap <Leader>o <C-w>o | |
nnoremap <Leader><Left> <C-w><Left> | |
nnoremap <Leader><Down> <C-w><Down> | |
nnoremap <Leader><Right> <C-w><Right> | |
nnoremap <Leader><Up> <C-w><Up> | |
nnoremap <Leader>H <C-w>H | |
nnoremap <Leader>J <C-w>J | |
nnoremap <Leader>K <C-w>K | |
nnoremap <Leader>L <C-w>L | |
nnoremap <Leader>{ a{<CR><C-o>mx<CR>}<C-o>`x | |
" Open alternate file in vertical split | |
nnoremap <Leader># :execute "vertical rightbelow sbuffer " . bufnr('#')<CR> | |
if has('gui_running') | |
nnoremap <Leader>ew :drop ~/work/ | |
nnoremap <Leader>es :drop ~/scratch/ | |
nnoremap <Leader>ems :drop ~/ml2/src/ | |
nnoremap <Leader>emt :drop ~/ml2/test/ | |
nnoremap <Leader>eft :drop ~/.vim/ftplugin/ | |
else | |
nnoremap <Leader>ew :edit ~/work/ | |
nnoremap <Leader>es :edit ~/scratch/ | |
nnoremap <Leader>ems :edit ~/ml2/src/ | |
nnoremap <Leader>emt :edit ~/ml2/test/ | |
nnoremap <Leader>eft :edit ~/.vim/ftplugin/ | |
endif | |
if has('gui_running') | |
nnoremap <Leader>v :drop ~/.vimrc<CR> | |
nnoremap <Leader>s :drop ~/Dropbox/scratch.txt<CR> | |
nnoremap <Leader>V :drop ~/Dropbox/scratch.vim<CR> | |
else | |
nnoremap <Leader>v :edit ~/.vimrc<CR> | |
nnoremap <Leader>s :edit ~/Dropbox/scratch.txt<CR> | |
nnoremap <Leader>V :edit ~/Dropbox/scratch.vim<CR> | |
endif | |
if has("gui-macvim") | |
nnoremap <D-[> <C-o> | |
nnoremap <D-]> <C-i> | |
endif | |
" Insert-mode key mappings {{{2 | |
inoremap jj <Esc> | |
inoremap <C-u> <C-g>u<C-u> | |
inoremap <C-w> <C-g>u<C-u> | |
inoremap ;; <Esc>A;<Esc> | |
inoremap ;;; <Esc>A;<CR> | |
inoremap ( ()<Left> | |
inoremap () () | |
inoremap { {}<Left> | |
inoremap {} {} | |
inoremap {<CR> {<CR><CR>}<Up><Tab> | |
inoremap [ []<Left> | |
inoremap [] []"}}} | |
" Abbreviations {{{1 | |
iabbrev kj Kristopher Johnson | |
iabbrev @@ [email protected] | |
iabbrev mlem [email protected] | |
iabbrev ckj Copyright ©2016 Kristopher Johnson | |
iabbrev cml Copyright ©2016 Mobile Labs, LLC | |
cabbrev vhelp vertical botright help | |
cabbrev vh vertical botright help | |
cabbrev vr vertical resize | |
cabbrev man Man | |
" Plugins {{{1 | |
:runtime! ftplugin/man.vim | |
" vim-plug <https://github.com/junegunn/vim-plug> | |
if isdirectory(expand('~/.vim/plugged')) | |
call plug#begin('~/.vim/plugged') | |
Plug 'keith/swift.vim' | |
Plug 'rizzatti/dash.vim' | |
Plug 'git://github.com/rking/ag.vim.git' | |
Plug 'fatih/vim-go' | |
Plug 'https://github.com/WolfgangMehner/vim-support.git' | |
Plug 'scrooloose/nerdcommenter' | |
Plug 'https://github.com/yegappan/mru.git' | |
call plug#end() | |
endif | |
" Functions {{{! | |
" From <http://learnvimscriptthehardway.stevelosh.com/chapters/38.html> | |
function! s:KJQuickfixToggle() | |
if g:kj_quickfix_is_open | |
cclose | |
let g:kj_quickfix_is_open = 0 | |
execute g:kj_quickfix_return_to_window . "wincmd w" | |
else | |
let g:kj_quickfix_return_to_window = winnr() | |
copen | |
let g:kj_quickfix_is_open = 1 | |
endif | |
endfunction | |
" From <http://learnvimscriptthehardway.stevelosh.com/chapters/38.html> | |
function! s:KJFoldColumnToggle() | |
if &foldcolumn | |
setlocal foldcolumn=0 | |
else | |
execute 'setlocal foldcolumn=' . g:kj_foldcolumn | |
endif | |
endfunction | |
" Commands {{{1 | |
" :O FILENAME to open file or jump to it if it's already open. | |
:command! -nargs=1 -complete=file O tab drop <args> | |
" Resize window to full screen size | |
:command! Maximize set lines=999 columns=999 | |
" Print decimal number as hexadecimal | |
:command! -nargs=1 D2x echo printf("%x", <args>) | |
" Insert MIT license | |
:command! MitLicense read ~/dotfiles/share/mitlicense.txt | |
" Insert BSD license | |
:command! BsdLicense read ~/dotfiles/share/bsdlicense.txt | |
" Highlight pattern with 'standout' style | |
highlight Standout term=standout cterm=standout gui=standout | |
:command! -nargs=+ Standout 2match Standout <args> | |
" Highlight pattern with reverse video | |
highlight Reverse term=reverse cterm=reverse gui=reverse | |
:command! -nargs=+ Reverse 2match Reverse <args> | |
" Highlight pattern with 'underline' style | |
highlight Underline term=underline cterm=underline gui=underline | |
:command! -nargs=+ Underline 2match Underline <args> | |
" Highlight pattern with 'undercurl' | |
highlight Undercurl term=undercurl cterm=undercurl gui=undercurl | |
:command! -nargs=+ Undercurl 2match Undercurl <args> | |
:command! MatchOff match none | 2match none | 3match none | |
" Convenient command to see the difference between the current buffer and the | |
" file it was loaded from, thus the changes you made. Only define it when not | |
" defined already. | |
if !exists(":DiffOrig") | |
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis | |
\ | wincmd p | diffthis | |
endif | |
" Autocommands {{{1 | |
if has("autocmd") | |
filetype plugin indent on | |
augroup vimrcEx | |
au! | |
autocmd BufReadPre,FileReadPre ~/.vimrc execute 'setlocal foldcolumn=' . g:kj_foldcolumn . ' foldmethod=marker' | |
" When editing a file, always jump to the last known cursor position. | |
" Don't do it when the position is invalid or when inside an event | |
" handler (happens when dropping a file on gvim). Also don't do it | |
" when the mark is in the first line, that is the default position | |
" when opening a file. | |
autocmd BufReadPost * | |
\ if line("'\"") > 1 && line("'\"") <= line("$") | | |
\ exe "normal! g`\"" | | |
\ endif | |
augroup END | |
else | |
set autoindent " always set autoindenting on | |
endif " has("autocmd") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment