Vim (Vi improved) is a text editor based on the vi text editor. It can be used from the command-line or as a standalone application with a graphical user interface.
USE flags for app-editors/vim Vim, an improved vi-style text editor
||Link console vim against X11 libraries to enable title and clipboard features in xterm||local|
||Add support for Access Control Lists||global|
||Enable cscope interface -- in vim for example||global|
||Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces||global|
||Add support for sys-libs/gpm (Console-based mouse driver)||global|
||Enable Lua scripting support||global|
||Use dev-lang/luajit instead of dev-lang/lua||local|
||Install a very minimal build (disables, for example, plugins, fonts, most drivers, non-critical features)||global|
||Add Native Language Support (using gettext - GNU locale utilities)||global|
||Add optional support/bindings for the Perl language||global|
||Add optional support/bindings for the Python language||global|
||Enable support for Scheme using dev-scheme/racket||local|
||Add support/bindings for the Ruby language||global|
||!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur||global|
||Add support the Tcl language||global|
||Enable terminal emulation support||local|
||Install vimpager and vimmanpager links||local|
If X Window System support is not needed, install app-editors/vim:
emerge --ask app-editors/vim
To install Vim with both the ncurses-based interface (/usr/bin/vim) as well as the graphical interface (for the X Window System - /usr/bin/gvim), install the app-editors/gvim package:
emerge --ask app-editors/gvim
The category app-vim provides a lot of additional syntax definitions, plugins and other Vim related stuff.
Use emerge or eix to get an overview of available packages in the app-vim category:
emerge --search "%@^app-vim"
eix -cC app-vim
Vim can be configured on a per-user basis or through a system-wide configuration file:
- /etc/vim/vimrc - The system wide (global) settings file.
- ~/.vimrc - The user-specific (local) configuration file. The tilde (~) means it is in the user's home directory.
Vim has a built-in tutorial which should require around 30 min to go through. Start it using the vimtutor command:
Tips and tricks
Using Vim like ex or ed from the command line
It is possible to use Vim for one-liners — commands that can be used in scripts or on the command line to make changes in an unattended manner.
For instance, the following command adds
# to the beginning of each line in the file.txt file:
vim -c ":%s/^/#/g" -c ":x" file.txt
What happens is that Vim interprets the passed on commands (through the
-c option). The first command is Vim's substitution command (which is very similar to sed's), the second one is Vim's instruction to save and exit the editor.
Change file encoding
To change the file encoding of a file to UTF-8, use the following command (in Vim command mode):
As shown in the previous trick, it is possible to do this from the command line as well:
vim -c ":wq! ++enc=utf8" file.txt
- Vim Guide - Explains how to use Vim in greater detail.
- Vim Documentation Includes Manuals (aka ":help" and Free VIM OPL Book), FAQS, HOWTO's, Tutorials, in HTML PDF, and PS formats.
- A vim Tutorial and Primer - An excellent vim tutorial/primer. Read this first.
- VIM Scripts/Plugins
- Vim for Humans (free ebook) - Clone and cd into the sources directory, mkdir dist, change
sphinx-buildfor SPHINXBUILD in rst/en/Makefile. Run ./makedist.sh. Read PDF in ./dist/vimpourleshumains/.
- Learning the vi and Vim Editors, 7th Edition O'Reilly Print ISBN: 978-0-596-52983-3, Ebook ISBN: 978-0-596-15935-1
- Vim anti-patterns - A blog entry on maintaining flow with Vim.