set nocompatible "Don't have to try to be compatible with old vi """""""" "" Plugin Loading with Pathogen """"""""""""""""""""""""""""""""""""""""""""""""""" call pathogen#infect() """""""" "" Environment """"""""""""""""""""""""""""""""""""""""""""""""""" " Determine what kind of machine we're on e.g. Linux, Darwin, Win(?) if has("unix") " remove the newline character from the uname command let s:uname = substitute(system("uname"), "\n", "", "") endif """""""" "" General Behaviours """"""""""""""""""""""""""""""""""""""""""""""""""" set autoread "Read a file if it's changed from outside of vim set splitbelow "New splits appear below current window instead of above set splitright "New splits appear right of current window set ttyfast "Smooth movement " Persistent undo if has("persistent_undo") set undofile set undodir=~/.vimundo endif set ttymouse=xterm2 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 autocmd BufReadPost * \ if line("'\"") > 0 && line ("'\"") <= line("$") | \ exe "normal! g'\"" | \ endif autocmd WinEnter * setlocal cursorline autocmd WinLeave * setlocal nocursorline " Source the vimrc file after saving it autocmd bufwritepost .vimrc source $MYVIMRC " A way to specify startup actions autocmd VimEnter * call StartUp() " if the last window is NERDTree, then close Vim "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif else set autoindent on endif """""""" "" Start Up """"""""""""""""""""""""""""""""""""""""""""""""""" function! StartUp() " Stuff in here will be called by autocmd below " example, start NERDTree if vim called with no arguments if 0 == argc() NERDTree end endfunction """""""" "" 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 indent set wrap lbr " wrap long lines of text set backspace=eol,start,indent "backspace over everything set textwidth=80 set colorcolumn=+1 " mark out the limits of the textwidth """""""" "" UI - Colours """""""""""""""""""""""""""""""""""""""""""""""""""""" syntax enable colorscheme solarized set t_Co=16 set background=dark hi Folded ctermfg=darkred "set colour for folded lines """""""" "" UI - Numbering """""""""""""""""""""""""""""""""""""""""""""""""""""""" set number "show line numbers set ruler "show row,col count in status line set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%) set laststatus=2 "always show a status line "set relativenumber "current line always 0 (requires 7.3 and up) """""""" "" 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 """""""" "" Key Remaps and Shortcuts """""""""""""""""""""""""""""""""""""""""""""""""""""""" let mapleader = "," "Leader key lets you make more kinds of shortcuts! " Edit .vimrc map v :e $MYVIMRC " More convenient escape imap ii imap II " Add extra lines up and down nmap j ok nmap k Oj nmap n :set number! nmap w :set wrap! " Toggle paste mode - no autoindenting of pasted material nmap p :set paste! paste? " Toggle visible whitespace characters nmap l :set list! " Toggle scrollbind for moving multiple splits in sync together nmap s :set scrollbind! scrollbind? " Toggle mouse support. nnoremap m :call ToggleMouse() " Toggle NERDTree instead of the normal dir browser... Doesn't seem to work yet nnoremap d :NERDTreeToggle " Toggle Commenting out lines with NERDCommenter nnoremap , :call NERDComment("n", "toggle") vnoremap , :call NERDComment("x", "toggle") " Traverse undo tree with Gundo! nnoremap u :GundoToggle " Search under cursor with ack! nnoremap a :Ack nnoremap A :Ack -a vnoremap a :Ack vnoremap A :Ack -a """""""" "" Key Remaps - Movement and Windows """""""""""""""""""""""""""""""""""""""""""""""""""""""" " jump to beginning and end of line easier nmap H ^ nmap 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("$") """""""" "" Plugin options """""""""""""""""""""""""""""""""""""""""""""""""""""""" " let g:NERDTreeQuitOnOpen = 1 " Having problems showing NERDTree arrows in OS X if s:uname == "Darwin" let g:NERDTreeDirArrows=0 endif " let g:SuperTabDefaultCompletionType = 'context' """""""" "" Functions, the Givers of Power (in order of use) """""""""""""""""""""""""""""""""""""""""""""""""""""""" 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 plural = "" if linecount != 1 let plural = "s" endif 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 " Colemak layout for INSERT mode only " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./ " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./ "inoremap e f "inoremap r p "inoremap t g "inoremap y j "inoremap u l "inoremap i u "inoremap o y "inoremap p ; "inoremap s r "inoremap d s "inoremap f t "inoremap g d "inoremap j n "inoremap k e "inoremap l i "inoremap ; o "inoremap n k "inoremap E F "inoremap R P "inoremap T G "inoremap Y J "inoremap U L "inoremap I U "inoremap O Y "inoremap P : "inoremap S R "inoremap D S "inoremap F T "inoremap G D "inoremap J N "inoremap K E "inoremap L I "inoremap : O "inoremap N K