Skip to content

Instantly share code, notes, and snippets.

@ngnguyen1
Created April 16, 2012 04:14
Show Gist options
  • Save ngnguyen1/2396316 to your computer and use it in GitHub Desktop.
Save ngnguyen1/2396316 to your computer and use it in GitHub Desktop.
Vim Config
if has("syntax")
syntax on
endif
if has("autocmd")
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
au BufWritePost *.sh !chmod +x %
au BufWritePost *.py !chmod +x %
endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
set nocompatible
filetype on
filetype plugin on
filetype indent on
function! VLoadTemplate()
silent! 0r $HOME/.vim/templates/%:e.tpl
syn match Todo "%\u\+%" containedIn=ALL
endfunction
function! VSetFileType()
autocmd FileType pascal setl smarttab tabstop=2 shiftwidth=2 sts=2 autoindent expandtab
autocmd FileType c call VSetIndent() | setl cindent
autocmd FileType cpp call VSetIndent()
autocmd FileType java call VSetIndent()
autocmd FileType html setl smarttab tabstop=2 shiftwidth=2 sts=2 autoindent expandtab
autocmd FileType php call VSetIndent()
autocmd FileType sh,bash call VSetIndent()
autocmd FileType perl call VSetIndent()
autocmd FileType python call VSetIndent()
autocmd FileType javascript call VSetIndent()
endfunction
function! VSetNormalSetting()
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showmatch " Show matching brackets.
set ignorecase " Do case insensitive matching
"set autowrite " Automatically save before commands like :next and :make
set hidden " Hide buffers when they are abandoned
set smartcase " Do smart case matching
set mouse=a " Enable mouse usage (all modes)
set showcmd " Show (partial) command in status line.
set dictionary+=~/.vim/dictionary/word
set tabstop=4
set expandtab
set title
set shiftwidth=4
set smartindent
set incsearch " find as your type search before you press enter
set number " Display number
set hlsearch " highlight when you search
set winminheight=0 " set windown height = 0 or you can be set wmh=0
set scrolloff=5
set cursorline
hi cursorline guibg=#333333
hi CursorColumn guibg=#333333
set stal=2
set tabline=%!MyTabLine()
set showtabline=1
set t_Co=256 " To enable 256 colors in Vim
endfunction
" Source a global configuration file if available
if filereadable("~/.vimrc")
source ~/.vim
endif
colorscheme chance
set laststatus=2
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ *\%{strftime(\"\%c\",getftime(expand(\"%\%\")))}* \ %=Line:\ %l/%L:%c
function! HasPaste()
if &paste
return 'PASTE MODE '
else
return ''
endif
endfunction
function! MyTabLine()
let s = ''
let wn = ''
let t = tabpagenr()
let i = 1
while i <= tabpagenr('$')
let buflist = tabpagebuflist(i)
let winnr = tabpagewinnr(i)
let s .= '%' . i . 'T'
let s .= (i == t ? '%1*' : '%2*')
let s .= ' '
let wn = tabpagewinnr(i,'$')
let s .= '%#TabNum#'
let s .= i
let s .= (i == t ? '%#TabLineSel#' : '%#TabLine#')
let bufnr = buflist[winnr - 1]
let file = bufname(bufnr)
let buftype = getbufvar(bufnr, 'buftype')
if buftype == 'nofile'
if file =~ '\/.'
let file = substitute(file, '.*\/\ze.', '', '')
endif
else
let file = fnamemodify(file, ':p:t')
endif
if file == ''
let file = '[No Name]'
endif
let s .= ' ' . file . ' '
let i = i + 1
endwhile
let s .= '%T%#TabLineFill#%='
let s .= (tabpagenr('$') > 1 ? '%999XX' : 'X')
return s
endfunction
set stal=2
set tabline=%!MyTabLine()
set showtabline=1
highlight link TabNum Special
"if has('statusline')
"set laststatus=2
" set statusline=%<%f\
" set statusline+=%w%h%m%r
" set statusline+=\ [%{&ff}/%Y]
" set statusline+=\ [%{getcwd()}]
" set statusline+=%=%-14.(%l,%c%V%)\ %p%%
"endif
"function! DateInsert()
" $delete
" read !date
"endfunction
function! VSetKeyMap()
"D.nga's keyboard mapping
nnoremap <C-p> /%\u.\{-1,}%<CR>c/%/e<CR>
map tn :tabnew<Space>
map te :tabedit<Space>
map <S-q> :q<cr>
map <F8> :!<Space>
map <S-Tab> gt
map tv :vsplit<CR>
map ts :split<CR>
map <F5> :update<cr>
imap <F5> <Esc>:update<cr>
map <Del> :bd<cr>
imap <Del> <Esc>:bd<cr>
map <F2> :echo 'Current time is ' . strftime('%c')<CR>
"map <F3> <F2>
map <F4> <ESC>:exec "help ".expand("<cWORD>")<CR>
map <F6> :buffers <CR>
imap <F6> <ESC> :buffers<CR>
map bn :bnext<CR>
map bp :bprevious<CR>
" moving in windows
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map <C-L> <C-W>l<C-W>_
map <C-H> <C-W>h<C-W>_
"nmap h <Nop>
endfunction
function! VSetTemplate()
autocmd! BufNewFile * call VLoadTemplate()
autocmd! BufNewFile,BufNewRead *.java colorscheme nduynga
autocmd! BufNewFile,BufNewRead *.c colorscheme diablo3
autocmd! BufNewFile,BufNewRead *.js colorsheme delek
autocmd! BufNewFile,BufNewRead *.html colorscheme chance
autocmd! BufNewFile,BufNewRead *.cpp colorscheme diablo3
autocmd! BufNewFile,BufNewRead *.py colorscheme pychimp
autocmd! BufNewFile,BufNewRead *.rb colorscheme ubloh
autocmd! BufNewFile,BufNewRead *.sh colorscheme diablo3
endfunction
function! SimpleBalloon()
return 'Cursor is at line/column: ' . v:beval_lnum .
\'/' . v:beval_col .
\ ' in file ' . bufname(v:beval_bufnr) .
\ '. Word under cursor is: "' . v:beval_text . '"'
endfunction
function! VSetIndent()
setl smarttab tabstop=4 shiftwidth=4 sts=4 autoindent expandtab
setl cino=(0
endfunction
call VSetTemplate()
call VSetKeyMap()
call VSetNormalSetting()
call SimpleBalloon()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment