Created
January 24, 2012 21:46
-
-
Save dialtone/1672908 to your computer and use it in GitHub Desktop.
My .vimrc file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set nocompatible " choose no compatibility with legacy vi | |
syntax enable | |
set encoding=utf-8 | |
set showcmd " display incomplete commands | |
filetype plugin indent on " load file type plugins + indentation | |
"" Whitespace | |
set nowrap " don't wrap lines | |
set tabstop=4 | |
set shiftwidth=4 " a tab is two spaces (or set this to 4) | |
set expandtab " use spaces, not tabs (optional) | |
set backspace=indent,eol,start " backspace through everything in insert mode | |
"" Various | |
set ruler " show position in status line | |
set cursorline " highlight current line | |
set number " line numbers | |
set list " show invisible chars | |
set listchars=tab:▸\ ,eol:¬,trail:·,extends:#,nbsp:· | |
set scrolloff=10 " unless not possible, don't reach the last line before scrolling | |
set visualbell " no sound | |
set t_vb= " and no sound | |
set antialias " better font | |
set clipboard=unnamed " Use the system clipboard | |
set laststatus=2 " basically enable vim status line | |
set autoread " autoreload files when there are no unsaved changes | |
"" Searching | |
set hlsearch " highlight matches | |
set incsearch " incremental searching | |
set ignorecase " searches are case insensitive... | |
set smartcase " ... unless they contain at least one capital letter | |
"" install pathogen | |
call pathogen#infect() | |
"" no backups | |
set nobackup | |
set nowritebackup | |
"set noswapfile | |
"set backupdir=~/.vim/_backup " where to put backup files. | |
set directory=~/.vim/_temp " where to put swap files. | |
"" use comma as <Leader> key instead of backslash | |
let mapleader="," | |
"" double percentage sign in command mode is expanded | |
"" to directory of current file - http://vimcasts.org/e/14 | |
cnoremap %% <C-R>=expand('%:h').'/'<cr> | |
" Go back to previous buffer | |
nnoremap <leader><leader> <c-^> | |
" Change buffer in the current split | |
map <m-d-left> :bprevious<cr> | |
map <m-d-right> :bNext<cr> | |
" Remap convenient vertical/horizontal split | |
map <leader>s :split<cr> | |
map <leader>v :vsplit<cr> | |
" Remap buffer delete | |
map `` :bd<cr> | |
" Remap autocomplete | |
inoremap <D-]> <c-n> | |
inoremap <D-[> <c-p> | |
" Remap moving between splits | |
nnoremap <c-j> <c-w>j | |
nnoremap <c-k> <c-w>k | |
nnoremap <c-h> <c-w>h | |
nnoremap <c-l> <c-w>l | |
colorscheme molokai | |
" take out the toolbar | |
set guioptions-=T | |
" Buffer history tree | |
nnoremap t :GundoToggle<CR> | |
" Wrap in certain cases. | |
function s:setupWrapping() | |
set wrap | |
set wrapmargin=2 | |
set textwidth=72 | |
endfunction | |
""" | |
""" | |
""" Given path to a directory find the project root for it | |
""" defined as the first directory to have a given marker | |
""" such as .git/.hg/_darcs/.bzr and so on. | |
function! s:findroot(curr, markers, depth) | |
" Search all markers in the current directory | |
for marker in a:markers | |
let found = !empty(globpath(a:curr, marker)) | |
if !found && a:depth > 40 | |
return '' | |
endif | |
if found | |
return a:curr | |
endif | |
endfor | |
" Increase depth | |
let depth = a:depth + 1 | |
" get the parent and recurse | |
let parent = s:getparent(a:curr) | |
if parent != a:curr | |
return s:findroot(parent, a:markers, depth) | |
endif | |
endfunction | |
function! s:getparent(item) | |
let parent = substitute(a:item, '[\/][^\/]\+[\/:]\?$', '', '') | |
if parent == '' || match(parent, '[\/]') < 0 | |
let parent .= '/' | |
endif | |
return parent | |
endf | |
function g:projectRoot(path) | |
let markers = ['root.dir','.git/','.hg/','_darcs/','.bzr/'] | |
let root = s:findroot(a:path, markers, 0) | |
if root == '' | |
return path | |
endif | |
return fnameescape(root) | |
endf | |
"""" | |
"""" | |
"" Some variants | |
if has("autocmd") | |
" In Makefiles, use real tabs, not tabs expanded to spaces | |
au FileType make set noexpandtab | |
" Make sure all markdown files have the correct filetype set and setup wrapping | |
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn,txt} setf markdown | call s:setupWrapping() | |
" Treat JSON files like JavaScript | |
au BufNewFile,BufRead *.json set ft=javascript | |
" make Python follow PEP8 ( http://www.python.org/dev/peps/pep-0008/ ) | |
au FileType python set softtabstop=4 tabstop=4 shiftwidth=4 textwidth=79 | |
" Remember last location in file, but not for commit messages. | |
" see :help last-position-jump | |
au BufReadPost * if &filetype !~ '^git\c' && line("'\"") > 0 && line("'\"") <= line("$") | |
\| exe "normal! g`\"" | endif | |
" This calls projectRoot and sets it to the root of the file currently open | |
au BufEnter * silent! exec "lcd ".g:projectRoot(expand("%:p:h")) | |
endif | |
" don't use Ex mode, use Q for formatting | |
map Q gq | |
" clear the search buffer when hitting return | |
nnoremap <CR> :nohlsearch<cr> | |
" No idea what this does but nobody should care about .pyc files | |
set wildignore+=*.pyc | |
" Get rid of extra white space | |
command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr> | |
" Allow erlang to be checked for correctness on file save | |
let g:erlangCheckFile='~/.vim/bundle/vimerl/compiler/erlang_check.erl' | |
" ^F is an awful combination for this strict indent... Better to use ^L | |
set indentkeys="0{,0},:,0#,!^F,o,O,e,!^L" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment