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 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 term=none cterm=none ctermfg=darkred ctermbg=none "set colour for folded lines """""""" "" UI - Numbering """""""""""""""""""""""""""""""""""""""""""""""""""""""" set number " show line numbers "set relativenumber " current line always 0 (requires 7.3 and up) set laststatus=2 " status line is second last line (not hidden by commands) set statusline=%f\ " short filepath set statusline+=%h " help flag set statusline+=%w " preview flag set statusline+=%r " read-only flag set statusline+=%m " modified flag set statusline+=%= " left-right aligned item separator "set statusline+=Chr:%B/%b " character value under cursor set statusline+=%{fugitive#statusline()} if exists("*strftime") set statusline+=\ \ %{strftime('%a\ %d\ %b\ %H:%M')} endif set statusline+=\ \ %-14(Line:%l/%L%) set statusline+=%-11(Col:%c%V%) set statusline+=Scroll:%P """""""" "" 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 file browser 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 " Git blame with Fugitive! nnoremap b :Gblame """""""" "" 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 """""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""" NERDTree let g:NERDTreeQuitOnOpen = 1 if s:uname == "Darwin" let g:NERDTreeDirArrows=0 " Problems showing NERDTree arrows in OS X endif """"""""" Gundo let g:gundo_width = 30 let g:gundo_preview_height = 12 let g:gundo_preview_bottom = 1 """"""""" Surround "let g:loaded_surround = 1 " Disable tpope's surround let g:did_surrounding = 1 " Disable msander's surrounding (surround fork) """"""""" HTML Autoclose Tag " We are instead trying out sparkup let g:mapped_auto_closetag = 1 " Disable html autoclose plugin let g:did_auto_closetag = 1 " Disable html autoclose plugin """""""" "" 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 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