vimenv

configure vim environment
git clone git://git.unixkoans.com/vimenv.git
Log | Files | Refs | Submodules

commit 150879ca771f8fdbef1af3a3df90503f2ecbb516
Author: Xiaodong Xu <xxdlhy@gmail.com>
Date:   Sun Apr 15 02:08:29 +0800

Initial commit

Diffstat:
.gitmodules | 24++++++++++++++++++++++++
README | 1+
_vim/bundle/Command-T | 1+
_vim/bundle/fugitive | 1+
_vim/bundle/jellybeans | 1+
_vim/bundle/nerdcommenter | 1+
_vim/bundle/pathogen | 1+
_vim/bundle/powerline | 1+
_vim/bundle/smartinput | 1+
_vim/bundle/tagbar | 1+
_vim/conf/abbrevs.vim | 19+++++++++++++++++++
_vim/conf/base.vim | 18++++++++++++++++++
_vim/conf/funcs.vim | 101+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
_vim/conf/latex.vim | 48++++++++++++++++++++++++++++++++++++++++++++++++
_vim/conf/perl.vim | 36++++++++++++++++++++++++++++++++++++
_vim/conf/plugin.vim | 33+++++++++++++++++++++++++++++++++
_vim/conf/ruby.vim | 16++++++++++++++++
_vimrc | 150+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
vimenv | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19 files changed, 510 insertions(+), 0 deletions(-)
diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,24 @@ +[submodule "_vim/bundle/fugitive"] + path = _vim/bundle/fugitive + url = git://github.com/tpope/vim-fugitive.git +[submodule "_vim/bundle/pathogen"] + path = _vim/bundle/pathogen + url = git://github.com/tpope/vim-pathogen.git +[submodule "_vim/bundle/jellybeans"] + path = _vim/bundle/jellybeans + url = git://github.com/nanotech/jellybeans.vim.git +[submodule "_vim/bundle/powerline"] + path = _vim/bundle/powerline + url = git://github.com/Lokaltog/vim-powerline.git +[submodule "_vim/bundle/smartinput"] + path = _vim/bundle/smartinput + url = git://github.com/kana/vim-smartinput.git +[submodule "_vim/bundle/Command-T"] + path = _vim/bundle/Command-T + url = git://github.com/wincent/Command-T.git +[submodule "_vim/bundle/nerdcommenter"] + path = _vim/bundle/nerdcommenter + url = git://github.com/scrooloose/nerdcommenter.git +[submodule "_vim/bundle/tagbar"] + path = _vim/bundle/tagbar + url = git://github.com/majutsushi/tagbar.git diff --git a/README b/README @@ -0,0 +1 @@ +Configure Vim environment. diff --git a/_vim/bundle/Command-T b/_vim/bundle/Command-T @@ -0,0 +1 @@ +Subproject commit ca5566eb312f57b9f4091023cfc03ad8e692bf29 diff --git a/_vim/bundle/fugitive b/_vim/bundle/fugitive @@ -0,0 +1 @@ +Subproject commit 4fe6e46a0ace8196aa1946b91cd02e853f8db9da diff --git a/_vim/bundle/jellybeans b/_vim/bundle/jellybeans @@ -0,0 +1 @@ +Subproject commit 2c306097f8320286ae26fd9e45b9c0a8911ec210 diff --git a/_vim/bundle/nerdcommenter b/_vim/bundle/nerdcommenter @@ -0,0 +1 @@ +Subproject commit cb242a9cb41e9fc9884caa2235c67d18b18e9067 diff --git a/_vim/bundle/pathogen b/_vim/bundle/pathogen @@ -0,0 +1 @@ +Subproject commit c9fb89dd6efdeedb95c411ec78b3a9493602d33d diff --git a/_vim/bundle/powerline b/_vim/bundle/powerline @@ -0,0 +1 @@ +Subproject commit 99277d9eed97a59cacc1db8c1dece2bcfd96d877 diff --git a/_vim/bundle/smartinput b/_vim/bundle/smartinput @@ -0,0 +1 @@ +Subproject commit 4dd4d6679113716937d0dbbaf41c4175b8ad4dac diff --git a/_vim/bundle/tagbar b/_vim/bundle/tagbar @@ -0,0 +1 @@ +Subproject commit eab0e67d1bb46884b7285cbe206f259fb2bade70 diff --git a/_vim/conf/abbrevs.vim b/_vim/conf/abbrevs.vim @@ -0,0 +1,19 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 Apr 16 +" + +"-- abbrevs --" + +iab _au author: Xu Xiaodong <xxdlhy@gmail.com> +iab _mo <c-r>="modified: " . strftime("%Y %b %d")<cr> + +iab _na Xu Xiaodong +iab _ma xxdlhy@gmail.com +iab _da <c-r>=strftime("%Y %b %d")<cr> + +iab _fn <c-r>=bufname("%")<cr> +iab _pl #!/usr/bin/env perl + +iab _xt http://linuxtoy.org +iab _xm <!--more--> diff --git a/_vim/conf/base.vim b/_vim/conf/base.vim @@ -0,0 +1,18 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 May 08 +" + +"-- base --" + +" make tab ident code +nmap <tab> I<tab><esc> +vmap <tab> >gv +nmap <s-tab> ^i<bs><esc> +vmap <s-tab> <gv + +" set modeline +nmap _m :call _set_modeline()<cr> + +" auto update timestamps +autocmd BufWritePre * call _last_modified() diff --git a/_vim/conf/funcs.vim b/_vim/conf/funcs.vim @@ -0,0 +1,101 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 Nov 26 +" + +"-- update timestamps --" + +function! _last_modified() + if &modified + let save_cursor = getpos(".") + let n = min([20, line("$")]) + keepjumps exe '1,' . n . 's#^\(.\{,10}modified: \+\).*#\1' . + \ strftime('%Y %b %d') . '#e' + call histdel('search', -1) + call setpos('.', save_cursor) + endif +endfunction + +"-- set modeline --" + +function! _set_modeline() + let filetype = input("Please enter file type: ", expand('<cword>')) + exe "normal i# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=" . filetype +endfunction + +"-- add ruby head --" + +function! _ruby_head() + let filename = bufname("%") + let date = strftime("%Y %b %d") + exe "normal i#!/usr/bin/env ruby" + exe "normal o# coding: utf-8" + exe "normal o#" + exe "normal o# name: " . filename + exe "normal o# author: Xu Xiaodong <xxdlhy@gmail.com>" + exe "normal o# license: GPL" + exe "normal o# created: " . date + exe "normal o# modified: " . date + exe "normal o#" +endfunction + +"-- add perl head --" + +function! _perl_head() + let filename = bufname("%") + let date = strftime("%Y %b %d") + exe "normal i#!/usr/bin/env perl" + exe "normal o#" + exe "normal o# name: " . filename + exe "normal o# author: Xu Xiaodong <xxdlhy@gmail.com>" + exe "normal o# license: GPL" + exe "normal o# created: " . date + exe "normal o# modified: " . date + exe "normal o#" +endfunction + +"-- add perl 'use' statement --" + +" make sure you have +" setlocal iskeyword=48-57,_,A-Z,a-z,: +" so colons are recognized as part of a keyword + +function! _perl_use() + let s:package = input('Package? ', expand('<cword>')) + " skip if that use statement already exists + if (search('^use\s\+'.s:package, 'bnw') == 0) + " below the last use statement, except for some special cases + let s:line = search('^use\s\+\(constant\|strict\|warnings\|parent\|base\|5\)\@!','bnw') + " otherwise, below the ABSTRACT (see Dist::Zilla) + if (s:line == 0) + let s:line = search('^# ABSTRACT','bnw') + endif + " otherwise, below the package statement + if (s:line == 0) + let s:line = search('^package\s\+','bnw') + endif + " if there isn't a package statement either, put it below + " the last use statement, no matter what it is + if (s:line == 0) + let s:line = search('^use\s\+','bnw') + endif + " if there are no package or use statements, it might be a + " script; put it below the shebang line + if (s:line == 0) + let s:line = search('^#!','bnw') + endif + " if s:line still is 0, it just goes at the top + call append(s:line, 'use ' . s:package . ';') + endif +endfunction + +"-- perl comment --" + +function! _perl_comment() + let l = getline('.') + if l =~ '^#' + exe 's/^#//g' + else + exe 's/^/#/g' + endif +endfunction diff --git a/_vim/conf/latex.vim b/_vim/conf/latex.vim @@ -0,0 +1,48 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 Apr 16 +" + +"-- latex --" + +" ,rl = run latex +map ,rl :!latex % + +" ,rx = run xelatex +map ,rx :!xelatex % + +" ,vd = view dvi file +map ,vd :!xdvi %<.dvi + +" ,cps = create ps file (from dvi file of current file) +map ,cps :!dvips %<.dvi -o:!ghostview %<.ps + +" ,rd = run dvipdf +map ,rd :!dvipdf %<.dvi + +" ,vp = view pdf file +map ,vp :!epdfview %<.pdf + +map! ]i \item +map! ]bi \begin{itemize} +map! ]ei \end{itemize} +map! ]be \begin{enumerate} +map! ]ee \end{enumerate} +map! ]bd \begin{description} +map! ]ed \end{description} +map! ]bc \begin{center} +map! ]ec \end{center} +map! [be {\samepage\begin{eqnarray} +map! [ee \end{eqnarray}} +map! ]s1 \section{ +map! ]s2 \subsection{ +map! ]s3 \subsubsection{ +map! ]p1 \paragraph{ +map! ]p2 \subparagraph{ +map! ]f \frac{ +map! ]o \overline{ +map! ]u \underline{ +map! ;em bi{\em lea}i +map! ]fn \footnote{ +map! ]bl \begin{lstlisting}[frame=tb] +map! ]el \end{lstlisting} diff --git a/_vim/conf/perl.vim b/_vim/conf/perl.vim @@ -0,0 +1,36 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 May 08 +" + +"-- perl --" + +let perl_include_pod=1 +let perl_extended_vars=1 +let perl_sync_dist=250 + +nmap <leader>p :call _perl_head()<cr> +nmap <leader>us :<c-u>call _perl_use()<cr> + +" comment +nmap _c :call _perl_comment()<cr> +vmap _c :call _perl_comment()<cr> + +" tidy selected lines (or entire file) with _t: +nmap <silent> _t :%!perltidy -q<cr> +vmap <silent> _t :!perltidy -q<cr> + +" check perl code with :make +autocmd FileType perl set makeprg=perl\ -c\ %\ $* +autocmd FileType perl set errorformat=%f:%l:%m +autocmd Filetype perl set equalprg=perltidy +autocmd FileType perl set autowrite + +" pressing K while on a keyword will bring up perldoc +autocmd FileType perl :nmap K :!perldoc <cword> <bar><bar> perldoc -f <cword><cr> + +" perl file header +autocmd BufNewFile *.pl call _perl_head() + +" compile check +autocmd! FileType perl :nmap <leader>c :!time perl -MVi::QuickFix -c %<cr> diff --git a/_vim/conf/plugin.vim b/_vim/conf/plugin.vim @@ -0,0 +1,33 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2012 Apr 14 +" + +"-- plugin --" + +" pathogen +runtime bundle/pathogen/autoload/pathogen.vim +call pathogen#infect() +call pathogen#helptags() + +" commant-t +let g:CommandTAlwaysShowDotFiles=1 +let g:CommandTScanDotDirectories=1 + +" gsession +let g:local_session_filename='.session.vim' + +" align +vmap <silent> <leader>i= <esc>:AlignPush<cr>:AlignCtrl lp1P1<cr>:'<,'>Align =<cr>:AlignPop<cr> +vmap <silent> <leader>i, <esc>:AlignPush<cr>:AlignCtrl lp0P1<cr>:'<,'>Align ,<cr>:AlignPop<cr> +vmap <silent> <leader>i( <esc>:AlignPush<cr>:AlignCtrl lp0P0<cr>:'<,'>Align (<cr>:AlignPop<cr> + +" yankring +map <leader>y :YRShow<cr> + +" closetag +"let g:closetag_html_style=1 +"source ~/.vim/scripts/closetag.vim + +" mail +"autocmd BufRead ~/.mutt/temp/mutt* :source ~/.vim/conf/mail.vim diff --git a/_vim/conf/ruby.vim b/_vim/conf/ruby.vim @@ -0,0 +1,16 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2011 May 08 +" + +"-- ruby --" + +" completion +let g:rubycomplete_buffer_loading=1 +let g:rubycomplete_classes_in_global=1 + +" file header +autocmd BufNewFile *.rb call _ruby_head() + +" map +nmap <leader>rb :call _ruby_head()<cr> diff --git a/_vimrc b/_vimrc @@ -0,0 +1,150 @@ +" +" author: Xu Xiaodong <xxdlhy@gmail.com> +" modified: 2012 Apr 14 +" + +"-- source --" + +source ~/.vim/conf/abbrevs.vim +source ~/.vim/conf/base.vim +source ~/.vim/conf/funcs.vim +source ~/.vim/conf/latex.vim +source ~/.vim/conf/perl.vim +source ~/.vim/conf/plugin.vim +source ~/.vim/conf/ruby.vim + +"-- base --" + +set nocompatible +set hidden +set relativenumber +set ruler +set cursorline +set wildmenu +set splitbelow + +set history=500 +set scrolloff=6 +set cmdheight=1 +set display=lastline +set omnifunc=syntaxcomplete#Complete + +set laststatus=2 +set statusline=\ [%n]\ \ %F%m%r\ \ %h%y%w\ \ [%l,%c]\ \ [%L]\ \ [%P] + +syntax on + +"-- colorscheme --" + +if &t_Co < 256 + colorscheme miro8 +else + colorscheme jellybeans +endif + +"-- file --" + +filetype plugin indent on + +set autoread +set noswapfile +set nowritebackup + +set fileencoding=utf-8 +set fileencodings=ucs-bom,utf-8,gb18030,default + +"-- format --" + +set expandtab +set smarttab +set shiftround +set tabstop=2 +set shiftwidth=2 +set softtabstop=2 +set textwidth=78 + +set autoindent +set smartindent +set copyindent + +set foldenable +set foldmethod=marker + +set backspace=indent,eol,start +set iskeyword+=: +set matchpairs+=<:> +set whichwrap+=<,>,h,l + +set list +set listchars=tab:›\ ,eol:¬ + +set formatprg=par-format\ -w78 + +"-- search --" + +set smartcase +set incsearch +set hlsearch +set gdefault +set showmatch + +set grepprg=ack +set grepformat=%f:%l:%m + +"-- map --" + +let mapleader=',' + +map ; : + +" exit back to normal mode +imap jj <esc> + +nmap <leader>w :w!<cr> + +nmap <leader>s :source $MYVIMRC<cr> +nmap <leader>e :e! $MYVIMRC<cr> + +" formatting paragraph +nmap Q gqap" +vmap Q gq + +nmap <C-h> <C-w>h +nmap <C-j> <C-w>j +nmap <C-k> <C-w>k +nmap <C-l> <C-w>l + +" open a new vertical split and switch over to it +nmap <leader>l <c-w>v<c-w>l + +" horizontal split +nmap <leader>- <c-w>s<c-w>j + +" close window +nmap <leader>cw :close<cr> + +" grep +map <leader>n :cn<cr> +map <leader>p :cp<cr> + +" search +map <space> / +map <m-space> ? +nmap <silent> <leader>/ :nohlsearch<cr> + +" paste mode +set pastetoggle=<f2> + +" remove indenting on empty lines +map <f3> :%s/\s*$//g<cr>:noh<cr>'' + +" strip all trailing whitespace in the current file +nmap <leader>W :%s/\s\+$//<cr>:let @/=''<cr> + +" remove the Windows ^M +nmap <leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm + +"-- other --" + +" reload .vimrc +autocmd! BufWritePost vimrc source ~/.vimrc diff --git a/vimenv b/vimenv @@ -0,0 +1,56 @@ +#!/usr/bin/env ruby +# coding: utf-8 +# +# name: vimenv +# author: Xu Xiaodong <xxdlhy@gmail.com> +# license: GPL +# created: 2012 Apr 14 +# modified: 2012 Apr 15 +# + +require 'fileutils' +require 'optparse' + +def init + conf = %w[vimrc vim] + conf.each do |item| + orig = Dir.pwd + '/_' + item + target = Dir.home + '/.' + item + + puts "Symlinking #{orig} to #{target}" + FileUtils.symlink(orig, target, force: true) + end +end + +def add(author_slash_name) + name = author_slash_name.gsub(/^.*\/(?:vim-)?(.*)(?:\.vim)?$/, '\1') + + src = 'git://github.com/' + author_slash_name + '.git' + desc = '_vim/bundle/' + name + + puts "Adding #{src} to #{desc}" + + arg = ["add #{src} #{desc}", "init", "update"] + + arg.each do |elt| + system "git submodule #{elt}" + end +end + +def update + puts "Updating Vim plugins" + system "git submodule foreach git pull" +end + +opts = OptionParser.new +opts.on("-i", "--init", "Initialize Vim environment") { init } +opts.on("-a", "--add NAME", "Add Vim plugins") { |val| add(val) } +opts.on("-u", "--update", "Update Vim plugins") { update } + +if ARGV.empty? + puts opts.to_s +else + opts.parse(*ARGV) +end + +# vim: ai:et:ts=2:sw=2:sts=2:tw=78:ft=ruby