Skip to content

Instantly share code, notes, and snippets.

@emilyst
Created September 25, 2011 05:28
Show Gist options
  • Save emilyst/1240270 to your computer and use it in GitHub Desktop.
Save emilyst/1240270 to your computer and use it in GitHub Desktop.
Current vim stuff
"##### general settings #####
set nocompatible
set encoding=utf-8
set number
if exists('+relativenumber') | set relativenumber | endif
if has('unnamedplus') | set clipboard=unnamedplus | endif
"set numberwidth=4
set ruler
if has('persistent_undo')
set undodir=~/.vim/temp/undo/
set undofile
set undolevels=100000
if exists('+undoreload') | set undoreload=100000 | endif
endif
if exists('+cryptmethod') | set cryptmethod=blowfish | endif
let mapleader = ","
"set digraph
set modeline
set gdefault
set magic
set showmode
set showcmd
set showmatch
set matchtime=2
set history=100
set notitle
set ttyfast
"set ttyscroll=0
set scrolloff=3
set nostartofline
set backup
set backupdir=~/.vim/temp/backup/
set directory=~/.vim/temp/
set autowrite
set backspace=indent,eol,start
set splitbelow
if has('mouse') | set mouse=a | endif
"##### appearance #####
set t_Co=256
set background=dark
colorscheme tomorrow-night-eighties
if exists('+colorcolumn') | set colorcolumn=80,120 | endif
syntax on
let loaded_matchparen = 0
set cursorline
"set cursorcolumn
"##### whitespace #####
set nowrap
set whichwrap+=<>[]
set textwidth=80
"set formatoptions=tcqron1
"set lbr
set showbreak=→
set smartindent
set tabstop=4
set shiftwidth=4
set softtabstop=4
"set expandtab
set list listchars=tab:▸\ ,trail:·",eol:¬
filetype indent on
"##### folding #####
set foldenable
set foldmethod=syntax
set foldlevel=100 " Don't autofold anything
"##### perl #####
let g:perl_compiler_force_warnings = 0
let perl_moose_stuff = 1
let perl_no_scope_in_variables = 1
let perl_no_sync_on_sub = 1
let perl_no_sync_on_global_var = 1
let perl_extended_vars = 1
let perl_include_pod = 1
let perl_string_as_statement = 1
let perl_sync_dist = 1000
let perl_want_scope_in_variables = 1
let perl_pod_formatting = 1
let perl_pod_spellcheck_headings = 1
let perl_fold = 1
let perl_fold_blocks = 1
let perl_nofold_packages = 1
let perlhelp_prog = '/usr/bin/perldoc'
"##### searching #####
nnoremap / /\v
vnoremap / /\v
set ignorecase
set smartcase
set gdefault
set incsearch
set showmatch
set hlsearch
nnoremap <leader><space> :noh<cr>
nnoremap <tab> %
vnoremap <tab> %
"##### tab completion #####
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,*.bak,*.exe,*.pyc,*.DS_Store,*.db
"##### status bar #####
set laststatus=2
set statusline=%F%m%r%h%w\ [TYPE=%Y\ %{&ff}]\ [%l/%L\ (%p%%)]
"##### keyboard mappings #####
" clean trailing whitespace
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" hardwrap a paragraph
nnoremap <leader>q gqip
" reselect what was just pasted
nnoremap <leader>v V`]
" quickly open .vimrc as split window
nnoremap <leader>ev <C-w><C-v><C-l>:e $MYVIMRC<cr>
" toggle special characters
nmap <leader>l :set invlist!<CR>
nmap <leader>p :set invpaste!<CR>
" useful from RTK
map <leader>ca :!~/usealiases<CR>
map <leader>b :BufExplorer<cr>
" ack
"nnoremap <leader>a :Ack
" convenient mappings (TODO: what about insert mode?)
noremap <C-a> ggVG
"nnoremap <C-x> "+d
"noremap <C-c> "+y<CR>
"noremap <C-v> "+p<CR>
" Prev/Next Buffer
nmap <C-n> :bn<CR>
nmap <C-p> :bp<CR>
" easier split window
nnoremap <leader>w <C-w>v<C-w>l
" scroll shortcuts
nmap <C-h> zH
nmap <C-l> zL
nmap <C-j> <C-d>
nmap <C-k> <C-u>
" highlight search matches
nmap <F3> :set hls!<CR>
" display unprintable characters
nnoremap <F2> :set list!<CR>
" insert date
map <F4> :r !date<CR>
" highlight cursor's current column
map <F6> :set cursorcolumn!<CR>
" replacing (local, global)
nnoremap gr gd[{V%:s/<C-R>///gc<left><left><left>
nnoremap gR gD:%s/<C-R>///gc<left><left><left>
" folding (if enabled)
inoremap <F9> <C-O>za
nnoremap <F9> za
onoremap <F9> <C-C>za
vnoremap <F9> zf
nnoremap <silent> <Space> @=(foldlevel('.')?'za':'l')<CR>
vnoremap <Space> zf
" Make C-w o (only window) reversible by opening a tab
nnoremap <C-W>O :tabnew %<CR>
nnoremap <C-W>o :tabnew %<CR>
nnoremap <C-W><C-O> :tabnew %<CR>
" Text object for indented code
onoremap <silent>ai :<C-u>call IndTxtObj(0)<CR>
onoremap <silent>ii :<C-u>call IndTxtObj(1)<CR>
vnoremap <silent>ai :<C-u>call IndTxtObj(0)<CR><Esc>gv
vnoremap <silent>ii :<C-u>call IndTxtObj(1)<CR><Esc>gv
function! IndTxtObj(inner)
if &filetype == 'haml' || &filetype == 'sass' || &filetype == 'python'
let meaningful_indentation = 1
else
let meaningful_indentation = 0
endif
let curline = line(".")
let lastline = line("$")
let i = indent(line(".")) - &shiftwidth * (v:count1 - 1)
let i = i < 0 ? 0 : i
if getline(".") =~ "^\\s*$"
return
endif
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
while p > 0 && (nextblank || indent(p) >= i )
-
let p = line(".") - 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner)
-
endif
normal! 0V
call cursor(curline, 0)
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
while p <= lastline && (nextblank || indent(p) >= i )
+
let p = line(".") + 1
let nextblank = getline(p) =~ "^\\s*$"
endwhile
if (!a:inner && !meaningful_indentation)
+
endif
normal! $
endfunction
" git blame
vmap <leader>gb :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>
" Remap TAB to keyword completion
function! InsertTabWrapper(direction)
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
elseif "backward" == a:direction
return "\<c-p>"
elseif "forward" == a:direction
return "\<c-n>"
else
return "\<c-x>\<c-k>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper("forward")<CR>
inoremap <s-tab> <c-r>=InsertTabWrapper("backward")<CR>
inoremap <c-tab> <c-r>=InsertTabWrapper("startkey")<CR>
"##### autocommands #####
if has('autocmd')
" settings immediately take effect
augroup vimrc
au!
au BufWritePost ~/.vimrc :source ~/.vimrc
au BufLeave ~/.vimrc :source ~/.vimrc
augroup END
augroup focus
au!
au FocusLost * :wa
augroup END
augroup dir
au!
autocmd BufEnter * cd %:p:h
augroup END
augroup lastcursorpos
au!
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
augroup END
" enabled file type detection and file-type specific plugins.
filetype plugin on
" PEP8
augroup python
au!
au BufReadPre,FileReadPre *.py set tabstop=4
au BufReadPre,FileReadPre *.py set expandtab
au BufReadPre,FileReadPre *.py set tw=0
augroup END
" Perl (and extra things)
augroup perl
au!
au FileType pl,pm,t set filetype=perl
au FileType perl noremap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr>
au FileType perl set makeprg=perl\ -c\ %\ $*
au FileType perl set errorformat=%f:%l:%m
au FileType perl set keywordprg=perldoc\ -f
au FileType perl set formatprg=perl\ -MText::Autoformat\ -e'autoformat'
au FileType perl set formatoptions=qro
au FileType perl set tabstop=4
au FileType perl set expandtab
au FileType perl set tw=0
au BufWritePre,FileWritePre *.pm,*.pl,*.t :%s/\s\+$//e
augroup END
endif
"##### auto-replace #####
" days of week
iab monday Monday
iab tuesday Tuesday
iab wednesday Wednesday
iab thursday Thursday
iab friday Friday
iab saturday Saturday
iab sunday Sunday
"##### RTK-specific #####
if filereadable('/usr/local/etc/vimrc_files/reasonably_stable_mappings.vim')
source /usr/local/etc/vimrc_files/reasonably_stable_mappings.vim
endif
" Tomorrow Night Eighties - Full Colour and 256 Colour
" http://chriskempson.com
"
" Hex colour conversion functions borrowed from the theme "Desert256""
" Default GUI Colours
let s:foreground = "cfcfcf"
let s:background = "151515"
let s:selection = "515151"
let s:line = "393939"
let s:comment = "888888"
let s:red = "f2777a"
let s:orange = "f99157"
let s:yellow = "ffcc66"
let s:green = "99cc99"
let s:aqua = "009999"
let s:blue = "99cccc"
let s:purple = "cc99cc"
set background=dark
hi clear
syntax reset
let g:colors_name = "tomorrow-night-eighties"
if has("gui_running") || &t_Co == 88 || &t_Co == 256
" Returns an approximate grey index for the given grey level
fun <SID>grey_number(x)
if &t_Co == 88
if a:x < 23
return 0
elseif a:x < 69
return 1
elseif a:x < 103
return 2
elseif a:x < 127
return 3
elseif a:x < 150
return 4
elseif a:x < 173
return 5
elseif a:x < 196
return 6
elseif a:x < 219
return 7
elseif a:x < 243
return 8
else
return 9
endif
else
if a:x < 14
return 0
else
let l:n = (a:x - 8) / 10
let l:m = (a:x - 8) % 10
if l:m < 5
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" Returns the actual grey level represented by the grey index
fun <SID>grey_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 46
elseif a:n == 2
return 92
elseif a:n == 3
return 115
elseif a:n == 4
return 139
elseif a:n == 5
return 162
elseif a:n == 6
return 185
elseif a:n == 7
return 208
elseif a:n == 8
return 231
else
return 255
endif
else
if a:n == 0
return 0
else
return 8 + (a:n * 10)
endif
endif
endfun
" Returns the palette index for the given grey index
fun <SID>grey_colour(n)
if &t_Co == 88
if a:n == 0
return 16
elseif a:n == 9
return 79
else
return 79 + a:n
endif
else
if a:n == 0
return 16
elseif a:n == 25
return 231
else
return 231 + a:n
endif
endif
endfun
" Returns an approximate colour index for the given colour level
fun <SID>rgb_number(x)
if &t_Co == 88
if a:x < 69
return 0
elseif a:x < 172
return 1
elseif a:x < 230
return 2
else
return 3
endif
else
if a:x < 75
return 0
else
let l:n = (a:x - 55) / 40
let l:m = (a:x - 55) % 40
if l:m < 20
return l:n
else
return l:n + 1
endif
endif
endif
endfun
" Returns the actual colour level for the given colour index
fun <SID>rgb_level(n)
if &t_Co == 88
if a:n == 0
return 0
elseif a:n == 1
return 139
elseif a:n == 2
return 205
else
return 255
endif
else
if a:n == 0
return 0
else
return 55 + (a:n * 40)
endif
endif
endfun
" Returns the palette index for the given R/G/B colour indices
fun <SID>rgb_colour(x, y, z)
if &t_Co == 88
return 16 + (a:x * 16) + (a:y * 4) + a:z
else
return 16 + (a:x * 36) + (a:y * 6) + a:z
endif
endfun
" Returns the palette index to approximate the given R/G/B colour levels
fun <SID>colour(r, g, b)
" Get the closest grey
let l:gx = <SID>grey_number(a:r)
let l:gy = <SID>grey_number(a:g)
let l:gz = <SID>grey_number(a:b)
" Get the closest colour
let l:x = <SID>rgb_number(a:r)
let l:y = <SID>rgb_number(a:g)
let l:z = <SID>rgb_number(a:b)
if l:gx == l:gy && l:gy == l:gz
" There are two possibilities
let l:dgr = <SID>grey_level(l:gx) - a:r
let l:dgg = <SID>grey_level(l:gy) - a:g
let l:dgb = <SID>grey_level(l:gz) - a:b
let l:dgrey = (l:dgr * l:dgr) + (l:dgg * l:dgg) + (l:dgb * l:dgb)
let l:dr = <SID>rgb_level(l:gx) - a:r
let l:dg = <SID>rgb_level(l:gy) - a:g
let l:db = <SID>rgb_level(l:gz) - a:b
let l:drgb = (l:dr * l:dr) + (l:dg * l:dg) + (l:db * l:db)
if l:dgrey < l:drgb
" Use the grey
return <SID>grey_colour(l:gx)
else
" Use the colour
return <SID>rgb_colour(l:x, l:y, l:z)
endif
else
" Only one possibility
return <SID>rgb_colour(l:x, l:y, l:z)
endif
endfun
" Returns the palette index to approximate the 'rrggbb' hex string
fun <SID>rgb(rgb)
let l:r = ("0x" . strpart(a:rgb, 0, 2)) + 0
let l:g = ("0x" . strpart(a:rgb, 2, 2)) + 0
let l:b = ("0x" . strpart(a:rgb, 4, 2)) + 0
return <SID>colour(l:r, l:g, l:b)
endfun
" Sets the highlighting for the given group
fun <SID>X(group, fg, bg, attr)
if a:fg != ""
exec "hi " . a:group . " guifg=#" . a:fg . " ctermfg=" . <SID>rgb(a:fg)
endif
if a:bg != ""
exec "hi " . a:group . " guibg=#" . a:bg . " ctermbg=" . <SID>rgb(a:bg)
endif
if a:attr != ""
exec "hi " . a:group . " gui=" . a:attr . " cterm=" . a:attr
endif
endfun
" Vim Highlighting
call <SID>X("Normal", s:foreground, s:background, "")
call <SID>X("LineNr", s:comment, s:line, "")
call <SID>X("ColorColumn", "", s:line, "")
call <SID>X("NonText", s:selection, "", "")
call <SID>X("SpecialKey", s:selection, "", "")
call <SID>X("Search", s:background, s:yellow, "")
call <SID>X("TabLine", s:foreground, s:background, "reverse")
call <SID>X("StatusLine", s:foreground, s:background, "reverse")
call <SID>X("StatusLineNC", s:foreground, s:background, "reverse")
call <SID>X("Visual", "", s:selection, "")
call <SID>X("Directory", s:blue, "", "")
call <SID>X("ModeMsg", s:green, "", "")
call <SID>X("MoreMsg", s:green, "", "")
call <SID>X("Question", s:green, "", "")
call <SID>X("WarningMsg", s:red, "", "")
if version >= 700
call <SID>X("CursorLine", "", s:line, "none")
call <SID>X("CursorColumn", "", s:line, "none")
call <SID>X("PMenu", s:foreground, s:selection, "none")
call <SID>X("PMenuSel", s:foreground, s:selection, "reverse")
end
" Standard Highlighting
call <SID>X("Comment", s:comment, "", "")
call <SID>X("Todo", s:comment, "", "")
call <SID>X("Title", s:comment, "", "")
call <SID>X("Identifier", s:red, "", "none")
call <SID>X("Statement", s:foreground, "", "")
call <SID>X("Conditional", s:foreground, "", "")
call <SID>X("Repeat", s:foreground, "", "")
call <SID>X("Structure", s:purple, "", "")
call <SID>X("Function", s:blue, "", "")
call <SID>X("Constant", s:orange, "", "")
call <SID>X("String", s:green, "", "")
call <SID>X("Special", s:foreground, "", "")
call <SID>X("PreProc", s:purple, "", "")
call <SID>X("Operator", s:aqua, "", "none")
call <SID>X("Type", s:blue, "", "none")
call <SID>X("Define", s:purple, "", "none")
call <SID>X("Include", s:blue, "", "")
"call <SID>X("Ignore", "666666", "", "")
" Vim Highlighting
call <SID>X("vimCommand", s:red, "", "none")
" C Highlighting
call <SID>X("cType", s:yellow, "", "")
call <SID>X("cStorageClass", s:purple, "", "")
" PHP Highlighting
call <SID>X("phpVarSelector", s:red, "", "")
call <SID>X("phpKeyword", s:purple, "", "")
call <SID>X("phpRepeat", s:purple, "", "")
call <SID>X("phpConditional", s:purple, "", "")
call <SID>X("phpStatement", s:purple, "", "")
call <SID>X("phpMemberSelector", s:foreground, "", "")
" Ruby Highlighting
call <SID>X("rubySymbol", s:green, "", "")
call <SID>X("rubyConstant", s:yellow, "", "")
call <SID>X("rubyAttribute", s:blue, "", "")
call <SID>X("rubyInclude", s:blue, "", "")
call <SID>X("rubyLocalVariableOrMethod", s:orange, "", "")
call <SID>X("rubyCurlyBlock", s:orange, "", "")
" Python Highlighting
call <SID>X("pythonInclude", s:purple, "", "")
call <SID>X("pythonStatement", s:purple, "", "")
call <SID>X("pythonConditional", s:purple, "", "")
call <SID>X("pythonFunction", s:blue, "", "")
" JavaScript Highlighting
call <SID>X("javaScriptBraces", s:foreground, "", "")
call <SID>X("javaScriptFunction", s:purple, "", "")
call <SID>X("javaScriptConditional", s:purple, "", "")
call <SID>X("javaScriptRepeat", s:purple, "", "")
call <SID>X("javaScriptNumber", s:orange, "", "")
call <SID>X("javaScriptMember", s:orange, "", "")
" Delete Functions
delf <SID>X
delf <SID>rgb
delf <SID>colour
delf <SID>rgb_colour
delf <SID>rgb_level
delf <SID>rgb_number
delf <SID>grey_colour
delf <SID>grey_level
delf <SID>grey_number
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment