.vimrc

syntax on
filetype on
filetype indent on
filetype plugin on


"show line number 
set nu!


" expand tab with space
set expandtab


" tab stop at 4th space
set softtabstop=4
set shiftwidth=4


" ignorecase when search, equal to /\c
set ignorecase


set incsearch


" highlight search
set hls


" indent when typing
set autoindent


set guifont=LucidaTypewriter\ 14


" allow backspacing over everything in insert mode
set backspace=indent,eol,start


if (has("gui_running"))
"    set guifont=LucidaTypewriter\ 6


    "enable right click pop up menu
    set mousemodel=popup


    "enable bottom scrollbar
    set guioptions+=b


    "remove toolbar
    set guioptions-=T


    "wrap 
    set nowrap


    "set the color
    colorscheme evening
else
    set nowrap
    
    "colorscheme ron
endif


" let gvim more powerfull
set nocompatible


" show the row and column info 
set ruler




" Protect large files from sourcing and other overhead.
" Files become read only
if 1
    if !exists("my_auto_commands_loaded")
        let my_auto_commands_loaded = 1
        " Large files are > 10M
        " Set options:
        " eventignore+=FileType (no syntax highlighting etc
        " assumes FileType always on)
        " noswapfile (save copy of file)
        " bufhidden=unload (save memory when other file is viewed)
        " buftype=nowritefile (is read-only)
        " undolevels=-1 (no undo possible)
        let g:LargeFile = 1024 * 1024 * 10
        augroup LargeFile
        "autocmd BufReadPre * let f=expand("") | if getfsize(f) > g:LargeFile | set eventignore+=FileType | setlocal noswapfile bufhidden=unload buftype=acwrite undolevels=-1 | else | set eventignore-=FileType | endif
        augroup END
    endif
endif


"restore last cursor 
" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :20 : up to 20 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo


" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
    au!
    autocmd BufReadPost *
                \ if expand(":p:h") !=? $TEMP |
                \ if line("'\"") > 1 && line("'\"") <= line("$") |
                \ let JumpCursorOnEdit_foo = line("'\"") |
                \ let b:doopenfold = 1 |
                \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
                \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
                \ let b:doopenfold = 2 |
                \ endif |
                \ exe JumpCursorOnEdit_foo |
                \ endif |
                \ endif
    " Need to postpone using "zv" until after reading the modelines.
    autocmd BufWinEnter *
                \ if exists("b:doopenfold") |
                \ exe "normal zv" |
                \ if(b:doopenfold > 1) |
                \ exe "+".1 |
                \ endif |
                \ unlet b:doopenfold |
                \ endif
augroup END




" ----- Emulate 'gf' but recognize :|, line format -----
if 1
    function! GotoFile(w,m)
        if a:m == "v"
            let curword = GetVisual()
        else
            let curword = expand("")
        endif
        if (strlen(curword) == 0)
            return
        endif
        let matchstart = match(curword, '[:|,]\d\+$')
        if matchstart > 0
            let pos = '+' . strpart(curword, matchstart+1)
            let fname = strpart(curword, 0, matchstart)
        else
            let pos = ""
            let fname = curword
        endif
        " Open new window if requested
        if a:w == "new"
            new
        endif
        " Use 'find' so path is searched like 'gf' would
        execute 'find ' . pos . ' ' . fname
    endfunction
    function! GetVisual() range
        let reg_save = getreg('"')
        let regtype_save = getregtype('"')
        let cb_save = &clipboard
        set clipboard&
        normal! ""gvy
        let selection = getreg('"')
        call setreg('"', reg_save, regtype_save)
        let &clipboard = cb_save
        return selection
    endfunction




    set isfname+=: " include colon in filenames


    " Override vim commands 'gf', '^Wf', '^W^F'
    nnoremap gf :call GotoFile("","")
    nnoremap f :call GotoFile("new","")
    nnoremap :call GotoFile("new","")
    vnoremap gf :call GotoFile("", "v")
endif




"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" below is not necessary                                                    "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
":fixdel


"No attention message 
set shortmess+=A


" double click to search
 noremap <2-LeftMouse> :let @/="\\<".expand("")."\\>":set hlsearch


" p4 open current file by type PfOpen command in vim
" it is the same as !p4 open %
:command! -nargs=0 PfOpen :exe "!p4 open "expand("%")


" from module to instance
noremap : s/\(\w\w*\)\(,*.*\)\s*$/\.\1(\1)\2/g : nohl


" Ctrl+C to comment or uncomment
"noremap :call Comment() j
"function! Comment()
"    let l = getline(".")
"    if l =~ '^\s*\/\/'
"        :s/^\(\s*\)\/\//\1/
"    else
"        ":s/^\(\s*\)\(\w*\)/\1\/\/\2/
"        :s/.*/\/\/&/g
"    endif
"endfunction




"colorscheme murphy
"map to g] for ctags default tlist behavior
"noremap g]
"
"set statusline=[%02n]\ %f 
"set nolist
"set of auto line break
"set linebreak
" set which key can move line at begin or end of a line
" set whichwrap=b,s,<,>,[,]


" verilog indent, need a local indent file to work properly
au BufReadPost * if exists("b:current_syntax")
au BufReadPost *   if b:current_syntax == "verilog"
au BufReadPost *     let b:verilog_indent_modules = 1
au BufReadPost *   endif
au BufReadPost * endif


"auto insert template
function SetTitle()
    "jump to head of the file
    autocmd BufNewFile * normal gg
    
    if &filetype == 'perl'
        "remove the original head
        autocmd BufNewFile * normal 36dd
        call setline(1,"#! /usr/bin/perl")
        call setline(2,"# ---------------------------------------------------------------------")
        call setline(3,"# FILE NAME    : ")
        call setline(4,"# TYPE         : ")
        call setline(5,"# AUTHOR       :  ")
        call setline(6,"# EMAIL        :.com")
        call setline(7,"# ---------------------------------------------------------------------")
        call setline(8,"#")
        call setline(9,"# Release history")
        call setline(10,"# VERSION DATE AUTHOR DESCRIPTION")
        call setline(11,"# KEYWORD      : ")
        call setline(12,"# PURPOSE      : ")
        call setline(13,"# Created Time : ".strftime("%c"))
        call setline(14,"#")
        call setline(15,"# ---------------------------------------------------------------------")
    else
        if &filetype == 'verilog'
            "remove the original head
            autocmd BufNewFile * normal 29dd
            call setline(1,"// ---------------------------------------------------------------------")
            call setline(2,"// FILE NAME    : ")
            call setline(3,"// TYPE         : ")
            call setline(4,"// AUTHOR       :  ")
            call setline(5,"// EMAIL        : com")
            call setline(6,"// ---------------------------------------------------------------------")
            call setline(7,"//")
            call setline(8,"// Release history")
            call setline(9,"// VERSION DATE AUTHOR DESCRIPTION")
            call setline(10,"// KEYWORD      : ")
            call setline(11,"// PURPOSE      : ")
            call setline(12,"// Created Time : ".strftime("%c"))
            call setline(13,"//")
            call setline(14,"// ---------------------------------------------------------------------")
        else
            call setline(1,"// ---------------------------------------------------------------------")
            call setline(2,"// FILE NAME    : ")
            call setline(3,"// TYPE         : ")
            call setline(4,"// AUTHOR       :  ")
            call setline(5,"// EMAIL        : .com")
            call setline(6,"// ---------------------------------------------------------------------")
            call setline(7,"//")
            call setline(8,"// Release history")
            call setline(9,"// VERSION DATE AUTHOR DESCRIPTION")
            call setline(10,"// KEYWORD      : ")
            call setline(11,"// PURPOSE      : ")
            call setline(12,"// Created Time : ".strftime("%c"))
            call setline(13,"//")
            call setline(14,"// ---------------------------------------------------------------------")
        endif
        if &filetype == 'c' || &filetype == 'cpp' || &filetype == 'cc'
            call setline(1,"#include ")
            call setline(2,"using namespace std;")
            call setline(3,"                    ")
            call setline(4,"// AUTHOR       : ")
            call setline(5,"// EMAIL        : .com")
            call setline(6,"// ---------------------------------------------------------------------")
            call setline(7,"//")
            call setline(8,"// Release history")
            call setline(9,"// VERSION DATE AUTHOR DESCRIPTION")
            call setline(10,"// KEYWORD      : ")
            call setline(11,"// PURPOSE      : ")
            call setline(12,"// Created Time : ".strftime("%c"))
            call setline(13,"//")
            call setline(14,"// ---------------------------------------------------------------------")
        endif
    endif
endfunction
autocmd BufNewFile *.pl,*.sv,*.v,*.c,*.cpp,*.c: call SetTitle() 


"@m insert FF_DLY
let @m = "i#`FF_DLY "


"@c insert #!/bin/csh -f
let @c = "i#!/bin/csh -f"

你可能感兴趣的:(vi,使用,gvim)