VIM:我的GVIM设置(通用设置和编程语言设置)

   

主要内容:

1,设置按F5编译java,c语言,c++等语言源代码

2,设置用4个空格代替tab进行缩进

3,取消备份文件

 前言:   

     为了在linux环境下熟悉VIM,我在windows环境下安装了GVIM8

     修改vimrc文件可以更改VIM默认的设置,不需要每一次打开VIM就需要重新调整设置。 

     以下时vimrc的全部内容:

source $VIMRUNTIME/vimrc_example.vim

so $VIMRUNTIME/delmenu.vim    "以下三句将语言更改为英语"
set langmenu=none
so $VIMRUNTIME/menu.vim

set guifont=Courier_new:h20:b:cDEFAULT   "更改字体,hxx是大小"

set noundofile  "取消undo文件" 
set nobackup    "取消备份文件"

set encoding=utf-8 "设置字符编码格式为utf-8"
colorscheme zellner "设置主题颜色"
set diffexpr=MyDiff()

:set fileencodings=ucs-bom,utf-8,cp936
:set fileencoding=gb2312
:set termencoding=utf-8
:set nu  "显示行号"
" 修改tab = 4个空格"
set expandtab  "tab缩进用空格表示"
set ts=4   "tabstop tab的宽度" 
set autoindent "换行自动缩进"
set shiftwidth=4 "每级缩进设置为4个空格"

"---------------------------------编译器设置-------------------------------"
"设置编译器:Linux和windows"
"功能:当文件类型为c的时候,用gcc编译当前文件"
"当文件类型为cpp的时候,用g++编译当前文件"
"当文件类型为java的时候,用javac命令编译当前文件,并用java命令执行class文件"
map <F5> :call CompileRunGcc()<CR>
imap <F5> <ESC>:call CompileRunGcc()<CR>
function! CompileRunGcc()
    exec "w"
    exec "cd %:p:h"
    if &filetype == 'c'
        exec "!gcc % -o %<"
        exec "! ./%<"
"注意Linux和windows执行程序的方式不一样"
"windows下需要将 exec "!./%<"换成exec "! %<"
    elseif &filetype == 'cpp'
        exec "!g++ % -o %<"
        exec "! ./%<"
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!java %<"
    elseif &filetype == 'sh'
        :!./%
    endif
endfunction

"---------------------------------分隔符-------------------------------"
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 arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif

endfunction

需要注意的是:"设置编辑器部分"

    windows下执行程序输入命令:  文件名

    而linux下执行程序输入命令: ./文件名

猜你喜欢

转载自blog.csdn.net/IMBA_09/article/details/82902597