Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 940
pickle323 Avatar asked Oct 15 '13 05:10

pickle323


People also ask

Where is the vimrc file on Windows?

vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it easy to copy it to another system.

What is the vimrc file?

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix based systems, the file is named .vimrc , while on Windows systems it is named _vimrc . : help vimrc. You can customize Vim by putting suitable commands in your vimrc.

Where does Vim look for vimrc?

According to the help menu (see :help $MYVIMRC ), vim will look for a user vimrc in specific places. It look first for ~/. vimrc and then for ~/. vim/vimrc .

How do I create a .vimrc file?

vimrc using vim. In vim, add the commands that you know you want to put in, then type :wq to save the file. Now open vim again. Once in vim you can just type: :scriptnames to print a list of scripts that have been sourced.


2 Answers

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 <C-v> 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).

like image 142
romainl Avatar answered Sep 18 '22 10:09

romainl


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.

like image 43
sambot Avatar answered Sep 20 '22 10:09

sambot