This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Vim

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Vim and the translation is 65% complete.
Outdated translations are marked like this.
Resources

Vim (Vi improved) は vi テキストエディタを基にしたテキストエディタです。コマンドラインから使うことも、単独で動作する GUI アプリケーションとして使うこともできます。

インストール

USE フラグ

USE flags for app-editors/vim Vim, an improved vi-style text editor

X Link console vim against X11 libraries to enable title and clipboard features in xterm
acl Add support for Access Control Lists
crypt Use dev-libs/libsodium for crypto support
cscope Enable cscope interface
debug 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
gpm Add support for sys-libs/gpm (Console-based mouse driver)
lua Enable Lua scripting support
minimal Install a very minimal build (disables, for example, plugins, fonts, most drivers, non-critical features)
nls Add Native Language Support (using gettext - GNU locale utilities)
perl Add optional support/bindings for the Perl language
python Add optional support/bindings for the Python language
racket Enable support for Scheme using dev-scheme/racket
ruby Add support/bindings for the Ruby language
selinux  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
sound Enable sound support
tcl Add support the Tcl language
terminal Enable terminal emulation support
vim-pager Install vimpager and vimmanpager links

Emerge

X Window System のサポートが不要なら、 app-editors/vim をインストールしてください。

root #emerge --ask app-editors/vim

追加のソフトウェア

Gvim

ncurses ベースのインターフェースを備えた vim (/usr/bin/vim) とX Window System 用のグラフィカルインターフェースを備えた vim (/usr/bin/gvim) の両方をインストールするには、app-editors/gvim をインストールしてください。

root #emerge --ask app-editors/gvim

Vim-qt

app-editors/vim-qt という、Qt インタフェースを使った実験的なものもあり、これをインストールすることもできます。

Plugins

app-vim カテゴリには、追加のシンタックス定義や、プラグイン、その他 vim に関連するものがたくさん用意してあります。

app-vim カテゴリ内の利用可能なパッケージの概要を見るには、emerge または eix が使えます。

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

設定

ファイル

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

  • /etc/vim/vimrc - システム全体の(グローバルな)設定ファイルです。
  • ~/.vimrc - ユーザ固有の(ローカルな)設定ファイルです。チルダ (~) は、設定ファイルはユーザのホームディレクトリの中にあるという意味です。

使い方

はじめに

Vim には 30 分程度で読み終わるチュートリアルが組み込まれています。vimtutor コマンドを使ってチュートリアルを開始できます。

user $vimtutor

Color schemes

About a dozen color schemes are shipped with the base Vim package. They can be listed in last line mode by typing colorscheme, then pressing either Ctrl+d or pressing the Tab key twice:

:colorscheme
blue       darkblue   default    delek      desert     elflord    evening    industry   koehler    morning    murphy     pablo      peachpuff  ron        shine      slate      torte      zellner

They can be changed in Vim by using the colorscheme (alternatively use colo) command while in last line mode:

:colorscheme peachpuff

Color schemes can be permanently applied in the .vimrc file:

FILE ~/.vimrc
colorscheme peachpuff
syntax on

The first line sets the default color scheme while the last line activates the color scheme.

ヒントと小技

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 last line 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

こちらもご覧ください

  • Vim Guide - Vim の使い方をさらに詳しく解説しています。

外部の情報