Skip to content

Instantly share code, notes, and snippets.

@hanji
Created September 9, 2012 19:30
Show Gist options
  • Save hanji/3686705 to your computer and use it in GitHub Desktop.
Save hanji/3686705 to your computer and use it in GitHub Desktop.
vim configuration file
"vim configuration file
"(C) Copyright 2009-2012, Ji Han
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set fileencodings=ucs-bom,utf-8,gbk,big5,euc-jp,euc-kr,default
set encoding=utf-8
language message en_US.utf-8
set langmenu=en_US.utf-8
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible
set nomodeline
set visualbell t_vb=
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
set history=800
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
filetype plugin indent on
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
au FileType make setl ts=8 sts=8 sw=8 noet
au FileType css,html,javascript,xhtml,xml,xsd,xslt setl ts=2 sts=2 sw=2 noet
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"timestamps
"press Alt-I then T to insert current date and time in default format
imap <silent> <M-i>t <C-R>=strftime("%c")<CR>
nmap <M-i>t a<M-i>t<Esc>
vmap <M-i>t <Esc><M-i>tgv
"type `today<Tab>' to insert current date (like `Sunday, October 10, 2010')
imap <silent> today<Tab>
\ <C-R>=strftime("%A, %B ") . join(map(split(strftime("%d %Y")), 'abs(v:val)'), ', ')<CR>
"type `now<Tab>' to insert current time (like `10:10 AM')
imap <silent> now<Tab>
\ <C-R>=join(map(split(strftime("%I")), 'abs(v:val)')) . strftime(":%M %p")<CR>
"keep the `last updated' timestamp up to date
au BufWritePre * exe
\ 'silent! :%s/\(^.\{,8}\)\@<=\(last[- ]\)\(updated\|modified\):\s\+.*$/\2\3: '
\ . substitute(strftime('%a %b %d %H:%M:%S %Y'), '/', '\\/', 'g') . '/i'
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set clipboard=unnamed
set backspace=indent,eol,start
set whichwrap=b,s,<,>,[,]
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set autowriteall
"set backup backupdir=./.backup,~/.backup,.,$TEMP
"au BufWritePre * let &bex = '.' . strftime("%Y%m%d%H%M%S") . '.bak'
set hidden
set switchbuf=usetab,newtab
set nobackup nowritebackup
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set guioptions-=T
try | set guifont=Monaco:h10 | endtry
try | set guifontwide=NSimsun | endtry
set linespace=0 lines=33 columns=132
set nowrap
nmap <M-o>w :setl wrap! wrap?<CR>
imap <M-o>w <C-o><M-o>w
vmap <M-o>w <Esc><M-o>wgv
setg textwidth=78
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set showcmd
set number
nmap <M-o>n :setl number! number?<CR>
imap <M-o>n <C-o><M-o>n
vmap <M-o>n <Esc><M-o>ngv
set ruler
set cursorline
nmap <M-o>c :setl cursorline! cursorline?<CR>
imap <M-o>c <C-o><M-o>c
vmap <M-o>c <Esc><M-o>cgv
set list listchars=tab:>-,trail:-
nmap <M-o>l :setl list! list?<CR>
imap <M-o>l <C-o><M-o>l
vmap <M-o>l <Esc><M-o>lgv
au FileType css,html,javascript,xhtml,xml,xsd,xslt setl nolist
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set hlsearch
nmap <M-o>h :setl hlsearch! hlsearch?<CR>
imap <M-o>h <C-o><M-o>h
vmap <M-o>h <Esc><M-o>hgv
set incsearch
set ignorecase smartcase
nmap <M-o>i :setl ignorecase! ignorecase?<CR>
imap <M-o>i <C-o><M-o>i
vmap <M-o>i <Esc><M-o>igv
"grep always print filenames
if has("unix") | set grepprg=grep\ -nH\ $*\ /dev/null | endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set showmatch
au FileType html,xhtml,xml,xsd,xslt setl matchpairs+=<:>
au FileType * inoremap <buffer> " ""<Left>
au FileType vim iunmap <buffer> "
"parenthesis matching (completion and deletion)
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
"quick and dirty. makes BS kind of expensive. hopefully vim users don't BS heavily
function! SmartBS()
if getline('.')[col('.')-2:col('.')-1] == "()"
return "\<C-O>cab"
elseif getline('.')[col('.')-2:col('.')-1] == "[]"
return "\<C-O>ca]"
elseif getline('.')[col('.')-2:col('.')-1] == "{}"
return "\<C-O>ca}"
else
return "\<BS>"
endif
endf
inoremap <silent> <BS> <C-R>=SmartBS()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Ctrl-BS to delete current word; prefix a count for repeating
nmap <silent> <C-BS> @='bdaw'<CR>
imap <silent> <C-BS> <C-O><C-BS>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Alt-up/Alt-down to move lines, keeping cursor position and visual selection
function! MoveLines(offset) range
let l:col = virtcol('.')
let l:offset = str2nr(a:offset)
exe 'silent! :' . a:firstline . ',' . a:lastline . 'm'
\ . (l:offset > 0 ? a:lastline + l:offset : a:firstline + l:offset)
exe 'normal ' . l:col . '|'
endf
imap <silent> <M-up> <C-O>:call MoveLines('-2')<CR>
imap <silent> <M-down> <C-O>:call MoveLines('+1')<CR>
nmap <silent> <M-up> :call MoveLines('-2')<CR>
nmap <silent> <M-down> :call MoveLines('+1')<CR>
vmap <silent> <M-up> :call MoveLines('-2')<CR>gv
vmap <silent> <M-down> :call MoveLines('+1')<CR>gv
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"transpose words (like emacs `transpose-words')
function! TransposeWords()
if search('\w\+\%#\w*\W\+\w\+')
elseif search('\w\+\W\+\%#\W*\w\+')
endif
let l:pos = getpos('.')
exe 'silent! :s/\(\%#\w\+\)\(\W\+\)\(\w\+\)/\3\2\1/'
call setpos('.', l:pos)
let l:_ = search('\(\%#\w\+\W\+\)\@<=\w\+')
normal el
endf
nmap <silent> <M-right> :call TransposeWords()<CR>
imap <silent> <M-right> <C-O>:call TransposeWords()<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set autoindent smartindent
au FileType c,cpp setl cindent
set foldmethod=marker
if has("gui_running") | colorscheme rubyblue | endif
syntax enable
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
let g:html_use_xhtml = 1
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"Last-updated: Fri Sep 21 15:44:22 2012
".vimrc ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment