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 " mouse support. TODO: Are there any checks we should be doing? set ttymouse=xterm2 set mouse=a 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 """""""" "" UI - Colours """""""""""""""""""""""""""""""""""""""""""""""""""""" syntax enable colorscheme solarized set t_Co=16 set background=dark set colorcolumn=+1 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=MyFoldText() function! MyFoldText() 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 """""""" "" 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 " Toggle numbering nmap n :set number! " Toggle wrap nmap w :set wrap! " Toggle paste with/without indenting nmap p :set paste! paste? " Toggle showing whitespace characters nmap l :set list! " Toggle scrollbind for moving multiple splits in sync together nmap s :set scrollbind! scrollbind? " Toggle NERDTree instead of the normal dir browser... Doesn't seem to work yet nmap d :NERDTreeToggle " Toggle Commenting out lines with NERDCommenter nnoremap , :call NERDComment("n", "toggle") vnoremap , :call NERDComment("x", "toggle") " Vim's Undo Tree with Gundo! nnoremap u :GundoToggle " Search with ack! nnoremap a :Ack nnoremap A :Ack -a vnoremap a :Ack vnoremap A :Ack -a " 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 """""""" "" Key Remaps - Movement and Windows """""""""""""""""""""""""""""""""""""""""""""""""""""""" " jump to beginning and end of line easier nmap H ^ nmap L $ " Smart way to move btw. windows nmap j nmap k nmap h nmap l " mapping to make movements operate on 1 screen line in wrap mode function! ScreenMovement(movement) if &wrap return "g" . a:movement else return a:movement endif endfunction 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'