Skip to content

Instantly share code, notes, and snippets.

@jacobsimeon
Created February 15, 2013 18:11
Show Gist options
  • Save jacobsimeon/4962209 to your computer and use it in GitHub Desktop.
Save jacobsimeon/4962209 to your computer and use it in GitHub Desktop.
vimrc
call pathogen#infect()
filetype plugin indent on
"indentation
set tabstop=2 shiftwidth=2 expandtab
set cindent
set smartindent
set autoindent
set nowrap
set number
" save buffers, etc
set hidden
" enable persisten undo
if exists("+undofile")
set udf
set undodir=~/.vimundo
endif
" display settings
set guifont=Consolas:h10
syntax on
set background=dark
colorscheme solarized
"not really sure
runtime! macros/matchit.vim
" filetype syntax modes
au BufRead,BufNewFile {Capfile,.autotest,Gemfile,Rakefile,Thorfile,config.ru,.caprc,.irbrc,irb_tempfile*} set ft=ruby
augroup myfiletypes
" Clear old autocmds in group
autocmd!
" autoindent with two spaces, always expand tabs
autocmd FileType ruby,eruby,yaml set ai sw=2 sts=2 et
augroup END
" don't show menu/toolbars
if has("gui_running")
set guioptions=egmrt
endif
" move between screens
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" use capitals to move to beginning and end of lines
nnoremap L $
nnoremap H ^
vnoremap L $
vnoremap H ^
" use jk to get out of insert mode
inoremap jk <Esc>
inoremap JK <Esc>
" wrap selection in given character
function! Quote(quote)
let save = @"
silent normal gvy
let @" = a:quote . @" . a:quote
silent normal gvp
let @" = save
endfunction
" single quote selected text
vmap <silent> <Leader>qs :call Quote("'")<CR>
" double quote selected text
vmap <silent> <Leader>qd :call Quote('"')<CR>
" use system clipboard
set clipboard=unnamed
" ignore case in searches
set ic
" override ignore case when string contains capitals
set scs
" remap leader to comma
let mapleader = ","
" select all
map <Leader>a ggVG
" 80 characters color column
if exists('+colorcolumn')
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
" highlight trailing whitespace
highlight WhitespaceEOL ctermbg=Red guibg=Red
match WhitespaceEOL /\s\+$/
" remove trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<cr>
" remove whitespace before save
autocmd BufWritePre {*.rb,*.js,*.coffee,*.scss,*.haml} :%s/\s\+$//e
" use arrow keys to move back and forth between buffers
nmap <up> :bp<CR>
nmap <down> :bn<CR>
nmap <left> :tabp<CR>
nmap <right> :tabn<CR>
" insert blank lines without going into insert mode
nmap t o<ESC>k
nmap T O<ESC>j
" quickly open and source vimrc
nnoremap <Leader>vv :e $MYVIMRC<CR>
nnoremap <Leader>ss :source $MYVIMRC<Bar>:source $MYVIMRC<CR>
" find merge conflict markers
nmap <silent> <leader>cf <ESC>/\v^[<=>]{7}( .*\|$)<CR>
" update open files automatically when edited externally
set autoread
" listmethods in obj-c files
map <leader>l :ListMethods
" quickopen obj-c documentation
map <leader>d :exec("CocoaDoc ".expand("<cword>"))<CR>
" function to loop through a specified path and include each tag file
if has('python')
function! BuildTagsFromPath()
python << EOF
import os
import vim
tags = ''
tagpath = "%s/%s" % (os.environ['HOME'], '.vimtags')
if (os.path.exists(tagpath)):
for file in os.listdir(tagpath):
if (file != 'README'):
tags += "%s/%s," % (tagpath, file)
cmdsettags = "set tags=%s" % tags
vim.command(cmdsettags)
EOF
endfunction
call BuildTagsFromPath()
endif
" open obj-c counterpart
let g:alternateExtensions_m = "h"
let g:alternateExtensions_h = "m"
map <leader>s :A
" tab for autocomplete
function! SuperCleverTab()
if strpart(getline('.'), 0, col('.') - 1) =~ '^\s*$'
return "\<Tab>"
else
if &omnifunc != ''
return "\<C-X>\<C-O>"
elseif &dictionary != ''
return "\<C-K>"
else
return "\<C-N>"
endif
endif
endfunction
inoremap <Tab> <C-R>=SuperCleverTab()<cr>
" search google for selected text
function! GoogleSearch()
let searchterm = getreg("g")
silent! exec "silent! !open \"http://google.com/search?q=" . searchterm . "\" &"
endfunction
vnoremap ?? "gy<Esc>:call GoogleSearch()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment