简体   繁体   English

Windows版vim的默认vimrc文件的说明

[英]Explanation of default vimrc file for windows version of vim

I've just downloaded vim7.4 for windows and I'll like to know what the default vimrc file that comes with it is doing. 我刚刚下载了vim7.4 for windows,我想知道它附带的默认vimrc文件是做什么的。 Just a brief explanation of each item would be nice to know. 只需对每个项目进行简要说明即可。 Here it is. 这里是。

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set diffexpr=MyDiff()
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
set nocompatible

By default, Vim behaves like its ancestor vi. 默认情况下,Vim的行为与其祖先vi相似。 It's not really a problem for quick edits but it seriously sucks if you intend to use it for more than 10 minutes. 这对于快速编辑来说并不是一个真正的问题,但如果您打算使用它超过10分钟,它会非常糟糕。 set nocompatible makes Vim more Vim-like than Vi-like. set nocompatible使得Vim比Vi更像Vim。

See :help nocompatible . 请参阅:help nocompatible

source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim

Source those two files. 来源这两个文件。 vimrc_example.vim contains example settings. vimrc_example.vim包含示例设置。 It may be a good idea to take a look at it: it may contain useful things for you. 看看它可能是一个好主意:它可能包含有用的东西。

behave mswin

mswin.vim contains a bunch of settings and mappings designed to make Vim work more or less like a typical Windows editor, like <Cv> to paste. mswin.vim包含一系列设置和映射,旨在使Vim或多或少像典型的Windows编辑器一样工作,如<Cv>粘贴。 This command "activates" that stupid behavior. 这个命令“激活”了这种愚蠢的行为。

set diffexpr=MyDiff()
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

This is a function that defines Vim's behavior when used for diffing two or more buffers. 这是一个定义Vim在用于区分两个或多个缓冲区时的行为的函数。 It looks more like a hack than anything else, to me. 对我来说,它看起来更像是一个黑客而不是其他任何东西。 It seems to be checking if your Windows environment is able to do the diff itself and, if not, use the builtin diff. 它似乎是检查你的Windows环境是否能够自己做差异,如果没有,使用内置差异。

If you intend to use/learn Vim seriously, none of the above should go into your $HOME\\_vimrc . 如果你打算认真使用/学习Vim,上面的任何一个都不应该进入你的$HOME\\_vimrc Not even the first line since nocompatible is set automatically for you if Vim finds a $HOME\\_vimrc . 如果Vim找到$HOME\\_vimrc则自动为您设置nocompatible即使是第一行也不行。

I'm not really familiar with Windows so the diff part may be useful but you can safely drop the rest. 我并不熟悉Windows,因此差异部分可能很有用,但您可以安全地放弃其余部分。

When you see a set something , do :help 'something (with the single quote). 当你看到set something ,做:help 'something (用单引号)。

You may have figured this out, but one thing you may want to add if you remove the vimrc_example.vim source is syntax on . 您可能已经想到了这一点,但是如果删除vimrc_example.vim源,您可能想要添加的一件事就是syntax on Without this, text will be colorless in gvim regardless of colorscheme . 没有这一点,文本将在gvim的无色无论colorscheme

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM