Vim

From Gentoo Wiki
Jump to: navigation, search
Other languages:
English • ‎español • ‎日本語 • ‎한국어 • ‎русский


Resources

Vim (Vi improved) is a text editor based on vi. It can be used from the command-line or as a standalone application with a graphical user interface.

Installation

USE flags

Optional USE flags for app-editors/vim:
USE flag (what is that?) Default Recommended Description
X No Link console vim against X11 libraries to enable title and clipboard features in xterm
acl Yes Add support for Access Control Lists
cscope No Enable cscope interface -- in vim for example
debug No Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see http://www.gentoo.org/proj/en/qa/backtraces.xml
gpm No Add support for sys-libs/gpm (Console-based mouse driver)
lua No Enable Lua scripting support
luajit No Use dev-lang/luajit instead of dev-lang/lua
minimal No Install a very minimal build (disables, for example, plugins, fonts, most drivers, non-critical features)
nls Yes Add Native Language Support (using gettext - GNU locale utilities)
perl No Add optional support/bindings for the Perl language
python No Add optional support/bindings for the Python language
python_targets_python2_7 No Build with Python 2.7
python_targets_python3_3 No Build with Python 3.3
python_targets_python3_4 No Build with Python 3.4
racket No Enable support for Scheme using dev-lang/racket
ruby No Add support/bindings for the Ruby language
tcl No Add support the Tcl language
vim-pager No Install vimpager and vimmanpager links

Vim command-line

If X Window System support is not needed, install app-editors/vim:

root #emerge --ask app-editors/vim

Vim GUI

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 app-editors/gvim:

root #emerge --ask app-editors/gvim

There is also an experimental Qt interface called app-editors/vim-qt which can also be installed.

Extensions

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:

user $emerge --search "%@^app-vim"
user $eix -cC app-vim

Configuration

Vim can be configured on a per-user basis or through a system-wide configuration file.

The system wide settings are set in /etc/vim/vimrc whereas the user-specific configuration is located inside the user's home directory at ~/.vimrc.

Usage

Getting started

Vim has a built-in tutorial which should require around 30 min to go through. Start it using the vimtutor command:

user $vimtutor

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:

user $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):

:e ++enc=utf8

As shown in the previous trick, it is possible to do this from the command line as well:

user $vim -c ":wq! ++enc=utf8" file.txt

See also

  • Vim Guide - Explains how to use Vim in greater detail.

External resources