"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " General settings """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Point to pathogen autoload file runtime bundle/vim-pathogen/autoload/pathogen.vim " Load pathogen bundled plugins execute pathogen#infect() " Turn on syntax highlighting syntax on " Load ftplugins and indent files filetype plugin indent on " Break away from old vi compatibility set nocompatible " Use X11 clipboard for yank and paste set clipboard=unnamedplus " Change the mapleader from \ to , let mapleader = "," " Avoid annoying CSApprox warning message let g:CSApprox_verbose_level = 0 " Allow backspacing over everything in insert mode set backspace=indent,eol,start " Set command line history limit set history=1000 " Show the cursor position all the time set ruler " Show incomplete commands at the bottom set showcmd " Show current mode at the bottom set showmode " Highlight search matches set hlsearch " Highlight search match as you type set incsearch " Display line numbers set number " Display ... as wrap break set showbreak=... " Proper wrapping set wrap linebreak nolist " Add some line space for easy reading set linespace=4 " Disable visual bell set visualbell t_vb= " Gvim if has("autocmd") && has("gui") au GUIEnter * set t_vb= endif " Turn off toolbar on GVim set guioptions-=T " Store temporary files in a central spot set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp " Indentation settings set shiftwidth=2 set softtabstop=2 set expandtab set autoindent " Folding settings set foldmethod=indent " Set deepest folding to 3 levels set foldnestmax=3 " Don't fold by default set nofoldenable " Activate TAB auto-complete for file paths set wildmode=longest,list " Make tab completion for files/buffers act like bash set wildmenu " Make searches case-sensitive only if they contain upper-case characters set ignorecase set smartcase " Vertical/horizontal scroll off settings set scrolloff=3 set sidescrolloff=7 set sidescroll=1 " Some stuff to get the mouse going in term " set mouse=a " set ttymouse=xterm2 " Allow backgrounding buffers without saving them set hidden " Max 80 chars per line set colorcolumn=81 " Colorscheme if has("gui_running") " Tell the term has 256 colors set t_Co=256 set term=gnome-256color colorscheme railscasts " solarized " colorscheme solarized " syntax enable " set background=light " set background=dark else set term=xterm-256color colorscheme jellybeans " solarized " colorscheme solarized " let g:solarized_termcolors=256 " syntax enable " set background=dark " set background=light endif " Use Ack instead of grep let g:ackprg="ack-grep -H --nocolor --nogroup --column" set grepprg=ack """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Mappings """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Select last paste in visual mode nnoremap gb '`[' . strpart(getregtype(), 0, 1) . '`]' " Use :w!! to write to a file using sudo if you forgot to "sudo vim file" cmap w!! %!sudo tee > /dev/null % " Window navigation map h map j map k map l " Tab navigation noremap gT noremap gt " Map ESC imap jj imap " Switch between last two buffers nnoremap " Go to vim shell map sh :sh " Disable arrow keys map :echo "no!" map :echo "no!" map :echo "no!" map :echo "no!" " Make & trigger :&& so it preserves flags nnoremap & :&& xnoremap & :&& " Paste last yanked text map "0p " Edit/View files relative to current directory cnoremap %% =expand('%:h').'/' map re :edit %% map rv :view %% " Ctags nnoremap :!ctags -R --exclude=.git --exclude=log * " View routes or Gemfile in large split map gr :topleft :split config/routes.rb map gg :topleft :split Gemfile " map gg :topleft 100 :split Gemfile " Scenario Outline align vmap :Align \| " insert => imap => " Switch between buffers noremap :bn noremap :bp " Close buffer nmap bd :bprevious:bdelete # " Close all buffers nmap bD :bufdo bd " Clear the search buffer when hitting return :nnoremap :nohlsearch " xnoremap - mappings should apply to Visual mode, but not to Select mode xnoremap * :call VSetSearch()/=@/ xnoremap # :call VSetSearch()?=@/ " Generate html from the file with syntax highligh nmap ss :runtime! syntax/2html.vim " Execute current ruby file nmap E :!ruby % " Open vimrc file map v :e ~/.vim/vimrc " Personal dropbox mappings map di :e ~/Dropbox/notes/improve.txt map dt :e ~/Dropbox/notes/todo.txt " map dp :sp ~/Dropbox/notes/project-notes.txt map dn :CtrlP ~/Dropbox/notes/ map dp :CtrlP ~/Dropbox/projects/ " Automatically execute ctags each time a file is saved " autocmd BufWritePost * call system("ctags -R") " Source the vimrc file after saving it " if has("autocmd") " autocmd BufWritePost vimrc source $MYVIMRC " endif """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Statusline setup """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set statusline=%f "tail of the filename " set statusline+=%h "help file flag " set statusline+=%y "filetype " set statusline+=%r "read only flag " set statusline+=%m "modified flag " Display a warning if &et is wrong, or we have mixed-indenting set statusline+=%#error# set statusline+=%{StatuslineTabWarning()} set statusline+=%* set statusline+=%{StatuslineTrailingSpaceWarning()} set statusline+=%= "left/right separator set statusline+=%c, "cursor column set statusline+=%l/%L "cursor line/total lines set statusline+=\ %P "percent through file set laststatus=2 "recalculate the trailing whitespace warning when idle, and after saving autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning "return '[\s]' if trailing white space is detected "return '' otherwise function! StatuslineTrailingSpaceWarning() if !exists("b:statusline_trailing_space_warning") if search('\s\+$', 'nw') != 0 let b:statusline_trailing_space_warning = '[\s]' else let b:statusline_trailing_space_warning = '' endif endif return b:statusline_trailing_space_warning endfunction "recalculate the tab warning flag when idle and after writing autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning "return '[&et]' if &et is set wrong "return '[mixed-indenting]' if spaces and tabs are used to indent "return an empty string if everything is fine function! StatuslineTabWarning() if !exists("b:statusline_tab_warning") let tabs = search('^\t', 'nw') != 0 let spaces = search('^ ', 'nw') != 0 if tabs && spaces let b:statusline_tab_warning = '[mixed-indenting]' elseif (spaces && !&et) || (tabs && &et) let b:statusline_tab_warning = '[&et]' else let b:statusline_tab_warning = '' endif endif return b:statusline_tab_warning endfunction """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Tabular """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" nmap t= :Tabularize /= vmap t= :Tabularize /= nmap t: :Tabularize /:\zs vmap t: :Tabularize /:\zs """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " CtrlP """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set runtimepath^=~/.vim/bundle/ctrlp.vim let g:ctrlp_map = '' let g:ctrlp_match_window_bottom = 0 let g:ctrlp_match_window_reversed = 0 set runtimepath^=~/.vim/bundle/ctrlp.vim set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.jpg,*.gif,*.png,*.pdf let g:ctrlp_custom_ignore = { \ 'dir': '\.git$\|\.hg$\|\.svn$', \ 'file': '\.png$\|\.gif$\|\.jpg$', \ } """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " NERDTree """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let NERDTreeShowBookmarks = 0 let NERDChristmasTree = 1 let NERDTreeWinPos = "left" let NERDTreeHijackNetrw = 1 "let NERDTreeQuitOnOpen = 1 let NERDTreeWinSize = 40 map p :NERDTreeToggle " Open NERDTree by default "autocmd VimEnter * NERDTree "autocmd VimEnter * wincmd p """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " rails.vim """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map rg :Rgenerate map rd :Rdestroy map em :Emodel map ev :Eview map ec :Econtroller map eh :Ehelper map el :Elib map er :Emailer map ej :Ejavascript map es :Estylesheet map ey :Elayout map ee :Eenvironment map ei :Einitializer map ew :Emigration map ed :Eschema map ef :Efixtures map eu :Eunittest map et :Efunctionaltest " :Espec " :Elocale " :Etask " :Eintegrationtest """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Vimux """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map Tt SendTestToTmux map TT SendFocusedTestToTmux map at :call VimuxRunCommand('bundle exec rspec --color') let g:VimuxHeight = "55" let g:VimuxOrientation = "h" " Prompt forca command to run map rp :PromptVimTmuxCommand " Run last ccmmand executed by RunVimTmuxCommand map rl :RunLastVimTmuxCommand " Inspect runner pane map ri :InspectVimTmuxRunner " Close all other tmux panes in current window map rc :CloseVimTmuxPanes " Interrupt any command running in the runner pane map rs :InterruptVimTmuxRunner """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Vroom """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:vroom_use_bundle_exec = 0 " don't use bundle exec let g:vroom_spec_command = 'spring rspec' let g:vroom_map_keys = 0 " don't use default mapping r and R map rr :VroomRunTestFile map rR :VroomRunNearestTest " let g:vroom_use_vimux = 1 " use vimux """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Test mapping """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " nmap ,rr :w\|!rspec spec/file_spec.rb """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " EasyMotion """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:EasyMotion_leader_key = '' hi link EasyMotionTarget ErrorMsg hi link EasyMotionShade Comment """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Javascript """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " configured used javascript libs let g:used_javascript_libs = 'angularjs' """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Functions """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Search for string in files function! AckGrep() normal ebvey exec ":Ack " . @" endfunction map ag :call AckGrep() nmap af :Ack " Jump to last cursor position when opening a file except when writing a commit log entry autocmd BufReadPost * call SetCursorPosition() function! SetCursorPosition() if &filetype !~ 'commit\c' if line("'\"") > 0 && line("'\"") <= line("$") exe "normal! g`\"" normal! zz endif end endfunction " Strip trailing whitespace function! StripTrailingWhitespaces() " Preparation: save last search, and cursor position. let _s=@/ let l = line(".") let c = col(".") " Do the business: %s/\s\+$//e " Clean up: restore previous search history, and cursor position let @/=_s call cursor(l, c) endfunction " autocmd BufWritePre * :call StripTrailingWhitespaces() " autocmd BufWritePre *.rb :call StripTrailingWhitespaces() autocmd FileType c,cpp,scss,css,html,erb,java,php,ruby,python,javascript autocmd BufWritePre :call StripTrailingWhitespaces() nnoremap cs :call StripTrailingWhitespaces() " Show routes function! ShowRoutes() " Requires 'scratch' plugin :topleft 100 :split __Routes__ " Make sure Vim doesn't write __Routes__ as a file :set buftype=nofile " Delete everything :normal 1GdG " Put routes output in buffer :0r! rake -s routes " Size window to number of lines (1 plus rake output length) :exec ":normal " . line("$") . "_ " " Move cursor to bottom :normal 1GG " Delete empty trailing line :normal dd endfunction map gR :call ShowRoutes() " Snipmate setup source ~/.vim/snippets/support_functions.vim autocmd vimenter * call s:SetupSnippets() function! s:SetupSnippets() "if we're in a rails env then read in the rails snippets if filereadable("./config/environment.rb") call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby") call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby") endif call ExtractSnips("~/.vim/snippets/html", "eruby") call ExtractSnips("~/.vim/snippets/html", "xhtml") endfunction " Work-around to copy selected text to system clipboard " and prevent it from clearing clipboard when using ctrl + z (depends on xsel) function! CopyText() normal gv"+y :call system('xsel -ib', getreg('+')) endfunction vmap y :call CopyText() " Search for the current selection function! s:VSetSearch() let temp = @s norm! gv"sy let @/ = '\V' . substitute(escape(@s, '/\'), '\n', '\\n', 'g') let @s = temp endfunction " Populate the argument list with each of the files named in the quickfix list function! QuickfixFilenames() let buffer_numbers = {} for quickfix_item in getqflist() let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr']) endfor return join(map(values(buffer_numbers), 'fnameescape(v:val)')) endfunction command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames() " Rename current file function! RenameFile() let old_name = expand('%') let new_name = input('New file name: ', expand('%'), 'file') if new_name != '' && new_name != old_name exec ':saveas ' . new_name exec ':silent !rm ' . old_name redraw! endif endfunction map rf :call RenameFile() " Promote variable to RSpec let function! PromoteToLet() :normal! dd " :exec '?^\s*it\>' :normal! P :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/ :normal == endfunction :command! PromoteToLet :call PromoteToLet() :map let :PromoteToLet function! OpenURL(url) if has("win32") exe "!start cmd /cstart /b ".a:url."" elseif $DISPLAY !~ '^\w' exe "silent !sensible-browser \"".a:url."\"" else exe "silent !sensible-browser -T \"".a:url."\"" endif redraw! endfunction command! -nargs=1 OpenURL :call OpenURL() nnoremap gu :OpenURL nnoremap gG :OpenURL http://www.google.com/search?q= nnoremap gU :OpenURL http://www.urbandictionary.com/define.php?term= " function! ExtractVar() " normal ^*`` " normal ww " normal "zDdd`` " normal cwz " endfunction " map ,gt :call ExtractVar() function! ViewHtmlText(url) if !empty(a:url) new setlocal buftype=nofile bufhidden=hide noswapfile execute 'r !elinks ' . a:url . ' -dump -dump-width ' . winwidth(0) 1d endif endfunction " Save and view text for current html file. nnoremap H :updatecall ViewHtmlText(expand('%:p')) " View text for visually selected url. vnoremap h y:call ViewHtmlText(@@) " View text for URL from clipboard. " On Linux, use @* for current selection or @+ for text in clipboard. nnoremap h :call ViewHtmlText(@+)