set nocompatible " Don't have to try to be compatible with old vi set encoding=utf-8 """""""" "" Plugin Loading with Pathogen """"""""""""""""""""""""""""""""""""""""""""""""""" call pathogen#infect() call pathogen#helptags() """""""" "" Environment - What kind of machine are we on? """"""""""""""""""""""""""""""""""""""""""""""""""" if has("unix") " remove the newline character from the uname command let s:uname = substitute(system("uname"), "\n", "", "") endif """""""" "" General Behaviours """"""""""""""""""""""""""""""""""""""""""""""""""" set splitbelow " New splits appear below current window instead of above set splitright " New splits appear right of current window set ttyfast " Smooth movement set ttymouse=xterm2 set mouse=a set scrolloff=4 " keep distance from top and bottom for current line set cursorline " ensure that there is a cursor line " Persistent undo if has("persistent_undo") set undofile set undodir=~/.vim/undo endif if has("autocmd") " Enable filetype specific features filetype plugin indent on " Clear existing autocmd autocmd! " When editing a file, always jump to the last cursor position " (from Ubuntu's `/etc/vim/vimrc`) autocmd BufReadPost * \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal! g'\"" | \ endif " Show trailing white space autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@ q :ccl:lcl autocmd FileType qf nnoremap o " Global remaps for all QuickFix buffers autocmd BufWinEnter quickfix \ setlocal nocursorline | \ let g:qfix_win = bufnr("$") | \ call MapQfPrevNext() autocmd BufWinLeave * \ if exists("g:qfix_win") && expand("") == g:qfix_win | \ unlet! g:qfix_win | \ call UnmapQfPrefNext() | \ endif " Open QuickFix window after any grep invocation (Glog and Ggrep) autocmd QuickFixCmdPost *grep* cwindow | \ setlocal nocursorline | \ let g:qfix_win = bufnr("$") | \ call MapQfPrevNext() " if the last window is NERDTree, then close Vim "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " " Show cursorline only on active window. No need for this now "autocmd WinEnter * setlocal cursorline "autocmd WinLeave * setlocal nocursorline else set autoindent on endif """""""" "" Tabs and Text Formatting """""""""""""""""""""""""""""""""""""""""""""""""""""" set expandtab " change to single spaces set tabstop=2 " actual tab press distance set shiftround " indent to nearest tabstops set shiftwidth=2 " amount to indent with > and < set smarttab " backspace tabs where appropriate even if spaces set softtabstop=2 " let backspace delete by indents set nowrap " do not wrap long lines of text set backspace=eol,start,indent "backspace over everything set textwidth=80 " try to keep text within 80 characters set colorcolumn=+1 " mark out the limits of the textwidth set listchars=trail:_,tab:>.,eol:$ """""""" "" UI - Colours """""""""""""""""""""""""""""""""""""""""""""""""""""" syntax enable colorscheme solarized set t_Co=16 set background=dark " set colour for folded lines highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none " show trailing white space highlight ExtraWhitespace ctermfg=red ctermbg=red guifg=red guibg=red " reverse indent guides highlighting highlight IndentGuidesOdd ctermbg=darkgrey highlight IndentGuidesEven ctermbg=black """""""" "" UI - Numbering """""""""""""""""""""""""""""""""""""""""""""""""""""""" set number " show line numbers "set relativenumber " current line always 0 (requires 7.3 and up) """""""" "" UI - Statusline (now using powerline) """""""""""""""""""""""""""""""""""""""""""""""""""""""" set laststatus=2 " status line is second last line (not hidden by commands) """""""" "" UI - Code Folding """""""""""""""""""""""""""""""""""""""""""""""""""""""" set foldmethod=indent set foldlevel=10 set foldtext=FoldText() """""""" "" UI - Search """""""""""""""""""""""""""""""""""""""""""""""""""""""" set hlsearch " make searches highlighted set incsearch " vim will search as you type! set ignorecase " ignore case for searches set smartcase " well, unless a user puts in uppercase search characters set magic " enables wildcard searching " use ack for grepping if available if executable('ack-grep') set grepprg=ack-grep\ --with-filename\ --nocolor\ --nogroup elseif executable('ack') set grepprg=ack\ --with-filename\ --nocolor\ --nogroup endif set shellpipe=&> " don't display ack/grep terminal output. NOTE: not reliable " https://github.com/mileszs/ack.vim/issues/18 """""""" "" Key Remaps """""""""""""""""""""""""""""""""""""""""""""""""""""""" let mapleader = "," " easier to use than \ " More convenient escape imap ii imap II " Yank to end of line, like D deletes to end of line nmap Y y$ " Add extra lines up and down nmap j ok nmap k Oj " Edit .vimrc nmap v :e $MYVIMRC " Clear TRAILING WHITE SPACE nmap $ :%s/\s\+$//g " Convert TABS to SPACES nmap :%s// /g " Space as a folding toggle in normal mode. nmap @=(foldlevel('.')?'za':"\") " Tab to CLEAR CURRENT SEARCH (and stop highlighting) in normal mode " TODO would love to use (more intuitive), but there are issues at vim " startup nmap \ :call ClearSearch() nmap n :set number! nmap w :set wrap! nmap 80 gggqG " Toggle paste mode - no autoindenting of pasted material nmap p :set paste! paste? " Toggle visible whitespace characters nmap l :set list! " Toggle keyboard layout nmap :call CycleKeymap() " Toggle scrollbind for moving multiple splits in sync together nmap s :set scrollbind! scrollbind? " Toggle mouse support. nmap m :call ToggleMouse() " Toggle NERDTree file browser nmap d :NERDTreeToggle " Toggle Commenting out lines with NERDCommenter nmap , :call NERDComment("n", "toggle") vmap , :call NERDComment("x", "toggle") " Traverse undo tree with Gundo nmap u :GundoToggle " Git commands with Fugitive nmap gs :Gstatus nmap gc :Gcommit -v nmap gl :Glog nmap gap :Git add -p nmap b :Gblame " Ack with Ctrl-F nmap :Grep " Code heirarchy with Tagbar nmap t :TagbarToggle " Unite settings " "nnoremap :Unite file_rec/async:! -prompt=Goto\ File\ >\ -buffer-name=Files -resume "let g:unite_enable_start_insert = 1 "call unite#custom_source('file_rec/async', 'matchers', 'matcher_fuzzy') "call unite#custom_source('file_rec/async', 'sorters', 'sorter_rank') """""""" "" Key Remaps - Movement and Windows """""""""""""""""""""""""""""""""""""""""""""""""""""""" " jump to beginning and end of line easier nmap H ^ nmap L $ vmap H ^ vmap L $ " Smart way to move between windows nmap j nmap k nmap h nmap l " mapping to make movements operate on 1 screen line in wrap mode onoremap j ScreenMovement("j") onoremap k ScreenMovement("k") onoremap 0 ScreenMovement("0") onoremap ^ ScreenMovement("^") onoremap $ ScreenMovement("$") nnoremap j ScreenMovement("j") nnoremap k ScreenMovement("k") nnoremap 0 ScreenMovement("0") nnoremap ^ ScreenMovement("^") nnoremap $ ScreenMovement("$") xnoremap j ScreenMovement("j") xnoremap k ScreenMovement("k") xnoremap 0 ScreenMovement("0") xnoremap ^ ScreenMovement("^") xnoremap $ ScreenMovement("$") """""""" "" Plugin options """""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""" NERDTree let g:NERDTreeQuitOnOpen = 1 " close sidebar after we go to selection """"""""" Gundo let g:gundo_width = 30 let g:gundo_preview_height = 12 let g:gundo_preview_bottom = 1 """"""""" Powerline set rtp+=~/dotfiles/powerline/powerline/powerline/bindings/vim set noshowmode " don't show e.g. --INSERT-- since we're using powerline """"""""" Tagbar let g:tagbar_autoclose = 1 " close sidebar after we go to selection """"""""" EasyGrep let g:EasyGrepCommand = 1 " don't use the built in vimgrep, which is slow " Caveat about using ack: cannot search unsaved changes in buffer, unlike vimgrep let g:EasyGrepJumpToMatch = 0 let g:EasyGrepHighlightQfMatches = 1 let g:EasyGrepRecursive = 1 " always start trying to recurse through directories """"""""" Indent Guides let g:indent_guides_enable_on_vim_startup = 1 let g:indent_guides_auto_colors = 0 """"""""" SuperTab let g:SuperTabDefaultCompletionType = 'context' """"""""" Syntastic let g:syntastic_auto_jump = 1 """"""""" CtrlP let g:ctrlp_working_path_mode = 'rw' let g:ctrlp_user_command = { \ 'types': { \ 1: ['.git', 'cd %s && git ls-files'], \ 2: ['.hg', 'hg --cwd %s locate -I .'] \ }, \ 'fallback': 'find %s -type f' \ } """"""""" Vdebug let g:vdebug_options = { \ 'break_on_open' : 0, \ 'watch_window_style' : 'compact', \ 'path_maps' : {"/usr": "/jails/alcatraz/usr"} \ } """"""""" Vim Markdown let g:vim_markdown_folding_disabled = 1 """"""""" Sparkup let g:sparkupNextMapping = 'n' """""""" "" Functions """""""""""""""""""""""""""""""""""""""""""""""""""""""" function! FoldText() let line = getline(v:foldstart) let indent = indent(v:foldstart) let indentOnly = strpart(line, 0, indent-1) let linecount = v:foldend+1 - v:foldstart let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)' return foldtext endfunction function! ToggleMouse() if &mouse == 'a' set mouse= echo "Mouse usage disabled" else set mouse=a echo "Mouse usage enabled" endif endfunction function! ScreenMovement(movement) if &wrap return "g" . a:movement else return a:movement endif endfunction function! ClearSearch() if (@/ != "") let @/="" redraw endif endfunction function! CycleKeymap() if has('keymap') if (&keymap == '') set keymap=colemak echo "Colemak keymap selected" elseif (&keymap == 'colemak') set keymap=dvorak echo "Dvorak keymap selected" else set keymap= echo "Qwerty keymap selected" endif else echo "Keymaps not supported" endif endfunction function! MapQfPrevNext() " jump to the next/previous instance in Quickfix window exec "nmap :cprev" exec "nmap :cnext" endfunction function! UnmapQfPrefNext() exec "nunmap " exec "nunmap " endfunction