" Teddy Wing " http://www.teddywing.com " " 2010.11.06 " " CHANGELOG: " 2014.04.03: " * Add Shift-Tab mapping to exit Insert mode " " 2014.04.11: " * Preserve indentation on blank lines " " 2014.04.12: " * Add leader and symbols for showing invisible characters " (http://vimcasts.org/episodes/show-invisibles/) " * Remove `set expandtab` " * Add `set softtabstop=4` " * Add function from Vimcasts to set tab width " * Add normal mode mapping to toggle expandtab " * Add [ and ] indentation to retain selection when indenting " * Add `set hidden` " * Add `set list` " * Add soft wrap " * Source .vimrc whenever it has been saved " " 2014.04.15: " * Add pathogen " * Add twilight256 colour scheme " * Add NERD Tree " * Add Command-T " * Remap Command-T from t to d " * Set switchbuf=usetab,newtab " * Map Control-h to :update " " 2014.04.16: " * Set NERDTree sort order such that all files & directories are sorted " alphabetically, instead of directories appearing above files. " * Set NERDTree default width to 24 columns " * Map j -> gj and k -> gk for moving on wrapped lines " * Set noendofline " * Add project-level indentation settings for Flashnotes " * Remove t mapping because Command-T will not overwrite " a pre-existing mapping " * Install TabBar for buffer tabs, add mappings to access tabs using " commands " * Map Shift-Tab to Esc in normal mode in addition to Insert & Visual " * Install commentary.vim and set comment strings for Ruby, JavaScript, " SCSS, HTML, Python " " 2014.04.17: " * Remove `set :noendofline` as it wasn't doing what I wanted it to do " * Add & set PreserveNoEOL plugin to preserve file EOL " * Move commentary.vim autocmds into an augroup " * Always show status line " * Make custom status line " * Change `vb` setting to unabbreviated form, `visualbell` " * Change 'set' to 'setlocal' in my autocommands " " 2014.04.18: " * Add mappings for easier buffer switching (leader-j, leader-k, " leader-bx) " * Use 'a' instead of 'i' in my Control-h save mapping because we want " to return to the same cursor position " * Map bl to list buffers " " 2014.04.19: " * Set `timeoutlen` to 500 milliseconds " " 2014.04.20: " * Install EasyGrep plugin and add configuration for EasyGrepCommand=1, " EasyGrepRecursive=1, EasyGrepEveryMatch=1, " EasyGrepReplaceAllPerFile=1 " * Set grepprg=ack " * Add an extra line of spacing between sections and '===' underlines " below main headings " * Move project-specific settings into ~/.vim/projects and source all " files in that directory " " 2014.04.23: " * Set EasyGrep to be case insensitive by default " " 2014.04.25: " * Map / to clear search highlighting " * Map gj -> j and gk -> k so we can still skip wrapped lines if we want " * Set ignorecase and smartcase " * Add file encoding to statusline " " 2014.04.28: " * Add augroup for custom syntax highlighting by filetype " * Add autocmd to set .json files to use JavaScript syntax highlighting " and have a json filetype " " 2014.04.30: " * Set backupdir, directory, and undodir to be within ~/.vim so that my " filesystem doesn't clutter with *.swp files and the like " " 2014.05.01: " * Change status bar colour from white to green when switching into and " out of insert mode " " 2014.05.02: " * Add augroup for filetype indentation settings " * Set gitcommit files to use 2-space indentation " * Remove `switchbuf=usetab,newtab` setting because it doesn't work " with my current workflow. Now when I use EasyGrep the files opened " from the Quickfix window will open in the same tab instead of a new " tab, which is less of a surprise and context switch. " " 2014.05.08: " * Add Indent Guides plugin to show tab stops " * Remap Indent Guides toggle command to ts " * Set Indent Guides size to 1 column (only works for expandtab) " * Set custom colours for Indent Guides that are a little less intrusive " " Pathogen " ======== runtime bundle/vim-pathogen/autoload/pathogen.vim execute pathogen#infect() call pathogen#helptags() " Default configuration " ===================== set visualbell t_vb= " Turn off error beep set autoindent set tabstop=4 " Use 4-space tabs set softtabstop=4 " Allow delete to remove indent when expandtab is enabled set shiftwidth=4 " set expandtab set wrap " Soft wrap set linebreak " Don't wrap in the middle of words. Only works when nolist is set set scrolloff=3 " Scroll offset: always keep 3 lines set showmatch " Highlight matching braces etc. set hlsearch " Highlight searches set incsearch " Search for text as you enter it set ruler " Show cursor position set number " Show line numbers set list " Show invisibles by default set hidden " Don't raise errors when switching buffers with unsaved changes set timeoutlen=500 " If bl and b are both mapped, wait 0.5 " seconds instead of 1 second to fire b if no l " is pressed subsequently set grepprg=ack " Use ack instead of grep set ignorecase " Case insensitive set smartcase " Case insensitive unless an uppercase character is entered " Store swap files in .vim/ directory " http://stackoverflow.com/a/15317146 set backupdir=~/.vim/backup/backup// set directory=~/.vim/backup/swap// set undodir=~/.vim/backup/undo// set laststatus=2 " Always show the status line " Statusline set statusline=%f " Path to file set statusline+=\ " Separator set statusline+=%y " Filetype set statusline+=\ " Separator " File encoding " (http://vim.wikia.com/wiki/Show_fileencoding_and_bomb_in_the_status_line) set statusline+=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"} set statusline+=\ " Separator set statusline+=%m " File modified? flag set statusline+=%r " Readonly? flag set statusline+=\ " Separator set statusline+=-b%n- " Buffer number as -b{buffer #}- set statusline+=\ " Separator set statusline+=%= " Switch to right side set statusline+=%5l " Line number (ensure space for 5 characters) set statusline+=, " Comma separator set statusline+=%-8c " Column number (ensure space for 8 characters) set statusline+=\ " Separator set statusline+=%4P " Percent through file in window (ensure space for 4 characters) " Syntax highlighting (base) " ========================== syntax on " Syntax highlighting hi Comment ctermfg=green guifg=#919191 cterm=none hi Constant ctermfg=red guifg=#1C4B80 cterm=none "hi Identifier hi Statement ctermfg=blue guifg=#696EC0 hi PreProc ctermfg=brown guifg=#73371C hi Type ctermfg=cyan guifg=#696EC0 hi Special ctermfg=red guifg=#696EC0 hi Normal ctermfg=black guifg=#dddddd guibg=#09192F " Invisible character colours hi NonText guifg=#4a4a59 hi SpecialKey guifg=#4a4a59 set guifont=Monaco\ 10 " Set Twilight theme colorscheme twilight256 " Change statusline color when entering & leaving Insert mode " Only when colourscheme is 'twilight256' if exists('g:colors_name') && g:colors_name ==# 'twilight256' augroup statusline_color_on_mode_change autocmd! autocmd InsertEnter * highlight statusline ctermfg=120 ctermbg=234 autocmd InsertLeave * highlight statusline ctermfg=15 ctermbg=235 augroup END endif " Plugins " ======= " Command-T " Remap Command-T from t to d (BBEdit style) nnoremap d :CommandT " NERDTree " Alphabetical sort ordering let NERDTreeSortOrder = [] let NERDTreeWinSize = 24 " Toggle NERDTree with leader command nnoremap f :NERDTreeToggle " TabBar " j/k to switch to previous/next buffer tab nnoremap j :Tbbp nnoremap k :Tbbn " Leader+# to switch to a specific buffer tab nnoremap 1 :TbBfSwitchTo 1: nnoremap 2 :TbBfSwitchTo 2: nnoremap 3 :TbBfSwitchTo 3: nnoremap 4 :TbBfSwitchTo 4: nnoremap 5 :TbBfSwitchTo 5: nnoremap 6 :TbBfSwitchTo 6: nnoremap 7 :TbBfSwitchTo 7: nnoremap 8 :TbBfSwitchTo 8: nnoremap 9 :TbBfSwitchTo 9: nnoremap 0 :TbBfSwitchTo 10: inoremap 1 :TbBfSwitchTo 1:a inoremap 2 :TbBfSwitchTo 2:a inoremap 3 :TbBfSwitchTo 3:a inoremap 4 :TbBfSwitchTo 4:a inoremap 5 :TbBfSwitchTo 5:a inoremap 6 :TbBfSwitchTo 6:a inoremap 7 :TbBfSwitchTo 7:a inoremap 8 :TbBfSwitchTo 8:a inoremap 9 :TbBfSwitchTo 9:a inoremap 0 :TbBfSwitchTo 10:a " commentary.vim augroup commentaryvim autocmd! autocmd FileType ruby setlocal commentstring=#\ %s autocmd FileType html setlocal commentstring= autocmd FileType javascript setlocal commentstring=//\ %s autocmd FileType scss setlocal commentstring=//\ %s autocmd FileType python setlocal commentstring=#\ %s augroup END " PreserveNoEOL let g:PreserveNoEOL = 1 " EasyGrep let g:EasyGrepCommand = 1 " Use grep instead of vimgrep let g:EasyGrepRecursive = 1 " Recursive search enabled let g:EasyGrepEveryMatch = 1 " Multiple matches on the same line are distinct let g:EasyGrepIgnoreCase = 1 let g:EasyGrepReplaceAllPerFile = 1 " Indent Guides let g:indent_guides_guide_size = 1 " Set guide size to 1 column let g:indent_guides_default_mapping = 0 " Remove default ig mapping " Set mapping to ts for "Tab Stop" nnoremap ts :IndentGuidesToggle " Set colours for indent guides if exists('g:colors_name') && g:colors_name ==# 'twilight256' " Turn off automatic colours let g:indent_guides_auto_colors = 0 autocmd VimEnter,Colorscheme * :hi IndentGuidesOdd ctermbg=238 autocmd VimEnter,Colorscheme * :hi IndentGuidesEven ctermbg=238 endif " Mappings " ======== " Shift-Tab to enter normal mode from insert mode nnoremap inoremap vnoremap " Control-h to save (Why 'h'? Because it seemed to be a non-important combo " across modes, and because bash by default doesn't let me map Control-s) nnoremap :update inoremap :updatea vnoremap :updatev " Preserve indentation on empty lines " http://stackoverflow.com/a/7413117 inoremap x nnoremap o ox nnoremap O Ox " Show invisibles with i nnoremap i :set list! " Use TextMate-style symbols for tabs and EOLs set listchars=tab:▸\ ,eol:¬ " Toggle between tab and space indentation nnoremap st :set expandtab! expandtab? " OS X-style indentation, retains selection when indenting " http://vimcasts.org/episodes/indentation-commands/ nnoremap [ << nnoremap ] >> vnoremap [ ] >gv " Allow easy moving to wrapped lines nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k " Easier buffer switching nnoremap bl :ls nnoremap j :bnext nnoremap k :bprevious " Close buffer without closing split " http://stackoverflow.com/a/4468491 nnoremap bx :bp \| bd # " Clear search highlighting nnoremap / :nohlsearch " Commands " ======== " Set tabstop, softtabstop and shiftwidth to the same value " http://vimcasts.org/episodes/tabs-and-spaces/ command! -nargs=* Stab call Stab() function! Stab() let l:tabstop = 1 * input('set tabstop = softtabstop = shiftwidth = ') if l:tabstop > 0 let &l:sts = l:tabstop let &l:ts = l:tabstop let &l:sw = l:tabstop endif call SummarizeTabs() endfunction function! SummarizeTabs() try echohl ModeMsg echon 'tabstop='.&l:ts echon ' shiftwidth='.&l:sw echon ' softtabstop='.&l:sts if &l:et echon ' expandtab' else echon ' noexpandtab' endif finally echohl None endtry endfunction " Swap between soft wrapping and no wrapping " http://vimcasts.org/episodes/soft-wrapping-text/ command! -nargs=* Wrap set wrap linebreak nolist " Autocommands " ============ " Source the vimrc file after saving it " http://vimcasts.org/episodes/updating-your-vimrc-file-on-the-fly/ " if has("autocmd") " autocmd bufwritepost .vimrc source $MYVIMRC " endif " Filetype syntax highlighting augroup filetype_syntax_highlighting autocmd! " Set JSON files to JavaScript syntax autocmd BufRead,BufNewFile *.json set filetype=json syntax=javascript augroup END " Indentation rules by file type augroup filetype_indentation autocmd! " git commit messages autocmd FileType gitcommit setlocal expandtab tabstop=2 softtabstop=2 shiftwidth=2 augroup END " Project Settings " ================ " Source all files in the ~/.vim/projects directory " http://stackoverflow.com/a/4500936 for f in split(glob('~/.vim/projects/*.vim'), '\n') execute 'source' f endfor