Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created May 3, 2011 20:15
Show Gist options
  • Save tcrayford/954130 to your computer and use it in GitHub Desktop.
Save tcrayford/954130 to your computer and use it in GitHub Desktop.
le vimrc
set nocompatible
filetype off
silent! call pathogen#runtime_append_all_bundles()
filetype plugin indent on
runtime macros/matchit.vim
set hidden
set autoread
set nobackup
set noswapfile
set nowritebackup
set number
set ignorecase
set smartcase
set cmdheight=2
set t_Co=256
let mapleader = " "
map <leader>e :e <C-R>=expand("%:h")<cr>/
map <leader>r :r <C-R>=expand("%:h")<cr>/
" Go to previous file
nnoremap <leader><leader> <c-^>
" Open a new vsplit window and switch to it
nnoremap <leader>w <C-w>v<C-w>l
nmap <silent> <leader>v :tabe $MYVIMRC<CR>
" Copy current visual selection to osx clipboard
map <silent> <leader>y :<C-u>silent '<,'>w !pbcopy<CR>
map <leader>n :cn <CR>
map <leader>p :cp <CR>
" Seriously, who ever actually uses '
nnoremap ' `
nnoremap ` '
nnoremap j gj
nnoremap k gk
"Seriously, guys. It's not like :W is bound to anything anyway.
command! W :w
command! Q :q
command! Wall :wall
" Tab in visual mode bounces between being at the start and at the end
vnoremap <tab> o
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=1000 " keep 1000 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" Make tab completion for files/buffers act like bash
set wildmenu
set completeopt=longest,menu
" Softtabs, 2 spaces
set tabstop=2
set shiftwidth=2
set expandtab
set softtabstop=2
set smarttab
set hlsearch
set cursorline
set numberwidth=5
syntax enable
set background=dark
colorscheme solarized
if has("autocmd")
augroup vimrcEx
au!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif
" Remap the tab key to do autocompletion or indentation depending on the
" context (from http://www.vim.org/tips/tip.php?tip_id=102)
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
autocmd BufNewFile,BufRead *.lua compiler lua_assert
autocmd BufNewFile,BufRead *.less set filetype=css
set statusline=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
set laststatus=2
" Map keys to go to specific files
map <leader>gr :topleft :split config/routes.rb<cr>
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 <leader>gR :call ShowRoutes()<cr>
map <leader>gd :topleft 100 :split spec/todo_spec.rb<cr>
:nnoremap <CR> :nohlsearch<cr>
" Ensure vim always runs from a shell, rvm needs this.
set shell=/bin/sh
" In these functions, we don't use the count argument, but the map referencing
" v:count seems to make it work. I don't know why.
" You can't see it on github, but there are raw character codes below
function! ScrollOtherWindowDown(count)
normal! 
normal! 
normal! 
endfunction
function! ScrollOtherWindowUp(count)
normal! 
normal! 
normal! 
endfunction
nnoremap g<c-y> :call ScrollOtherWindowUp(v:count)<cr>
nnoremap g<c-e> :call ScrollOtherWindowDown(v:count)<cr>
:inoremap <c-c> 
set winwidth=84
set scrolloff=2
set shiftround
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment