简体   繁体   中英

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. 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. It's not really a problem for quick edits but it seriously sucks if you intend to use it for more than 10 minutes. set nocompatible makes Vim more Vim-like than Vi-like.

See :help nocompatible .

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

Source those two files. vimrc_example.vim contains example settings. 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. 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. 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.

If you intend to use/learn Vim seriously, none of the above should go into your $HOME\\_vimrc . Not even the first line since nocompatible is set automatically for you if Vim finds a $HOME\\_vimrc .

I'm not really familiar with Windows so the diff part may be useful but you can safely drop the rest.

When you see a set something , do :help 'something (with the single quote).

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 . Without this, text will be colorless in gvim regardless of colorscheme .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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