Skip to content

Instantly share code, notes, and snippets.

@pangloss
Created June 10, 2013 00:22
Show Gist options
  • Save pangloss/5745842 to your computer and use it in GitHub Desktop.
Save pangloss/5745842 to your computer and use it in GitHub Desktop.
My current vim configuration
" Make external commands work through a pipe instead of a pseudo-tty
"set noguipty
" set the X11 font to use
" set guifont=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1
set guifont=DejaVu\ Sans\ Mono:h11
" set guifont=Anonymous\ Pro:h14
set ch=1 " Make command line x lines high
set mousehide " Hide the mouse when typing text
" Make shift-insert work like in Xterm
map <S-Insert> <MiddleMouse>
map! <S-Insert> <MiddleMouse>
" Only do this for Vim version 5.0 and later.
if version >= 500
" I like highlighting strings inside C comments
let c_comment_strings=1
" Switch on syntax highlighting if it wasn't on yet.
if !exists("syntax_on")
syntax on
endif
" Switch on search pattern highlighting.
set hlsearch
endif
" no audible bell
set t_vb=
" turn off as much chrome as possible
" a: integrate with OS copy and paste
" e: show the tab bar if necessary
" c: avoid popup dialogs (console dialogs instead)
" scrollbars, toolbars, menu bars, etc all turned off
set guioptions=aec
set columns=300
set lines=3000
color railscat
if has("gui_macvim")
" Fullscreen takes up entire screen
set fuoptions=maxhorz,maxvert
" Map Command-# to switch tabs
map <D-0> 0gt
imap <D-0> <Esc>0gt
map <D-1> 1gt
imap <D-1> <Esc>1gt
map <D-2> 2gt
imap <D-2> <Esc>2gt
map <D-3> 3gt
imap <D-3> <Esc>3gt
map <D-4> 4gt
imap <D-4> <Esc>4gt
map <D-5> 5gt
imap <D-5> <Esc>5gt
map <D-6> 6gt
imap <D-6> <Esc>6gt
map <D-7> 7gt
imap <D-7> <Esc>7gt
map <D-8> 8gt
imap <D-8> <Esc>8gt
map <D-9> 9gt
imap <D-9> <Esc>9gt
else
" Map Command-# to switch tabs
map <D-0> 0gt
imap <D-0> <Esc>0gt
map <D-1> 1gt
imap <D-1> <Esc>1gt
map <D-2> 2gt
imap <D-2> <Esc>2gt
map <D-3> 3gt
imap <D-3> <Esc>3gt
map <D-4> 4gt
imap <D-4> <Esc>4gt
map <D-5> 5gt
imap <D-5> <Esc>5gt
map <D-6> 6gt
imap <D-6> <Esc>6gt
map <D-7> 7gt
imap <D-7> <Esc>7gt
map <D-8> 8gt
imap <D-8> <Esc>8gt
map <D-9> 9gt
imap <D-9> <Esc>9gt
endif
" Project Tree
autocmd VimEnter * call s:CdIfDirectory(expand("<amatch>"))
" autocmd FocusGained * call s:UpdateNERDTree()
" If the parameter is a directory, cd into it
function s:CdIfDirectory(directory)
let explicitDirectory = isdirectory(a:directory)
let directory = explicitDirectory || empty(a:directory)
if explicitDirectory
exe "cd " . a:directory
endif
if directory
NERDTree
wincmd p
bd
endif
if explicitDirectory
wincmd p
endif
endfunction
" NERDTree utility function
function s:UpdateNERDTree(...)
let stay = 0
if(exists("a:1"))
let stay = a:1
end
if exists("t:NERDTreeBufName")
let nr = bufwinnr(t:NERDTreeBufName)
if nr != -1
exe nr . "wincmd w"
exe substitute(mapcheck("R"), "<CR>", "", "")
if !stay
wincmd p
end
endif
endif
if exists(":CommandTFlush") == 2
CommandTFlush
endif
endfunction
" Utility functions to create file commands
function s:CommandCabbr(abbreviation, expansion)
execute 'cabbrev ' . a:abbreviation . ' <c-r>=getcmdpos() == 1 && getcmdtype() == ":" ? "' . a:expansion . '" : "' . a:abbreviation . '"<CR>'
endfunction
function s:FileCommand(name, ...)
if exists("a:1")
let funcname = a:1
else
let funcname = a:name
endif
execute 'command -nargs=1 -complete=file ' . a:name . ' :call ' . funcname . '(<f-args>)'
endfunction
function s:DefineCommand(name, destination)
call s:FileCommand(a:destination)
call s:CommandCabbr(a:name, a:destination)
endfunction
" Public NERDTree-aware versions of builtin functions
function ChangeDirectory(dir, ...)
execute "cd " . a:dir
let stay = exists("a:1") ? a:1 : 1
NERDTree
if !stay
wincmd p
endif
endfunction
" Define the NERDTree-aware aliases
call s:DefineCommand("Cd", "ChangeDirectory")
" Command-T
if has("gui_macvim")
macmenu File.New\ Tab key=<nop>
macmenu &File.New\ Tab key=<nop>
endif
" Use Vim settings, rather then Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
call pathogen#infect()
set modelines=0
" undofile tells Vim to create <FILENAME>.un~ files whenever you edit a file. These files contain undo information so you can undo previous actions even after you close and reopen a file.
" http://stevelosh.com/blog/2010/09/coming-home-to-vim/#important-vimrc-lines
set undofile
set ttyfast
set scrolloff=3
set laststatus=2
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
set history=500 " keep 500 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
"set ignorecase
"set smartcase
set autoindent
nnoremap <tab> %
vnoremap <tab> %
"set number
set nowrap
set tabstop=2
set expandtab
set shiftwidth=2
set softtabstop=2
set virtualedit=onemore
"set virtualedit=all
set vb t_vb=
set wildmenu
set path=.,**
set viminfo='50,<1000,s100,:1000,n~/.vim/viminfo
set hid
" Set encoding
set encoding=utf-8
nmap <silent> <Leader>p :NERDTreeToggle<CR>
nmap <silent> <Leader>f :NERDTreeFind<CR>
" CTags
"map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
" Handy tab controls
map <silent> tn :tabnew<CR>
map <silent> td :tabclose<CR>
map <silent> th :tabp<CR>
map <silent> tl :tabn<CR>
" Open a new tab with the current file, with a bit of a hack to allow it to
" work on files with modifications and not lose undo history because :tabnew %
" doesn't work correctly.
" map <silent> <Leader>n :tabnew<CR> :execute 'e #'<CR>
map <silent> <Leader>n :set relativenumber<CR>
map <silent> <Leader>N :set norelativenumber<CR>
" Jump back and forth between lines on the clist
map <silent> <Leader><Space> :cn <CR>
map <silent> <Leader><S-Space> :cp <CR>
map <silent> <Leader><C-Space> :cnf <CR>
" Arrange a window with 4 buffers in any configuration into a 2x2 grid.
" steps: arrange in one column, move 1 buffer to the right column,
" switch to the top of the left column and mark the buffer, switch back to
" the right column, split the buffer and jump to the marked buffer. Delete
" the mark. Rotate the right pane to put the buffers back into their
" original order. Switch back to the copy of the marked buffer in the first
" column and close the extra copy of that buffer.
"
" With different number of buffers, it usually results in the right column
" having 2 buffers and the left column with the rest of them.
nmap <silent> <Leader>4 <C-W>J<C-W>w<C-W>J<C-W>w<C-W>L<C-W>hmM<C-W>l<C-W>s'M:delm M<CR><C-W>r<C-W>w<C-W>q
" Select the block from the current location to the line with matching parens,
" delete all folds in the area and turn it into a single fold. Useful for
" wrongly folded javascript functions, etc.
nmap zZ v%zDgvzF
" Make a composite fold of selected folds except delete the first child fold
" I wanted this at one time for something...
vmap zZ zFzozdzc
" Don't use Ex mode, use Q for formatting
map Q gq
" Shift tab escapes from insert mode (now using S-Tab using for snippets)
" imap <S-Tab> <Esc>
" \F (capital F) activates folding on the file
map <silent> <Leader><C-f> <Plug>SimpleFold_Foldsearch
" This is an alternative that also works in block mode, but the deleted
" text is lost and it only works for putting the current register.
"vnoremap p "_dp
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
endif
color slate
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" If the taglist window is open, close it and switch to the previously
" active buffer when leaving the tab.
autocmd TabLeave *
\ if bufwinnr(g:TagList_title) != -1 |
\ if bufwinnr(g:TagList_title) == bufwinnr('%') |
\ exe bufwinnr('#') . 'wincmd w' |
\ endif |
\ exe 'TlistClose' |
\ endif
" 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 " has("autocmd")
let g:SimpleFold_use_subfolds = 0
" Default is 100 but larger defrecords often are larger and if you hit
" this limit it misbehaves badly.
let g:paredit_matchlines = 300
" Up/down key behaviour {{{1
" -- Changes up/down arrow keys to behave screen-wise, rather than file-wise.
" Behaviour is unchanged in operator-pending mode.
" Behaviour is unchanged for the j and k bindings.
" Extra-elaborate to stop remapping from interfering with Omni-complete popup
inoremap <silent><expr><Up> pumvisible() ? "<Up>" : "<C-O>gk"
inoremap <silent><expr><Down> pumvisible() ? "<Down>" : "<C-O>gj"
" Treat wrapped text the way any other text editor would
nnoremap <silent>k gk
nnoremap <silent>j gj
nnoremap <silent><Up> gk
nnoremap <silent><Down> gj
vnoremap <silent>k gk
vnoremap <silent>j gj
vnoremap <silent><Up> gk
vnoremap <silent><Down> gj
map <C-l> <C-w>l
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
"<M-l>
map ¬ <C-w>l<C-w>_<C-w>6-
"<M-h>
map ˙ <C-w>h<C-w>_<C-w>6-
"<M-j>
map ∆ <C-w>j<C-w>_<C-w>6-
"<M-k>
map ˚ <C-w>k<C-w>_<C-w>6-
" Below, I uncerimoniously copy stuff from
" git://github.com/jferris/config_files.git
"
" .... not doing so much rails anymore.
" Edit config/routes.rb
"map <Leader>R :e config/routes.rb<CR>
"map <Leader>E :e config/environment.rb<CR>
"map <Leader>S :e db/schema.rb<CR>
"map <Leader>F :e spec/factories.rb<CR>
" Leader shortcuts for Rails commands
"map <silent> <Leader>r :.Rake <CR>
"map <Leader>m :Rmodel <CR>
"map <Leader>c :Rcontroller <CR>
"map <Leader>v :Rview <CR>
"map <Leader>u :Runittest <CR>
"map <Leader>f :Rfunctionaltest <CR>
"map <Leader>i :Rintegrationtest<CR>
"map <Leader>tm :RTmodel <CR>
"map <Leader>tc :RTcontroller <CR>
"map <Leader>tv :RTview <CR>
"map <Leader>tu :RTunittest <CR>
"map <Leader>tf :RTfunctionaltest <CR>
"map <Leader>ti :Rintegrationtest<CR>
"map <Leader>sm :RSmodel <CR>
"map <Leader>sc :RScontroller <CR>
"map <Leader>sv :RSview <CR>
"map <Leader>su :RSunittest <CR>
"map <Leader>sf :RSfunctionaltest <CR>
"map <Leader>si :RSintegrationtest<CR>
"map <Leader>vm :RVmodel <CR>
"map <Leader>vc :RVcontroller <CR>
"map <Leader>vv :RVview <CR>
"map <Leader>vu :RVunittest <CR>
"map <Leader>vf :RVfunctionaltest <CR>
"map <Leader>vi :RVintegrationtest<CR>
" Use \a to open the taglist and jump to it, or jump to the previous buffer
" and close the tag list.
nmap <silent><expr> <Leader>a bufwinnr(g:TagList_title) == -1 ? ":TlistToggle<CR><C-w>p" : bufwinnr(g:TagList_title) == bufwinnr('%') ? "<C-w>p:TlistToggle<CR>" : ":TlistToggle<CR>"
" Configuration for the taglist.vim plugin
let Tlist_Show_One_File = 1
let Tlist_Use_Right_Window = 1
let Tlist_Close_On_Select = 1
let Tlist_WinWidth = 60
" Hide search highlighting
map <silent> <Leader>h :set invhls <CR>
" Opens an edit command with the path of the currently edited file filled in
" Normal mode: <Leader>e
" map <Leader>e :e <C-R>=expand("%:p:h") <CR>/
" Opens a tab edit command with the path of the currently edited file filled in
" Normal mode: <Leader>t
" map <Leader>te :tabe <C-R>=expand("%:p:h") <CR>/
" Inserts the path of the currently edited file into a command
" Command mode: Ctrl+P
cmap <C-P> <C-R>=expand("%:p:h") <CR>/
" Delete the current buffer. Closes all views of the buffer and removes it
" from the buffer list
nmap <Leader>d :bd <CR>
" Quicker way to close a window.
nmap <Leader>q :q <CR>
" Delete the current file and close the buffer. This only works if the file is
" checked in to git and unmodified.
nmap <Leader><C-d> :!git rm %<CR>:bd<CR>
" Duplicate a selection
" Visual mode: D
vmap D y'>p
" Press p while in visual mode to replace the selection without
" overwriting the default register
vmap p p :call setreg('"', getreg('0')) <CR>
" Press gp while in visual mode to replace the selection without overwriting
" the default register and move the cursor to after the pasted text
vmap gp gp :call setreg('"', getreg('0')) <CR>
" Press P while in visual mode to get the original behaviour of p
vmap P "1ygv"0p :call setreg('"', getreg('1')) <CR>
" Display extra whitespace
set listchars=tab:»·,trail:·
if executable("ack")
set grepprg=ack\ -H\ --nogroup\ --nocolor
endif
" Tab completion options
" (only complete to the longest unambiguous match, and show a menu)
set completeopt=longest,menu
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc
set complete=.,t
" Key to echo the next function
let g:EchoFuncKeyNext = '<C-Space>'
" Key to echo the prev function
let g:EchoFuncKeyPrev = '<C-S-Space>'
" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby
" For dust templates
au BufNewFile,BufRead *.dust set filetype=html
function! s:setupWrapping()
"set wrap
set wm=2
set textwidth=72
endfunction
function! s:setupMarkup()
call s:setupWrapping()
map <buffer> <Leader>p :Mm <CR>
endfunction
" md, markdown, and mk are markdown and define buffer-local preview
au BufRead,BufNewFile *.{md,markdown,mdown,mkd,mkdn} call s:setupMarkup()
au BufRead,BufNewFile *.txt call s:setupWrapping()
"Directories for swp files
set backupdir=~/.vim/backup
set directory=~/.vim/backup
let g:SuperTabDefaultCompletionType = "<c-n>"
let g:SuperTabContextDefaultCompletionType = "<c-n>"
" From http://vimbits.com/bits?sort=top
map Y y$
" Adapted from http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
nmap <silent> <leader>= :call Preserve("normal gg=G")<CR>
nnoremap <silent> <leader>W :call Preserve("%s/\\s\\+$//e")<CR>
autocmd BufWritePre *.py,*.js,*.rb,*.coffee,*.clj,*.cljs :call Preserve("%s/\\s\\+$//e")
" Settings for VimClojure
let vimclojure#HighlightBuiltins = 1
let vimclojure#ParenRainbow = 1
" Settings for Specky
" see :help specky
let g:speckyQuoteSwitcherKey = "<C-S>'"
let g:speckySpecSwitcherKey = "<C-S>s"
let g:speckyRunSpecKey = "<C-S>r"
let g:speckyWindowType = 2
" http://sjl.bitbucket.org/gundo.vim/
nnoremap <LocalLeader>u :GundoToggle<CR>
nnoremap <F5> :GundoToggle<CR>
au FileType clojure inoremap <silent><C-d> <left><C-o>:call SlimvEvalDefun()<CR><right>
au FileType clojure inoremap <silent><C-e> <left><C-o>:call SlimvEvalExp()<CR><right>
" Command-T
let g:CommandTMaxHeight=20
map <silent> <D-t> :CommandT<CR>
" Delimit sentences with 2 spaces
set cpo+=J
" VimClojure options
let g:clojure_align_multiline_strings = 1
let g:clojure_maxlines = 200
" My multicursor settings... delete if switch to vim-multiple-cursors is permanent.
" nnoremap <leader>ma :<c-u>call MultiCursorPlaceCursor()<cr>
" nnoremap <leader>mm :<c-u>call MultiCursorManual()<cr>
" nnoremap <leader>mc :<c-u>call MultiCursorRemoveCursors()<cr>
" xnoremap <leader>mv :<c-u>call MultiCursorVisual()<cr>
" nnoremap <leader>ms :<c-u>call MultiCursorSearch('')<cr>
" nnoremap <leader>mw :<c-u>call MultiCursorSearch('<c-r><c-w>')<cr>
" xnoremap <leader>ms "*y<Esc>:call MultiCursorSearch('<c-r>=substitute(escape(@*, '\/.*$^~[]'), "\n", '\\n', "g")<cr>')<cr>
" let g:multicursor_quit = "<leader>mx"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment