my .vimrc

: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=31
set columns=102
set mouse=a "enable mouse
syntax on
filetyp on
filetype 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 12G
set expandtab "Converting tabs to spaces
set tabstop=4
set shiftwidth=4
set autoindent
set cindent
set cino=g0
set nu
set diffexpr=MyDiff()
set tags=tags
set autochdir
".C/C++的编译和运行 Build and run
map <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 %<"
endif
endfunction
".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自动更新标签文件tags
au BufWritePost *.cpp,*.h,*.c,*.rl,*.def call system("ctags --tag-relative -a -o ~/.vim/tags/usr/ctags/tags --extra=+q " . expand("%:p"))
set nobackup
let &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 . eq
endfunction

"定义函数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)
    endif
endfunction
autocmd InsertLeave *.{py,c,js,css},*vimrc call AutoUpdateTheLastUpdateInfo()






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值