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

本文介绍了如何在GVIM中配置编译快捷键F5以支持Java, C, C++等语言源代码的编译,设置使用4个空格代替Tab进行缩进,以及取消备份文件的生成。通过修改vimrc文件,可以优化VIM的默认设置,提高编程效率。" 135000936,12831281,华为OD机试Python实现:打印任务优先级排序,"['华为OD机试', 'Python实现', '排序问题', '编程挑战']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

   

主要内容:

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个空格"
set hlsearch "设置查找字符高亮显示"

"---------------------------------编译器设置-------------------------------"
"设置编译器: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下执行程序输入命令: ./文件名

设置生效:

打开用户根目录, vim ~/.vimrc(如果没有会自动创建这一目录),这一目录是当前登录用户的vim设定,将上述设置写入.vimrc 文件,重新打开vim即可生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值