Chinaunix首页 | 论坛 | 博客
  • 博客访问: 72035
  • 博文数量: 21
  • 博客积分: 1478
  • 博客等级: 上尉
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2007-08-22 20:41
文章分类

全部博文(21)

文章存档

2011年(1)

2010年(2)

2009年(18)

我的朋友

分类: LINUX

2009-10-14 18:34:05


"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
Author: YangYingchao
" Email: yangyingchao@gmail.com
"

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
Update Log:
" V1: Someday in 2009: Created and modified;

文件:vimrc.rc.tar.bz2
大小:20KB
下载:下载

" V2: 2009,05,25: Update a shotkey to hide #ifdef Macro.
" V3: 2009,06,03: Update a function to control NERDTree with sigle
"
key; Update coding standadrd for Python.
" V3: 2009,06,04: Bind to

文件:vim_config.tar.bz2
大小:5KB
下载:下载

run Bash, to run python.
"
V4: 2009,06,05: Added some platform specific settings: fonts,
" backups, and so on.
"
V5: 2009,07,03: Added key settings related to subversion.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"*******************************************
"
Part One: General A list of 'set' command.
"*******************************************
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " A varible to judge whether it is Windows OS or not
    let s:MSWIN = has("
win16") || has("win32") || has("win64")

    "
Set mapleader
    let mapleader = ","
    let g:mapleader = ","
    let g:C_MapLeader = ','

    "Get out of VI's compatible mode..
    set nocompatible

    "
Sets how many lines of history VIM har to remember
    set history=100

    "Auto read a file when it has been changed by other program
    set autoread

    "
Enable filetype plugin
    filetype plugin on
    filetype indent on
    syntax on

    "Favorite filetypes
    set ffs=unix,dos

    "
Turn on WiLd menu
    set wildmenu
    "Always show current position
    set ruler
    "
The commandbar is 1 high
    set cmdheight=1
    "Don't show line number
    set nonu
    "
Do not redraw, when running macros.. lazyredraw
    set lz
    "Change buffer - without saving
    set hid
    "
Set backspace
    set backspace=eol,start,indent
    "Bbackspace and cursor keys wrap to
    "
set whichwrap+=<,>,h,l
    set whichwrap+=<,>
    "Increase search mode
    set incsearch
    "
Highlight search things
    set hlsearch
    "Set magic on
    set magic
    set nobackup
    "
No sound on errors.
    set noerrorbells
    set novisualbell
    "show matching bracets
    set showmatch

    let g:vikiUseParentSuffix=1

    "
Always hide the statusline
    set laststatus=2

    "Tab configuration
    set shiftwidth=4
    set tabstop=4
    set softtabstop=4
    set expandtab

    "
Disable winaltkeys to map Alt.
    set winaltkeys=no

    "set cinoptions={0,1s,t0,n-2,p2s,(03s,=.5s,>1s,=1s,:1s
    set cinoptions=:0,g0,t0,(0

    "
Restore cursor to file position in previous editing session
    set viminfo='20,\"50,:20,n~/.viminfo
    au BufReadPost * if line("
'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif

    augroup filetypedetect
        au! BufRead,BufNewFile *.viki setfiletype viki
    augroup END

    " Session options
    set sessionoptions-=curdir
    set sessionoptions+=sesdir

    "
Text options
    set smarttab
    set tw=78

    "Auto indent
    set autoindent
    set smartindent

    "
Wrap lines
    set wrap

    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    "
Colors and Fonts
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    if has("
gui_running")
        colorscheme mycolor
    else
        colorscheme evening
    endif

    "
GUI settings
    if has("gui_running")
        set guioptions-=T
        set guioptions-=L
        set guioptions-=r
        set guioptions-=m
        set mouse=a

        nmap p "+gp
        nmap y "
+gy

        imap p "+gp
        imap y "
+gy

        au GUIEnter * simalt ~x

        if s:MSWIN
            set guifont=Consolas:h11
        else
            set guifont=Consolas\ 12
        endif
    endif

    "Some nice mapping to switch syntax (useful if one mixes different languages in one file)
    autocmd BufEnter * :syntax sync fromstart

"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"*******************************************
"
Part Two: Configurations about plugins
"*******************************************
"
Required Plugins:
" C-support: Also known as c.vim, a powerful tool to write C/C++" code.
" NERDTree: A tool to explore local and network files and directories.
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    " cscope setting
    if has("
cscope")
        if s:MSWIN
            set csprg=D:\\Bin\cscope.exe
        else
            set csprg=/usr/bin/cscope
        endif
        set csto=1
        set cst
        set nocsverb
      "
add any database in current directory
      if filereadable("cscope.out")
          cs add cscope.out
      endif
      set csverb
    endif

    nmap s :cs find s =expand("")<CR>
    nmap g :cs find g =expand("")<CR>
    nmap c :cs find c =expand("")<CR>
    nmap t :cs find t =expand("")<CR>
    nmap e :cs find e =expand("")<CR>
    nmap f :cs find f =expand("")<CR>
    nmap i :cs find i ^=expand("")<CR>$
    nmap d :cs find d =expand("")<CR>
    nmap h :cs help

    " Taglist
    nmap :Tlist
    imap :Tlist
    let Tlist_Use_Right_Window = 1
    let Tlist_Show_One_File = 1
    let Tlist_WinWidth = 27
    let Tlist_Exit_OnlyWindow = 1

    "
C-Support
    "Mapleader was setted as ',' in previous setting.

    "
NERDTree function
    let s:Dir_F = 0
    func! NERDTree_OC()
        exe "normal mz"
        if s:Dir_F
            let s:Dir_F = 0
            exe "1"
            exe "normal mz"
            exe "NERDTreeClose"
            "exe ":wincmd j"
        else
            let s:Dir_F = 1
            exe "
normal mz"
            exe "
NERDTree"
        endif
    endfunc

"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"*******************************************
"
Part Three: Configurations about filetypes.
"*******************************************
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " C/C++
    autocmd FileType c,cpp map :make
    autocmd FileType c,cpp setlocal cindent
                \ shiftwidth=8
                \ tabstop=8
                \ softtabstop=8

    "
Highlight space errors in C/C++ source files (Vim tip #935)
    if $VIM_HATE_SPACE_ERRORS != '0'
        let c_space_errors=1
    endif

    " ANTLR
    au BufRead,BufNewFile *.g set syntax=antlr3

    "
Insert information of myself automaticaly when commit files using svn.
    au BufRead,BufNewFile svn-commit* call SVN_Insert()

    " HTML related
    let xml_use_xhtml = 1

    "
To HTML
    let html_use_css = 1
    let html_number_lines = 0
    let use_xhtml = 1

    """""""""""""""""""""""""""""""
    "
Vim section
    """""""""""""""""""""""""""""""
    autocmd FileType vim set nofen
    autocmd FileType vim map :w!:source %

    "
"""""""""""""""""""""""""""""
    "
HTML
    """""""""""""""""""""""""""""""
    au FileType html set ft=xml
    au FileType html set syntax=html

    "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Text file: using syntax plain to show all text files.
    "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    au BufRead,BufNewFile rfc*.* set syntax=plain
    au BufRead,BufNewFile RFC*.* set syntax=plain
    au BufRead,BufNewFile *.txt set syntax=plain
    au BufRead,BufNewFile draft* set syntax=plain
    au BufRead,BufNewFile DRAFT* set syntax=plain
    au BufRead,BufNewFile readme set syntax=plain
    au BufRead,BufNewFile README set syntax=plain
    au BufRead,BufNewFile *.log set syntax=log

    au BufRead,BufNewFile *.srt setf srt
    au BufRead,BufNewFile *.srt setl sts=2 dictionary=/home/yyc/.vim/dictionary/srt.dic
    au BufNewFile *srt call SRT_Insert()
    """"""""""""""""""""""""""""""
    " Tex
    "
""""""""""""""""""""""""""""""
    au BufRead,BufNewFile *.tex setl dictionary=/home/yyc/.vim/dictionary/tex.dic

    """"""""""""""""""""""""""""""
    " Python
    "
""""""""""""""""""""""""""""""
    au BufRead,BufNewFile *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4
                \ smarttab expandtab smarttab tw=72
                \ dictionary=/home/yyc/.vim/dictionary/python.dic
                \ syntax=python3
    au BufRead,BufNewFile *.py nmap rr :!python %
    au BufRead,BufNewFile *.py map cc :s/^/# /:nohlsearch
    au BufRead,BufNewFile *.py map co :s/^# //:nohlsearch
    au BufRead,BufNewFile *.py nmap :!python %
    au BufRead,BufNewFile *.sh nmap rr :!bash %

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
*******************************************
" Part For: Key Mappings.
"
*******************************************
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

    "
Keybind of F2 - F12
    nmap :call NERDTree_OC()
    " Was bind to a plugin named qbuf, which was used to display buffers.
    if s:MSWIN
        nmap :!cmd
    else
        nmap :!bash
    endif
    nmap :!python
    "
Was bind by Taglist
    " Was bind by C.vim to show errors when compile C code.
    "
was used by screen: move to the left window.
    " was used by screen: move to the right window.
    "
Others: Not Finished yet.

    "Case Sensitive or insensitive
    map ic :set ic
    map nic :set noic

    "
Fast saving
    nmap ww :w
    imap ,ww :w
    nmap wf :w!
    nmap wa :wa

    "Fast quiting
    nmap xx :x
    nmap qq :x
    nmap qa :xa
    imap ,xx :x
    imap ,qq :x
    nmap xa :xa
    nmap xa :call Myquit()
    vmap xa :call Myquit()
    imap xa :call Myquit()

    "
Windows configuration
    nmap w2 :split
    nmap w3 :vs
    nmap clo :close
    nmap ol :only

    "Buffer -- goto Next and Previous
    map bn :bn
    map bp :bp
    map :bn
    map :bp
    map zz

    "
About Blank lines: delete or merge.
    nmap db :g/^$/,/./j:w
    nmap rb :call ReduceBlankLines():w

    " Sort the
    nmap st :%sort
    vmap st :sort

    nmap mk : call Maketags()

    "
Enable of Disable Spell Check
    nmap sp :set spell
    nmap nsp :set nospell

    " Delete Repeated Lines and sort.
    nmap dr :%sort u
    vmap dr :sort u

    "
Shotkey to change tab configuration
    nmap t8 :set shiftwidth=8 softtabstop=8 tabstop=8
    nmap t4 :set shiftwidth=4 softtabstop=4 tabstop=4
    nmap et :set expandtab
    nmap nt :set noexpandtab

    " Keybind for Subversion.
    nmap ad :! svn add %
    imap ad :! svn add %
    nmap up :! svn up
    nmap ci :! svn ci .
    nmap vd :call Base_diff()

    "
Keybind for Vimdiff
    nmap dg :diffget
    nmap dp :diffput
    vmap dg :diffget
    vmap dp :diffput
    " Fast diff
    nmap df :diffsplit
    set diffopt+=vertical

    "
Shortkey to change Fileformats
    nmap fd :se ff=dos
    nmap fu :se ff=unix

    " Delete the superflous white sapces
    nmap ws :call DeleteTrailingWS():w
    imap ws :call DeleteTrailingWS():w

    "
Fast reloading and editing of .vimrc
    if s:MSWIN
        map sr :source D:\Program Files\Vim\vimrc
    else
        map sr :source ~/.vimrc
    endif
    if s:MSWIN
        map ee :e D:\Program Files\Vim\vimrc
    else
        map ee :e ~/.vimrc
    endif

    " Fast grep
    nmap lv :lv /=expand("
<cword>")/ %:lw
    vmap lv :lv /=GetVisualSelection()/ %:lw

    "
Mics: Other usefull settings.
    vmap ml :s/\n/ /g
    " Switch to current dir
    map cd :cd %:p:h
    "
No heigh color
    nmap :noh
    " Delete duplicated lines.
    nmap dd :call Del_duplicate()

"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"*******************************************
"
Part Five: Functions called by obove key maps.
"*******************************************
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    " Merge Blank lines into one.
    func! ReduceBlankLines()
        exe "
normal mz"
        g/^$/,/./-j
        nohl
        exe "
normal `z"
    endfunc

    "
Fast grep
    function! s:GetVisualSelection()
        let save_a = @a
        silent normal! gv"ay
        let v = @a
        let @a = save_a
        let var = escape(v, '\\/.$*')
        return var
    endfunction

    "
Delete supefoulus white spaces.
    func! DeleteTrailingWS()
      exe "normal mz"
      %s/\s\+$//ge
      nohl
      exe "normal `z"
    endfunc

    " Function to quit program in all modes.
    func! Myquit()
        exe "
normal mz"
        xa
    endfunc

    "
Function to diff with file in SVN server.
    function! Base_diff()
        let fdir = expand('%:p:h')
        let fn = expand('%:p:t')
        if s:MSWIN
            exe "diffsplit " .fdir."\\.svn\\text-base\\".fn.".svn-base"
        else
            exe "diffsplit " .fdir."/.svn/text-base/".fn.".svn-base"
        endif
    endfunction

    function! SVN_Insert()
        exe "goto 1"
        exe ":r $HOME/.vim/template/svn.template"
        exe "normal mz"
        exe "goto 1"
    endfunction

    function! SRT_Insert()
        exe "goto 1"
        exe "insert"
// DESC_BEGIN
// DESC_END
    endfunction

    function! Maketags()
        if s:MSWIN
            exe ": !mktags.bat"
        else
            exe ": !/home/yyc/tools/bin/mktags"
        endif
        exe "cs r"
    endfunction

    " function to delete duplicate lines
    function! Del_duplicate()
        if getline("
.") == getline(line(".") - 1) || getline(".") == getline(line(".") + 1)
            norm dd
        endif
    endfunction

    "
Function to run my script(for isct project).
    function! Run_STS()
        exe "w"
        let fscript=expand('%:p')
        let fdir=expand('%:p:h')
        if s:MSWIN
            let cmd='! cd '.fdir.'&& cd ..\..\ && F: && isct_run.py '.fscript
        else
            let cmd='! cd /home/yyc/work/sts/iscsi/src/python; ./isct_run.py '.fscript
        endif
        exe cmd
    endfunction

    function! Show_log()
        let fn=expand('%:p:t:r').'.log'
        if s:MSWIN
            let cmd='e F:\work\isct\isct\python\log\'.fn
        else
            let cmd='e /usr/local/inventec/sts/iscsi/log/'.fn
        endif
        exe cmd
        exe "setl nomodifiable"
    endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"
*******************************************
" Part Six: Frequently used Abbrevs
"
*******************************************
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    abbr Author: Author: YangYingchao, itc208024.
    abbr auth Author: YangYingchao, itc208024.
    abbr yang YangYingchao, itc208024.
    abbr Yang YangYingchao,
    abbr yangying yangyingchao@gmail.com

"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"*******************************************
"
Part Seven: Appendix.
"*******************************************
"
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 1. mktags.
    "
#!/bin/bash
    "#ctags -R .
    "
rm -rf cscope*
    "
    "
LIST_ONLY=
    "DIR='.'
    "
LIST_FILE='cscope.files'
    "DATABASE_FILE='cscope.out'
    "
RECURSE=
    "VERBOSE=
    "

    "find $DIR \( -type f -o -type l \) | \
    "
egrep -i '\.([chlyp](xx|pp|y)*|cc|hh)$' | \
    "sed -e '/\/CVS\//d' -e '/\/RCS\//d' -e '/\/\.svn\//d' -e 's/^\.\///' | \
    "
sort > $LIST_FILE
    "
    "
echo "Creating list of files to index ... done"
    "
    "
echo "Indexing files ..."
    "
    "
#cscope -b -i $LIST_FILE -f $DATABASE_FILE
    "cscope -bkq -i $LIST_FILE -f $DATABASE_FILE
    "

    "echo "Indexing files ... done"
    "
exit 0


阅读(812) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~