Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 345 lines (270 sloc) 10.356 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
set nocompatible " Don't sacrifice anything for Vi compatibility.
set encoding=utf-8 " In case $LANG doesn't have a sensible value.

" pathogem.vim lets us keep plugins etc in their own folders under ~/.vim/bundle.
" http://www.vim.org/scripts/script.php?script_id=2332
" filetype off and then on again afterwards for ftdetect files to work properly.
filetype off
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()

filetype plugin indent on " Load plugin and indent settings for the detected filetype.
syntax on " Syntax highlighting.
set t_Co=256
color jellybeans+ " Default color scheme.
set number " Show gutter with line numbers.
set ruler " Show line, column and scroll info in status line.
set laststatus=2 " Always show status bar.
set modelines=1 " Use modeline overrides.
set showcmd " Show partially typed command sequences.
set scrolloff=3 " Minimal number of lines to always show above/below the caret.

set wrap " Soft wrap.
" Would use lbr for nicer linebreaks, but can't combine with listchars.

" 2 spaces indent.
set softtabstop=2
set shiftwidth=2
set expandtab

" Autoindent with =
set autoindent

" Show invisibles.
set listchars=nbsp:·,tab:▸\ ,trail:·
set list!

" Highlight current line
" Makes vip take 100% and slow down in some files.
"set cursorline

" No pipes in vertical split separators.
set fillchars=vert:\

" Diff colors
" Dark red
hi DiffText term=reverse cterm=bold ctermbg=88
" Dark blue
hi DiffChange term=bold ctermbg=17
" Dark gray, lighter gray
hi DiffDelete term=bold ctermbg=234 ctermfg=235
" Dark green
hi DiffAdd term=bold ctermbg=22

" Searching.
set hlsearch " Highlight results.
set incsearch " Search-as-you-type.

" Case insensitve search/replace is not productive
"set ignorecase " Case-insensitive…
"set smartcase " …unless phrase includes uppercase.

set gdefault " Global search by default; /g for first-per-row only.

set nojoinspaces " 1 space, not 2, when joining sentences.
set backspace=indent,eol,start " Allow backspacing over everything in insert mode.

" Don't break words when wrapping
set nolist
set lbr

" NERDTree configuration
let NERDTreeIgnore=['\.rbc$', '\~$']

" Command-T configuration
let g:CommandTMaxHeight=20
let g:CommandTMatchWindowAtTop=1

" Ctrl-P
let g:ctrlp_match_window_bottom = 0
let g:ctrlp_match_window_reversed = 0
let g:ctrlp_max_height = 20
let g:ctrlp_show_hidden = 0
let g:ctrlp_max_files = 0
let g:ctrlp_switch_buffer = 0

" Don't let ctrlp change the working directory. Instead it now uses
" the directory where vim was started. This fixes issues with some
" projects that has nested git directories.
let g:ctrlp_working_path_mode = 0

" Files to skip.
set wildignore+=*.o,*.obj,.git,tmp
set wildignore+=public/uploads,db/sphinx,vim/backup
set wildignore+=public/uploads
set wildignore+=tmp/
set wildignore+=data/

" Workaround 'E854: path too long for completion' for now
" http://stackoverflow.com/questions/9590658/vim-e854-path-too-long-for-completion
set complete-=i

" Reload files changed outside the editor (for example by switching git branch)
" If a file is changed in two editors, but then only saved in one it will
" still generate a warning.
set autoread

" Automatically save changes before switching buffer with some
" commands, like :cnfile.
set autowrite

" Make terminal Vim trigger autoread more often.
au WinEnter,BufWinEnter,CursorHold * checktime

" 'Edit anyway' if swap file exists.
au SwapExists * let v:swapchoice = 'e'

" Highlight trailing whitespace
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()

" Remember last location in file, but not for commit messages.
if has("autocmd")
  au BufReadPost * if &filetype !~ 'commit\c' && line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif

if !exists("*s:setupWrapping")
  function s:setupWrapping()
    set wrap
    set wm=2
    set textwidth=72
  endfunction
endif

if !exists("*s:setupMarkup")
  function s:setupMarkup()
"call s:setupWrapping()
    map <buffer> <Leader>p :Mm <CR>
  endfunction
endif

" OS X only due to use of `open`. Adapted from
" http://vim.wikia.com/wiki/Open_a_web-browser_with_the_URL_in_the_current_line
" Uses John Gruber's URL regexp: http://daringfireball.net/2010/07/improved_regex_for_matching_urls
if has("ruby")
ruby << EOF
  def open_uri
    re = %r{(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\))+(?:\((?:[^\s()<>]+|(?:\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))}

    line = VIM::Buffer.current.line
    urls = line.scan(re).flatten

    if urls.empty?
      VIM::message("No URI found in line.")
    else
      system("open", *urls)
      VIM::message(urls.join(" and "))
    end
  end
EOF
endif

if !exists("*OpenURI")
  function! OpenURI()
    :ruby open_uri
  endfunction
endif

if has("autocmd")
" make and python use real tabs
  au FileType make set noexpandtab
  au FileType python set noexpandtab

" Ruby
  au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru,VagrantFile,Guardfile} set ft=ruby

" Javascript
  au BufRead,BufNewFile {*.json} set ft=javascript

" Javascript haml templates
  au BufRead,BufNewFile {*.jst.hamlc} set ft=haml

" md, markdown, and mk are markdown and define buffer-local preview
  au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()

" arduino source files
  au BufRead,BufNewFile {*.pde} set ft=cpp

" Uncomment to have txt files hard-wrap automatically.
"au BufRead,BufNewFile *.txt call s:setupWrapping()
endif

" Hit S in command mode to save, as :w<CR> is a mouthful and MacVim
" Command-S is a bad habit when using terminal Vim.
" We overload a command, but use 'cc' instead anyway.
noremap S :w<CR>

" Make Y consistent with C and D - yank to end of line, not full line.
nnoremap Y y$

" Map Q to something useful (e.g. QQ to hard-break current line).
" Otherwise Q enters the twilight zone of the 'Ex' mode.
noremap Q gq

" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") . "/" <CR>

" Move by screen lines instead of file lines.
" http://vim.wikia.com/wiki/Moving_by_screen_lines_instead_of_file_lines
noremap <Up> gk
noremap <Down> gj
noremap k gk
noremap j gj

" Seriously, why isn't this set by default
cmap WQ wq
cmap Wq wq
"cmap W w
"cmap Q q

" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e
" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv

" Tab/shift-tab to indent/outdent in visual mode.
vmap <Tab> >gv
vmap <S-Tab> <gv

" Directories for swp files
set backupdir=~/.vim/backup
set directory=~/.vim/backup

" Leader
let mapleader = ","

" Un-highlight search matches
nnoremap <leader><leader> :noh<CR>

map <leader>n :NERDTreeToggle<CR>
map <leader>N :NERDTreeFind<CR>" Reveal current file

" Open URL from this line (OS X only).
map <leader>u :call OpenURI()<CR>

" Ack/Quickfix windows
map <leader>q :cclose<CR>
map - :cprev<CR> :norm! zz<CR>" Previous fix and center line.
map + :cnext<CR> :norm! zz<CR>" Next fix and center line.

" Center line in previous/next file.
map g- :cpfile<CR> zz
map g+ :cnfile<CR> zz
map g= :cnfile<CR> zz

" Reload vim config
map <Leader>r :source $MYVIMRC<CR>

" Create a split on the given side.
" From http://technotales.wordpress.com/2010/04/29/vim-splits-a-guide-to-doing-exactly-what-you-want/ via joakimk.
nmap <leader><left> :leftabove vsp<CR>
nmap <leader><right> :rightbelow vsp<CR>
nmap <leader><up> :leftabove sp<CR>
nmap <leader><down> :rightbelow sp<CR>

" Get rid of all NERDCommenter mappings except one.
let g:NERDCreateDefaultMappings=0
map <leader>c <Plug>NERDCommenterToggle

" Use nearest split and not a new one
let g:VimuxUseNearestPane = 1

" Remap turbux to not collide with ctrlp
let g:no_turbux_mappings = 1

map <leader>m <Plug>SendTestToTmux

map <leader>M <Plug>SendFocusedTestToTmux

" Support command-t style shortcuts for a while
map <leader>t :CtrlP<CR>

" Trying out different mappings, can't get used to henriks <leader><shift>m thing.
map <leader>l <Plug>SendFocusedTestToTmux
map m <Plug>SendFocusedTestToTmux
map M <Plug>SendTestToTmux

" Control rubymotion from vim
map <Leader>q :call VimuxInterruptRunner()<CR>
map <Leader>w :call VimuxRunCommand("clear; rake simulator")<CR>
map <Leader>e :call VimuxRunCommand("clear; rake device")<CR>

" Map ctrl-s to save
nmap <c-s> :w<CR>
imap <c-s> <Esc>:w<CR>a
imap <c-s> <Esc><c-s>

" Run default task with "§" (usually runs all tests)
if filereadable("mix.exs")
  map § :call VimuxRunCommand("mix test")<CR>
else
  map § :call VimuxRunCommand("rake")<CR>
endif

" Stop commands with <leader>§
map <leader>§ :call VimuxInterruptRunner()<CR>

" GitGrep mapped to ,a
" http://henrik.nyh.se/2012/07/project-wide-search-and-replace-in-vim-with-qdo/
exe "nnoremap <leader>a :GitGrep "
exe "nnoremap <leader>d :Qdo "

" Be able to run some code to decide how to run a spec (with or without drb, etc)
let g:turbux_command_rspec = 'script/test'

" Fixes arrow keys when used within tmux
if &term =~ "screen"
  let g:CommandTCancelMap = ['<ESC>', '<C-c>']
  let g:CommandTSelectNextMap = ['<C-n>', '<C-j>', '<ESC>OB']
  let g:CommandTSelectPrevMap = ['<C-p>', '<C-k>', '<ESC>OA']
endif

" Support .slimbars (handlebars templates using slim)
autocmd BufNewFile,BufRead *.slimbars set filetype=slimbars
autocmd FileType slimbars set tabstop=2|set shiftwidth=2|set expandtab

" Turn RSpec 'should' into the new 'expect' style.
" Also turns 'should ==' into 'expect(…).to eq'.
" The command acts on the current line or in a given range (e.g. visual range).

function! s:ShouldToExpect()
  .s/^\(\s\+\)\(.\+\)\.should\>/\1expect(\2).to/e
  .s/^\(\s\+\)\(.\+\)\.should_not\>/\1expect(\2).not_to/e
  .s/\(expect(.\+)\.\(to\|not_to\)\) ==/\1 eq/e
endfunction

command! -range Expect execute '<line1>,<line2>call <SID>ShouldToExpect()'
Something went wrong with that request. Please try again.