:h %<
%< current file name without extension
我這裡的配置是針對vim所設定如果是最原始的vi,那麼是不支援下面一些配置的,如:
set mouse=a "enable mouse
set autochdir
出錯提示:
E538: No mouse support: mouse=a
E518: Unknown option: autochdir
執行yum install vim後,給vim設定別名vi
[workhard@zl 畢業設計]$ which vi
/bin/vi
[workhard@zl 畢業設計]$ alias vi='vim'
[workhard@zl 畢業設計]$ which vi
alias vi='vim'
/usr/bin/vim
set nocompatible"source $VIMRUNTIME/vimrc_example.vim"source $VIMRUNTIME/mswin.vim"behave mswin"設定vim預設視窗大小set lines=31set columns=102set mouse=a "enable mousesyntax onfiletyp onfiletype plugin indent on"autocmd FileType c set tabstop=8 "When edit c source code"au BufNewFile,BufRead *.txt set tabstop=8 ""When edit TXT file"建立.c,.h,.sh,.java檔案,自動插入檔案頭 autocmd BufNewFile *.[ch],*.sh,*.cpp,*.java exec ":call SetTitle()" "建立檔案後,:h normal...Execute Normal mode commands {commands}. 跳到第12行 autocmd BufNewFile * normal 12Gset expandtab "Converting tabs to spacesset tabstop=4set shiftwidth=4set autoindentset cindentset cino=g0set nuset diffexpr=MyDiff()set tags=tagsset autochdir".C/C++的編譯和運行 Build and runmap <F9> :call CompileRunGcc()func! CompileRunGcc() call CompileGcc()exec "!./%<"endfunc".C/C++的編譯運行_end".C/C++的編譯map <C-F9> :call CompileGcc()function CompileGcc()exec "w"if &filetype=="c"" %當前檔案名稱 current file name" %< 當前檔案名稱(去掉尾碼) current file name without extension exec "!gcc -g % -o %<" elseif &filetype=="cpp" exec "!g++ -g % -o %<"endifendfunction".C/C++的編譯_end".C/C++的運行map <C-F10> :exec "!./%<"".C/C++的運行_end"Ctrl-F12快速鍵自動產生tags檔案map <C-F12> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .<CR> "Ctrl-F12快速鍵自動產生tags檔案_end"Ctrl-F11快速鍵自動產生單前檔案的tags檔案map <C-F11> :!ctags %"Ctrl-F11快速鍵自動產生單前檔案的tags檔案_end"vim自動更新標籤檔案tagsau BufWritePost *.cpp,*.h,*.c,*.rl,*.def call system("ctags --tag-relative -a -o ~/.vim/tags/usr/ctags/tags --extra=+q " . expand("%:p"))set nobackuplet &termencoding=&encoding set fileencodings=utf-8,gbk,cp936###function MyDiff() let opt = '-a --binary ' if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif let arg1 = v:fname_in if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif let arg2 = v:fname_new if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif let arg3 = v:fname_out if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif let eq = '' if $VIMRUNTIME =~ ' ' if &sh =~ '\<cmd' let cmd = '""' . $VIMRUNTIME . '\diff"' let eq = '"' else let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"' endif else let cmd = $VIMRUNTIME . '\diff' endif silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eqendfunction"定義函數SetTitle,自動插入檔案頭 func SetTitle()call setline(1, "/**********************************************************************") call append(line("."), "* Compiler: gcc 4.5.1 20100924 (Red Hat 4.5.1-4)") call append(line(".")+1, "* Last Update: ".strftime("%c")) call append(line(".")+2, "* File Name: ".expand("%")) call append(line(".")+3, "* Arguments: ") call append(line(".")+4, "* Description: ") call append(line(".")+5, "************************************************************************/") if &filetype == 'c' call append(line(".")+6, "#include <stdio.h>") call append(line(".")+7, "#include <stdlib.h>") call append(line(".")+8, " ") call append(line(".")+9, "int main(int argc, char **argv)") call append(line(".")+10, "{") call append(line(".")+11, " ") call append(line(".")+12, "") call append(line(".")+13, " return 0;")call append(line(".")+14, "}") elseif &filetype == 'cpp' call append(line(".")+5, "#include <iostream>") call append(line(".")+6, " ") call append(line(".")+7, "int main()") call append(line(".")+8, "{") call append(line(".")+9, "") call append(line(".")+10, " return 0;")call append(line(".")+11, "}") elseif &filetype == 'java' call append(line(".")+5, "public class ".expand("%<").expand("{")) call append(line(".")+6, " public static void main(String[] args){") call append(line(".")+7, " ") call append(line(".")+8, " System.out.println();")call append(line(".")+9, " }") call append(line(".")+10, "}") call append(line(".")+11, " ") endif endfunc" 自動更新檔案的最後更新時間function! AutoUpdateTheLastUpdateInfo() let s:original_pos = getpos(".") let s:regexp = "^\* Last Update: " let s:lu = search(s:regexp) if s:lu != 0 let s:update_str = matchstr(getline(s:lu), s:regexp) call setline(s:lu, s:update_str . strftime(" %c")) call setpos(".", s:original_pos) endifendfunctionautocmd InsertLeave *.{py,c,js,css},*vimrc call AutoUpdateTheLastUpdateInfo()