Vim Tips Wiki
Register
m (Reverted edits by 115.114.125.146 (talk | block) to last version by Fritzophrenic)
(15 intermediate revisions by 11 users not shown)
Line 1: Line 1:
  +
{{TipNew
==Introduction==
 
  +
|id=1628
This is a sample <tt>.vimrc</tt> that attempts to offer an alternative to the <tt>vimrc_example.vim</tt> delivered with Vim. It has been created in discussion with the ops and regulars of the [[Vim_on_Freenode|#vim community]].
 
  +
|previous=1627
  +
|next=1629
  +
|created=2009
  +
|complexity=basic
  +
|author=Spiiph
  +
|version=7.0
  +
|subpage=/200907
  +
|category1=
  +
|category2=
  +
}}
 
This is a sample [[vimrc]] file that offers an alternative to the <code>vimrc_example.vim</code> delivered with Vim. It was created in discussion with the ops and regulars of the [[Vim_on_Freenode|#vim community]].
   
==Reqiuirements and Caveats==
+
==Requirements and caveats==
The code in this example <tt>.vimrc</tt> requires a full featured Vim. While it is possible to safeguard many of the options and settings for Vim binaries with less features, this would necessarily lower its readability and ease of understanding.
+
The code in this example <code>.vimrc</code> requires a full featured Vim. While it is possible to insert checks to omit some settings for Vim binaries with less features, that would make the file more complex and hard to understand.
   
If your Vim does not support some of the options and features suggested here, you will have to install a Vim package with a larger feature set, or upgrade to a newer version of Vim. For Windows, the default Vim package already contains all necessary features, as does the "Vim ''without Cream''" packages at [http://cream.sf.net cream.sf.net]. For Linux distributions, refer to the documentation for the Vim package and the package manager. For other operating systems, refer to the documentation on how to build Vim from source code.
+
If your Vim does not support some of the options and features suggested here, you will have to install a Vim package with a larger feature set, or [[Download|upgrade to a newer version]] of Vim.
   
  +
==Usage recommendations==
==Recommendations on Usage==
 
This is a minimal, but feature rich, <tt>.vimrc</tt> that aims to satisfy the majority of new and intermediate Vim users. While you may use this example as your <tt>.vimrc</tt> out-of-the-box, it is important to understand what the options and features do. It contains features and options that almost all Vim users should have at least basic knowledge about.
+
This is a minimal, but feature rich, <code>.vimrc</code> that aims to satisfy the majority of new and intermediate Vim users. While you may use this example as your <code>.vimrc</code> out-of-the-box, it is important to understand what the options and features do. It contains features and options that almost all Vim users should have at least basic knowledge about.
   
==The File==
+
==Example vimrc==
 
<pre>
 
<pre>
 
" URL: http://vim.wikia.com/wiki/Example_vimrc
 
" URL: http://vim.wikia.com/wiki/Example_vimrc
Line 16: Line 27:
 
" Description: A minimal, but feature rich, example .vimrc. If you are a
 
" Description: A minimal, but feature rich, example .vimrc. If you are a
 
" newbie, basing your first .vimrc on this file is a good choice.
 
" newbie, basing your first .vimrc on this file is a good choice.
" If you're a more advanced user, building your own .vimrc based
+
" If you're a more advanced user, building your own .vimrc based
" on this file is still a good idea.
+
" on this file is still a good idea.
   
 
"------------------------------------------------------------
 
"------------------------------------------------------------
 
" Features {{{1
 
" Features {{{1
 
"
 
"
" These options and commands enables some very useful features in Vim, that
+
" These options and commands enable some very useful features in Vim, that
 
" no user should have to live without.
 
" no user should have to live without.
   
 
" Set 'nocompatible' to ward off unexpected things that your distro might
 
" Set 'nocompatible' to ward off unexpected things that your distro might
 
" have made, as well as sanely reset options when re-sourcing .vimrc
 
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible
+
set nocompatible
   
 
" Attempt to determine the type of a file based on its name and possibly its
 
" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
+
" contents. Use this to allow intelligent auto-indenting for each filetype,
 
" and for plugins that are filetype specific.
 
" and for plugins that are filetype specific.
 
filetype indent plugin on
 
filetype indent plugin on
Line 41: Line 52:
 
" Must have options {{{1
 
" Must have options {{{1
 
"
 
"
" These are options that any sane Vim setup should have
+
" These are highly recommended options.
   
  +
" Vim with default settings does not allow easy switching between multiple files
" One of the most important options to activate. Allows you to switch from an
 
  +
" in the same editor window. Users can use multiple split windows or multiple
" unsaved buffer without saving it first. Also allows you to keep an undo
 
" history for multiple files. Vim will complain if you try to quit without
+
" tab pages to edit multiple files, but it is still best to enable an option to
  +
" allow easier switching between files.
" saving, and swap files will keep you safe if your computer crashes.
 
  +
"
  +
" One such option is the 'hidden' option, which allows you to re-use the same
 
" window and switch from an unsaved buffer without saving it first. Also allows
  +
" you to keep an undo history for multiple files when re-using the same window
  +
" in this way. Note that using persistent undo also lets you undo in multiple
  +
" files even in the same window, but is less efficient and is actually designed
  +
" for keeping undo history after closing Vim entirely. Vim will complain if you
 
" try to quit without saving, and swap files will keep you safe if your computer
  +
" crashes.
 
set hidden
 
set hidden
  +
  +
" Note that not everyone likes working this way (with the hidden option).
  +
" Alternatives include using tabs or split windows instead of re-using the same
  +
" window as mentioned above, and/or either of the following options:
  +
" set confirm
  +
" set autowriteall
   
 
" Better command-line completion
 
" Better command-line completion
Line 59: Line 85:
 
set hlsearch
 
set hlsearch
   
" Modelines have historically been a source of security vulnerabilities. As
+
" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
+
" such, it may be a good idea to disable them and use the securemodelines
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
+
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
" set nomodeline
+
" set nomodeline
   
   
Line 69: Line 95:
 
"
 
"
 
" These are options that users frequently set in their .vimrc. Some of them
 
" These are options that users frequently set in their .vimrc. Some of them
" changes Vim's behaviour in ways which deviate from the true Vi way, but
+
" change Vim's behaviour in ways which deviate from the true Vi way, but
 
" which are considered to add usability. Which, if any, of these options to
 
" which are considered to add usability. Which, if any, of these options to
 
" use is very much a personal preference, but they are harmless.
 
" use is very much a personal preference, but they are harmless.
Line 84: Line 110:
 
set autoindent
 
set autoindent
   
" Stop certain movements from always going to the first character of a line.
+
" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
+
" While this behaviour deviates from that of Vi, it does what most users
 
" coming from other editors would expect.
 
" coming from other editors would expect.
 
set nostartofline
 
set nostartofline
Line 103: Line 129:
 
set visualbell
 
set visualbell
   
" And reset the terminal code for the visual bell. If visualbell is set, and
+
" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
+
" this line is also included, vim will neither flash nor beep. If visualbell
 
" is unset, this does nothing.
 
" is unset, this does nothing.
 
set t_vb=
 
set t_vb=
Line 136: Line 162:
 
set expandtab
 
set expandtab
   
" Indentation settings for using hard tabs for indent. Display tabs as
+
" Indentation settings for using hard tabs for indent. Display tabs as
 
" two characters wide.
 
" two characters wide.
 
"set shiftwidth=2
 
"set shiftwidth=2
Line 145: Line 171:
 
" Mappings {{{1
 
" Mappings {{{1
 
"
 
"
" Useful mappings
+
" Useful mappings
   
 
" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
 
" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
Line 160: Line 186:
   
 
==Comments==
 
==Comments==
  +
Great stuff! Thanks for making my vim-setup usable! :)
  +
  +
/J

Revision as of 08:41, 1 July 2013

Tip 1628 Printable Monobook Previous Next

created 2009 · complexity basic · author Spiiph · version 7.0


This is a sample vimrc file that offers an alternative to the vimrc_example.vim delivered with Vim. It was created in discussion with the ops and regulars of the #vim community.

Requirements and caveats

The code in this example .vimrc requires a full featured Vim. While it is possible to insert checks to omit some settings for Vim binaries with less features, that would make the file more complex and hard to understand.

If your Vim does not support some of the options and features suggested here, you will have to install a Vim package with a larger feature set, or upgrade to a newer version of Vim.

Usage recommendations

This is a minimal, but feature rich, .vimrc that aims to satisfy the majority of new and intermediate Vim users. While you may use this example as your .vimrc out-of-the-box, it is important to understand what the options and features do. It contains features and options that almost all Vim users should have at least basic knowledge about.

Example vimrc

" URL: http://vim.wikia.com/wiki/Example_vimrc
" Authors: http://vim.wikia.com/wiki/Vim_on_Freenode
" Description: A minimal, but feature rich, example .vimrc. If you are a
"              newbie, basing your first .vimrc on this file is a good choice.
"              If you're a more advanced user, building your own .vimrc based
"              on this file is still a good idea.

"------------------------------------------------------------
" Features {{{1
"
" These options and commands enable some very useful features in Vim, that
" no user should have to live without.

" Set 'nocompatible' to ward off unexpected things that your distro might
" have made, as well as sanely reset options when re-sourcing .vimrc
set nocompatible

" Attempt to determine the type of a file based on its name and possibly its
" contents. Use this to allow intelligent auto-indenting for each filetype,
" and for plugins that are filetype specific.
filetype indent plugin on

" Enable syntax highlighting
syntax on


"------------------------------------------------------------
" Must have options {{{1
"
" These are highly recommended options.

" Vim with default settings does not allow easy switching between multiple files
" in the same editor window. Users can use multiple split windows or multiple
" tab pages to edit multiple files, but it is still best to enable an option to
" allow easier switching between files.
"
" One such option is the 'hidden' option, which allows you to re-use the same
" window and switch from an unsaved buffer without saving it first. Also allows
" you to keep an undo history for multiple files when re-using the same window
" in this way. Note that using persistent undo also lets you undo in multiple
" files even in the same window, but is less efficient and is actually designed
" for keeping undo history after closing Vim entirely. Vim will complain if you
" try to quit without saving, and swap files will keep you safe if your computer
" crashes.
set hidden

" Note that not everyone likes working this way (with the hidden option).
" Alternatives include using tabs or split windows instead of re-using the same
" window as mentioned above, and/or either of the following options:
" set confirm
" set autowriteall

" Better command-line completion
set wildmenu

" Show partial commands in the last line of the screen
set showcmd

" Highlight searches (use <C-L> to temporarily turn off highlighting; see the
" mapping of <C-L> below)
set hlsearch

" Modelines have historically been a source of security vulnerabilities. As
" such, it may be a good idea to disable them and use the securemodelines
" script, <http://www.vim.org/scripts/script.php?script_id=1876>.
" set nomodeline


"------------------------------------------------------------
" Usability options {{{1
"
" These are options that users frequently set in their .vimrc. Some of them
" change Vim's behaviour in ways which deviate from the true Vi way, but
" which are considered to add usability. Which, if any, of these options to
" use is very much a personal preference, but they are harmless.

" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase

" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start

" When opening a new line and no filetype-specific indenting is enabled, keep
" the same indent as the line you're currently on. Useful for READMEs, etc.
set autoindent

" Stop certain movements from always going to the first character of a line.
" While this behaviour deviates from that of Vi, it does what most users
" coming from other editors would expect.
set nostartofline

" Display the cursor position on the last line of the screen or in the status
" line of a window
set ruler

" Always display the status line, even if only one window is displayed
set laststatus=2

" Instead of failing a command because of unsaved changes, instead raise a
" dialogue asking if you wish to save changed files.
set confirm

" Use visual bell instead of beeping when doing something wrong
set visualbell

" And reset the terminal code for the visual bell. If visualbell is set, and
" this line is also included, vim will neither flash nor beep. If visualbell
" is unset, this does nothing.
set t_vb=

" Enable use of the mouse for all modes
set mouse=a

" Set the command window height to 2 lines, to avoid many cases of having to
" "press <Enter> to continue"
set cmdheight=2

" Display line numbers on the left
set number

" Quickly time out on keycodes, but never time out on mappings
set notimeout ttimeout ttimeoutlen=200

" Use <F11> to toggle between 'paste' and 'nopaste'
set pastetoggle=<F11>


"------------------------------------------------------------
" Indentation options {{{1
"
" Indentation settings according to personal preference.

" Indentation settings for using 2 spaces instead of tabs.
" Do not change 'tabstop' from its default value of 8 with this setup.
set shiftwidth=2
set softtabstop=2
set expandtab

" Indentation settings for using hard tabs for indent. Display tabs as
" two characters wide.
"set shiftwidth=2
"set tabstop=2


"------------------------------------------------------------
" Mappings {{{1
"
" Useful mappings

" Map Y to act like D and C, i.e. to yank until EOL, rather than act as yy,
" which is the default
map Y y$

" Map <C-L> (redraw screen) to also turn off search highlighting until the
" next search
nnoremap <C-L> :nohl<CR><C-L>


"------------------------------------------------------------

Comments

Great stuff! Thanks for making my vim-setup usable! :)

/J