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
vim/ directory ($HOME/vimfiles/ for MS-Windows). That makes it easy to copy it to another system.
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.
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 .
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.
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).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With