Skip to content

Instantly share code, notes, and snippets.

@pushcx
Created March 1, 2013 14:51
Show Gist options
  • Save pushcx/5065143 to your computer and use it in GitHub Desktop.
Save pushcx/5065143 to your computer and use it in GitHub Desktop.
My config file
" preliminaries {{{
" vim: foldmethod=marker
set nocompatible " real ultimate power
let mapleader=","
call pathogen#infect()
syntax on
filetype plugin indent on
" backups and undo
set autoread
set backup
set backupdir=~/.vim/backup//,/var/tmp//,/tmp//
set directory=~/.vim/swap//,/var/tmp//,/tmp//
set undofile
set undodir=~/.vim/undo//,/var/tmp//,/tmp//
" }}}
" input {{{
set pastetoggle=<F10>
" Q to linewrap paragraph
map Q {gq}
" :w!! to write as root
cmap w!! w !sudo tee % > /dev/null
" control-up/down to move the current line
map <C-Down> ddp
imap <C-Down> ddp
map <C-Up> dd<Up>P
imap <C-Up> dd<Up>P
nmap <leader>w :w
nmap <leader>W :wa
" my common typos
nmap :W :w
nmap :Q :q
nmap :Wq :wq
nmap :WQ :wq
nnoremap K :nohl<cr>
" remove delays switching out into insert
set timeout timeoutlen=1000 ttimeoutlen=100
" }}}
" ui {{{
set title
set shortmess+=I " disable welcome screen
set ttyfast
set showmatch " so nice for coding
hi MatchParen term=NONE cterm=NONE ctermfg=6 ctermbg=0
set backspace=2
set mouse=a " use mouse to grab things
" statusline
set history=1000 " keep a decent-sized history
set ruler " show ruler in status line
set showcmd " show incomplete command at bottom
set shortmess=a " keep it pithy
set fillchars=vert:┃
set laststatus=2
set statusline=%#error#%{SyntasticStatuslineFlag()}
set statusline+=%*%f\ %y%r%h
set statusline+=%{fugitive#statusline()}
set statusline+=%m
set statusline+=%=%(%c,\ %l/%L%)
" windows
set scrolloff=2 " always at least 2 lines of context
set noequalalways " don't resize windows on open/close
" Use ctrl + movement keys to move around windows
map <c-h> <c-w>h
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
" gvim
if has("gui_running")
set cursorline
" hide toolbar
set go-=T
" hide scrollbars
set guioptions-=L
set guioptions-=r
set guifont="Monospace\ 9"
endif
nnoremap <leader>rr :redraw!<cr>
" }}}
" colors {{{
set background=dark
colorscheme desert
if &t_Co > 2 || has("gui_running")
syntax on
endif
if &t_Co == 256
colorscheme inkpot
endif
" autocomplete menu color
highlight Pmenu ctermbg=238 gui=bold
" highlight column 81 in insert mode
highlight ColorColumn ctermbg=0*
if exists("&colorcolumn")
autocmd InsertEnter * set colorcolumn=81
autocmd InsertLeave * set colorcolumn=""
endif
" change cursor color in insert mode
if &term =~ "xterm"
let &t_SI = "\<Esc>]12;LightGreen\x7"
let &t_EI = "\<Esc>]12;white\x7"
endif
" only a cursorline in the current window
"autocmd WinLeave * set nocursorline
"autocmd WinEnter * set cursorline
" utility function when doing color tweakings
function! ShowColors()
let num = 255
while num >= 0
exec 'hi col_'.num.' ctermbg='.num.' ctermfg=white'
exec 'syn match col_'.num.' "ctermbg='.num.':...." containedIn=ALL'
call append(0, 'ctermbg='.num.':....')
let num = num - 1
endwhile
endfunction
map <leader>rp :RainbowParenthesesToggle<cr>
" good folding colors {{{
set foldmethod=syntax
highlight Folded guibg=black guifg=gray ctermbg=black ctermfg=gray
highlight FoldColumn guibg=black guifg=red ctermbg=black ctermfg=white
let g:SimpleFold_use_subfolds = 0
set foldtext=CleanFoldText()
function! CleanFoldText()
" http://vim.wikia.com/wiki/Customize_text_for_closed_folds
let line = getline(v:foldstart)
if match( line, '^[ \t]*\(\/\*\|\/\/\)[*/\\]*[ \t]*$' ) == 0
let initial = substitute( line, '^\([ \t]\)*\(\/\*\|\/\/\)\(.*\)', '\1\2', '' )
let linenum = v:foldstart + 1
while linenum < v:foldend
let line = getline( linenum )
let comment_content = substitute( line, '^\([ \t\/\*]*\)\(.*\)$', '\2', 'g' )
if comment_content != ''
break
endif
let linenum = linenum + 1
endwhile
let sub = initial . ' ' . comment_content
else
let sub = line
let startbrace = substitute( line, '^.*{[ \t]*$', '{', 'g')
if startbrace == '{'
let line = getline(v:foldend)
let endbrace = substitute( line, '^[ \t]*}\(.*\)$', '}', 'g')
if endbrace == '}'
let sub = sub.substitute( line, '^[ \t]*}\(.*\)$', '...}\1', 'g')
endif
endif
endif
let n = v:foldend - v:foldstart + 1
let info = " " . n . " "
let sub = sub . " "
let num_w = getwinvar( 0, '&number' ) * getwinvar( 0, '&numberwidth' )
let fold_w = getwinvar( 0, '&foldcolumn' )
let sub = strpart( sub, 0, winwidth(0) - strlen( info ) - num_w - fold_w - 1 )
return sub . info
endfunction
" }}}
" }}}
" navigating between files {{{
set wildmenu " show options for file completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,*.pyc,/home/harkins/Mail/**
" convenience for directory of file being edited
cnoremap %% <C-R>=expand('%:h').'/'<cr>
" switch between this and previous file
nnoremap <leader><leader> <c-^>
" using kien/ctrlp
let g:ctrlp_working_path_mode = 2
" NERDTree
nnoremap <leader>d :NERDTreeToggle<cr>
let NERDChristmasTree=1
let NERDTreeWinPos='left'
" Use Ack instead of Grep when available
if executable("ack")
set grepprg=ack\ -H\ --nogroup\ --nocolor
endif
command! -nargs=* -complete=file Ack call Ack(<q-args>)
nmap <leader>a :Ack
nmap <leader>A :Ack <cword><CR>
" common file I open
nmap <Leader>f :e ~/.fortune<CR><CR>
" }}}
" navigating in files {{{
set incsearch
set hlsearch
set ignorecase
set smartcase
nnoremap <Space> za
vnoremap <Space> za
" swap ' (jump to line) and ` (jump to line and col)
nnoremap ' `
nnoremap ` '
" jump to last known cursor position when opening a file {{{
augroup JumpCursorOnEdit
au!
autocmd BufReadPost *
\ if expand("<afile>:p:h") !=? $TEMP |
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ let JumpCursorOnEdit_foo = line("'\"") |
\ let b:doopenfold = 1 |
\ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
\ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
\ let b:doopenfold = 2 |
\ endif |
\ exe JumpCursorOnEdit_foo |
\ endif |
\ endif
" Need to postpone using "zv" until after reading the modelines.
autocmd BufWinEnter *
\ if exists("b:doopenfold") |
\ exe "normal zv" |
\ if(b:doopenfold > 1) |
\ exe "+".1 |
\ endif |
\ unlet b:doopenfold |
\ endif
augroup END
" }}}
" }}}
" version control integration {{{
" vimdiff current file
map <leader>cd :VCSVimDiff<Enter>
" using threesome.vim to resolve conflicts
let g:threesome_initial_scrollbind_grid=1
let g:threesome_initial_scrollbind_compare=1
" close everything, open all changed files
function! OpenChangedFiles()
only " Close all windows, unless they're modified
let status = system('git status -s | grep "^ \?\(M\|A\)" | cut -d " " -f 3')
let filenames = split(status, "\n")
exec "edit " . filenames[0]
for filename in filenames[1:]
exec "sp " . filename
endfor
endfunction
map <leader>o :call OpenChangedFiles()
" in vimdiff, use control + movement to get diffs
if &diff
nmap <c-h> :diffget<cr>
nmap <c-j> ]cz.
nmap <c-k> [cz.
nmap <c-l> :diffput<cr>
endif
" }}}
" filetype detection {{{
filetype plugin indent on
set fileencodings=utf-8,iso-8859-15
set fileencoding=utf-8
" }}}
" editing: text {{{
set textwidth=78
" filetype detection
au BufRead,BufNewFile *-sup.* :set ft=mail
au BufRead,BufNewFile sup.* :set ft=mail
autocmd FileType mail setlocal textwidth=72
" TODO: how do I turn off capitalization checking?
autocmd FileType mail setlocal spell spelllang=en_us
set linebreak " wrap
set nojoinspaces " two spaces is evil
set list
set listchars=tab:·\ ,trail:· ",eol:$ " don't often turn on list, but this is what I like
" re-select previous v selection
nnoremap <leader>v V`]
" convenience methods for working with X clipboard
nnoremap <leader>y "*y
nnoremap <leader>p "*p
nnoremap <leader>P "*P
nnoremap <leader>d "*d
" convenience for search-and-replace - need a V mode
nnoremap <leader>s :%s//g<left><left>
" set undo points at the end of each sentence, rather than one undo for all
" the time I spent in insert mode.
inoremap . .<C-g>u
inoremap ! !<C-g>u
inoremap ? ?<C-g>u
inoremap : :<C-g>u
" Gundo, the awesome undo tree
nnoremap <leader>u :GundoToggle<cr>
let g:gundo_width = 25
let g:gundo_preview_bottom = 1
let g:gundo_help = 0
map Y y$ " like C and D
" }}}
" editing: any code {{{
set iskeyword+=-,$,@,%,#
set synmaxcol=1024 " how far into long lines to check highlighting
" indenting
set autoindent
set shiftwidth=2
set shiftround
set expandtab " a code necessity; spaces instead of tabs
set softtabstop=2 " and another
" show subtle indent guides
highlight IndentGuidesEven ctermbg=235 gui=bold
let g:indent_guides_auto_colors = 0
let g:indent_guides_enable_on_vim_startup = 1
" plugin whines if this isn't defined somewhere
map <Leader>ff <Plug>SimpleFold_Foldsearch
nmap <Leader>n :TagbarOpenAutoClose<CR>
nmap <Leader>N :TagbarToggle<CR>
" gist {{{
let g:gist_put_url_to_clipboard_after_post = 1
let g:gist_clip_command = 'xclip'
let g:gist_detect_filetype = 1
let g:gist_show_privates = 1
let g:gist_private = 1
let g:github_user = 'pushcx'
let g:github_token = '229597b926478ac995680268163ba967'
" gist private
map <leader>gg :Gist -p<cr>
map <leader>gp :Gist -p<cr>
" gist public
map <leader>gP :Gist -P<cr>
" gist whole file
map <leader>gG :Gist<cr>
" gist all open buffers
map <leader>gm :Gist -m<cr>
" gist management: list, edit, delete, fork
map <leader>gl :Gist -l<cr>
map <leader>ge :Gist -e<cr>
map <leader>gd :Gist -d<cr>
map <leader>gf :Gist -f<cr>
" }}}
" }}}
" editing: css {{{
" ,s to sort CSS properties
nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:noh<CR>
" }}}
" editing: html {{{
au BufRead,BufNewFile *.coffee :set ft=coffee
autocmd TabEnter,WinEnter,BufWinEnter *.html,*.html.erb let g:html_indent_tags = g:html_indent_tags.'\|p'
" }}}
" editing: guile {{{
" run in guile - kinda junky, but handy
map <leader>g "ay!guile<cr>"aP
" }}}
" editing: ruby {{{
" filetype detection
au BufRead,BufNewFile *.haml :set ft=haml
" often get long lines in haml
" but maybe this just means I suck and need more partials/presenters
autocmd FileType haml setlocal textwidth=0
au FileType ruby,eruby set foldlevel=1
au FileType ruby,eruby set omnifunc=rubycomplete#Complete
au FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
au FileType ruby,eruby let g:rubycomplete_rails = 1
au FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
" getting around fast
map <leader>sg :topleft 100 :split Gemfile<cr>
" ExtractVariable and InlineVariable {{{
" source: https://github.com/garybernhardt/dotfiles/blob/master/.vimrc
function! ExtractVariable()
let name = input("Variable name: ")
if name == ''
return
endif
" Enter visual mode (not sure why this is needed since we're already in
" visual mode anyway)
normal! gv
" Replace selected text with the variable name
exec "normal c" . name
" Define the variable on the line above
exec "normal! O" . name . " = "
" Paste the original selected text to be the variable value
normal! $p
endfunction
function! InlineVariable()
" Copy the variable under the cursor into the 'a' register
" XXX: How do I copy into a variable so I don't pollute the registers?
:normal "ayiw
" It takes 4 diws to get the variable, equal sign, and surrounding
" whitespace. I'm not sure why. diw is different from dw in this respect.
:normal 4diw
" Delete the expression into the 'b' register
:normal "bd$
" Delete the remnants of the line
:normal dd
" Go to the end of the previous line so we can start our search for the
" usage of the variable to replace. Doing '0' instead of 'k$' doesn't
" work; I'm not sure why.
normal k$
" Find the next occurence of the variable
exec '/\<' . @a . '\>'
" Replace that occurence with the text we yanked
exec ':.s/\<' . @a . '\>/' . @b
endfunction
vnoremap <leader>rv :call ExtractVariable()<cr>
nnoremap <leader>ri :call InlineVariable()<cr>
" }}}
" routing {{{
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>sR :call ShowRoutes()<cr>
map <leader>sr :topleft :split config/routes.rb<cr>
" }}}
" }}}
" editing: php {{{
" filetype detection
au BufRead,BufNewFile *.phps :set ft=php
au BufRead,BufNewFile *.pcgi :set ft=php
let php_sql_query = 1 " highlight sql queries
let php_htmlInStrings = 1 " and html in strings
let php_minlines = 1000 " be smart about syntax colorization
let php_parent_error_close = 1
let php_parent_error_open = 1
let php_folding = 1 " let's keep things tidy
" dictionary file(s) for tab completion
set complete+=.,t,b
:au BufReadPost * if exists("b:current_syntax")
:au BufReadPost * let &dictionary = substitute("~/.vim/dict/FT.dict", "FT", b:current_syntax, "")
:au BufReadPost * endif
" }}}
" editing: python {{{
let python_highlight_all = 1
" }}}
" editing: shell {{{
let g:is_bash = 1 " all .sh is bash, because I am a terrible linux coder
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment