From 20690d4a9b4db25426b7ee888b32879986d2c1b9 Mon Sep 17 00:00:00 2001 From: Milly Date: Thu, 6 Sep 2018 05:18:17 +0900 Subject: [PATCH 01/12] Update file and section header. --- vim_faq/vim_faq.jax | 168 +++++++++++++++++++++----------------------- 1 file changed, 82 insertions(+), 86 deletions(-) diff --git a/vim_faq/vim_faq.jax b/vim_faq/vim_faq.jax index 26cfb498f..6db8f36cc 100644 --- a/vim_faq/vim_faq.jax +++ b/vim_faq/vim_faq.jax @@ -1,32 +1,28 @@ *vim_faq.txt* よく訊かれる質問 -このファイルをインストールする方法については、vim内で > - :help add-local-help -とタイプしてください。 +Last updated on: 05 September 2018 -Last updated on: 17 October 2004 + VIM FAQ by: Christian Brabandt - VIM リファレンスマニュアル by: Yegappan Lakshmanan - -Frequently Asked Questions *faq* *FAQ* +Frequently Asked Questions *vim-faq* *Vim-FAQ* このVim FAQは、vim@vim.orgメーリングリストとcomp.editorsニューズグループに投稿 された質問とその答から作られました。Vimにおいて問題を解決する方法はいくつかあ ります。このFAQを読めば、その数種類の可能性のうちの1つが得られます。このFAQ中 の情報とリンクを使って他の方法を探すこともできます。このFAQの答に対するクレ -ジットはPeppe, Benji, Charles Campbellと他多数の人々に帰属します。 - +ジットはPeppe, Benji, Charles Campbellと他多数の人々に帰属します。FAQのオンラ +インバージョンは https://vimhelp.appspot.com/vim_faq.txt.html にあります。 *faq-index* -目次 +目次 ~ *faq-general-information* -SECTION 1 - 一般的な情報 +SECTION 1 - 一般的な情報 ~ |faq-1.1| Vimとは何ですか? |faq-1.2| 誰が Vim を書いたんですか? |faq-1.3| Vim は Vi と互換性がありますか? |faq-1.4| Vim が Vi よりも向上している点は何ですか? |faq-1.5| Vim は無料ですか? *faq-resources* -SECTION 2 - 情報源 +SECTION 2 - 情報源 ~ |faq-2.1| どこに行けば Vim についてもっと学べるでしょうか? |faq-2.2| メーリングリストはありますか? |faq-2.3| メーリングリストのアーカイブはありますか? @@ -42,14 +38,14 @@ SECTION 2 - 情報源 インを開発したり、新しいスクリプトやカラースキームを開発しました。 これをアップロードできる公開のウェブサイトはありますか? *faq-availability* -SECTION 3 - 入手 +SECTION 3 - 入手 ~ |faq-3.1| Vim の最新のバージョンは何ですか? |faq-3.2| どこで Vim の最新版を見つけられますか? |faq-3.3| どのプラットフォーム上で実行できるんですか? |faq-3.4| どこでVimのランタイムファイルの最新バージョンをダウンロードできま すか? *faq-help* -SECTION 4 - ヘルプ +SECTION 4 - ヘルプ ~ |faq-4.1| どうやってヘルプファイルを利用するんですか? |faq-4.2| どうやってVimヘルプファイル中のキーワードを探すんですか? |faq-4.3| エラーメッセージE123が出ました。何がまずいのでしょうか? @@ -58,7 +54,7 @@ SECTION 4 - ヘルプ イルを生成することができますか? |faq-4.6| 圧縮したヘルプファイルを使うことはできますか? *faq-editing-a-file* -SECTION 5 - ファイルの編集 +SECTION 5 - ファイルの編集 ~ |faq-5.1| ファイルを編集用に読み込むには? |faq-5.2| 現在のファイルを別な名前で保存(save as)して新しいファイルを編集す るには? @@ -73,7 +69,7 @@ SECTION 5 - ファイルの編集 |faq-5.9| ファイルを定期的に自動保存するには? |faq-5.10| ファイルを読み取り専用モードで開くには? *faq-editing-multiple-files* -SECTION 6 - 複数のファイルを編集する +SECTION 6 - 複数のファイルを編集する ~ |faq-6.1| Vim内で同時に複数のファイルを開くには? |faq-6.2| 複数のファイル・バッファを切り替えるには? |faq-6.3| それぞれのファイルを別ウィンドウで開くには? @@ -84,7 +80,7 @@ SECTION 6 - 複数のファイルを編集する |faq-6.6| Vim内でディレクトリをブラウズするには? |faq-6.7| ftp/scp/rcp/httpでネットワークごしにファイルを編集するには? *faq-backup* -SECTION 7 - バックアップ +SECTION 7 - バックアップ ~ |faq-7.1| ファイルを保存したとき元のファイル名の末尾に"~"という文字をつけた ファイルが作られます。このファイルを作成するのを止めさせるには? (または)バックアップ機能を無効にするには? @@ -93,7 +89,7 @@ SECTION 7 - バックアップ |faq-7.3| ファイルを保存するとファイルパーミッションが変更されます。ファイル パーミッションを変更せずにファイルを保存するよう設定するには? *faq-buffers* -SECTION 8 - バッファ +SECTION 8 - バッファ ~ |faq-8.1| バッファに対して変更を加えました。変更されたバッファを保存せずに、 かつ変更を失うことなく他のバッファを編集するには? |faq-8.2| バッファを切り替えるときに自動的に保存するよう設定するには? @@ -110,14 +106,14 @@ SECTION 8 - バッファ |faq-8.10| ウィンドウを閉じることなくバッファを削除するには? |faq-8.11| Tabキーで全バッファを巡回するようにマップするには? *faq-windows* -SECTION 9 - ウィンドウ +SECTION 9 - ウィンドウ ~ |faq-9.1| ウィンドウとバッファの違いは? |faq-9.2| ウィンドウの幅を広げるには? |faq-9.3| ウィンドウをズームイン・ズームアウトするには? |faq-9.4| 全バッファまたは全ウィンドウ、引数リスト中の全ファイルに対してex コマンドを実行するには? *faq-motion* -SECTION 10 - モーション +SECTION 10 - モーション ~ |faq-10.1| ファイルの先頭や末尾に移動するには? |faq-10.2| 挿入モードでキーを押してノーマルモードに移行すると、カーソル が1文字左へ移動します(カーソルが行の最初の文字の上にあるときを除い @@ -141,7 +137,7 @@ SECTION 10 - モーション |faq-10.12| テキストをスクロールするとき、前後の行を表示するには? |faq-10.13| 以前のカーソル位置に戻るには? *faq-searching-text* -SECTION 11 - テキストを検索する +SECTION 11 - テキストを検索する ~ |faq-11.1| テキストを検索した後、マッチしたテキストが全て強調されます。この強 調を一時的/永続的に無効にするには? |faq-11.2| 検索パターンにキャリッジリターン文字を含めるには? @@ -168,7 +164,7 @@ SECTION 11 - テキストを検索する |faq-11.21| 複数行にわたる文字列を検索するには? |faq-11.22| バッファの指定した範囲内から検索するには? *faq-changing-text* -SECTION 12 - テキストを変更する +SECTION 12 - テキストを変更する ~ |faq-12.1| 行末の空白文字(スペースとタブ)を全て削除するには? |faq-12.2| 連続する空白文字を1個のスペースに置換するには? |faq-12.3| 連続する空行を1行だけに圧縮するには? @@ -209,13 +205,13 @@ SECTION 12 - テキストを変更する |faq-12.33| ファイル中の全ての行の前に行番号をつけるには? |faq-12.34| 2つの文字・単語・行を入れ換えるには? *faq-completion-in-insert-mode* -SECTION 13 - 挿入モードでの補完 +SECTION 13 - 挿入モードでの補完 ~ |faq-13.1| 挿入モードで単語や行を補完するには? |faq-13.2| 挿入モードでファイル名を補完するには? |faq-13.3| 挿入モードで単語を補完するのにCTRL-P/CTRL-Nを使っています。 今補完した単語の後に現れる単語を補完するには? *faq-text-formatting* -SECTION 14 - テキストの整形 +SECTION 14 - テキストの整形 ~ |faq-14.1| 折り返された行の末尾に改行を挿入するには? |faq-14.2| 1行がn文字以下になるように長い行を整形するには? |faq-14.3| 短い行を連結して段落を形成するには? @@ -244,7 +240,7 @@ SECTION 14 - テキストの整形 |faq-14.16| ファイル中の全てのタブ文字をスペースに変換するには? |faq-14.17| 後でワードプロセッサーに送るテキストを編集するためのオプションは? *faq-visual-mode* -SECTION 15 - ビジュアルモード +SECTION 15 - ビジュアルモード ~ |faq-15.1| 矩形範囲をコピーするには? |faq-15.2| ファイルの特定の列を削除・変更するには? |faq-15.3| ビジュアル選択した行に対してexコマンドを適用するには? @@ -262,7 +258,7 @@ SECTION 15 - ビジュアルモード てしまいます。なぜですか? |faq-15.10| 最後にコピー/ペーストされたテキストをビジュアル選択するには? *faq-command-line-mode* -SECTION 16 - コマンドラインモード +SECTION 16 - コマンドラインモード ~ |faq-16.1| コマンドモードまたはexコマンドモードでカレントファイル名を使うには? |faq-16.2| Vimのコマンドラインで効率的にテキストを編集するには? |faq-16.3| ViモードからExモードに移行するには? @@ -276,13 +272,13 @@ SECTION 16 - コマンドラインモード |faq-16.7| あるコマンドを実行することなくコマンド履歴に入れるには? |faq-16.8| コマンドラインの高さを上げるには? *faq-viminfo* -SECTION 17 - VIMINFO +SECTION 17 - VIMINFO ~ |faq-17.1| Vimを起動したときviminfoファイルに不正な文字があるとエラーメッセー ジが出ます。このメッセージを出なくさせるには? |faq-17.2| viminfo機能を無効にするには? |faq-17.3| Vimのセッションをまたいでマークを保存し、使用するには? *faq-remote-editing* -SECTION 18 - リモート編集 +SECTION 18 - リモート編集 ~ |faq-18.1| 既に起動しているgvimでファイルを開くには? Vim 5.xの OpenWithVim.exeとSendToVim.exeはどうなりました? |faq-18.2| vimサーバーに全てのバッファをディスクに保存するようなコマンドを送 @@ -290,7 +286,7 @@ SECTION 18 - リモート編集 |faq-18.3| Vimのリモートサーバー機能についてのドキュメントはどこで手に入りま すか? *faq-options* -SECTION 19 - オプション +SECTION 19 - オプション ~ |faq-19.1| Vimを設定する簡単な方法は? |faq-19.2| オプションの値をトグルするには? |faq-19.3| 現在のバッファ/ウィンドウに対してだけ効果を及ぼすようにオプション @@ -312,7 +308,7 @@ SECTION 19 - オプション ようにするには? |faq-19.17| 1回の":set"コマンドでオプションから複数のフラグを除去するには? *faq-mapping-keys* -SECTION 20 - キーマップ +SECTION 20 - キーマップ ~ |faq-20.1| キーがどうマップされているかを知るには? |faq-20.2| ユーザー定義のキーマッピングをリストするには? |faq-20.3| キーマップを解除するには? @@ -337,7 +333,7 @@ SECTION 20 - キーマップ を作るには? |faq-20.16| キーの機能を保ったままCtrl-Iにマッピングするには? *faq-abbreviations* -SECTION 21 - 短縮入力 +SECTION 21 - 短縮入力 ~ |faq-21.1| スペリングを間違えた単語を自動的に修正するには? |faq-21.2| 複数行の短縮入力を作るには? |faq-21.3| 短縮入力が展開されたとき、展開されたテキストの末尾に余計なスペース @@ -345,7 +341,7 @@ SECTION 21 - 短縮入力 |faq-21.4| 現在の日付・時刻を挿入するには? |faq-21.5| 挿入モードで短縮入力が展開されるのを防ぐには? *faq-record-and-playback* -SECTION 22 - レコーディングと繰り返し +SECTION 22 - レコーディングと繰り返し ~ |faq-22.1| 編集操作(挿入、削除、ペースト等)を繰り返すには? |faq-22.2| キーシーケンスを記録し、繰り返すには? |faq-22.3| 記録したキーシーケンスを編集するには? @@ -354,7 +350,7 @@ SECTION 22 - レコーディングと繰り返し 記録したキーシーケンスの中でテキストをヤンクしています。一度その キーシーケンスを再生すると、もうそれを再現することができません。 *faq-autocommands* -SECTION 23 - 自動コマンド +SECTION 23 - 自動コマンド ~ |faq-23.1| 読み込み専用ファイルを修正しようとしたときにコマンドを実行するには? |faq-23.2| あるバッファに入るときに毎回コマンドを実行するには? |faq-23.3| あるウィンドウに入るときに毎回コマンドを実行するには? @@ -364,7 +360,7 @@ SECTION 23 - 自動コマンド するには? |faq-23.6| Vimを終了するときにクリーンアップ用の関数を実行するには? *faq-syntax-highlight* -SECTION 24 - 構文強調 +SECTION 24 - 構文強調 ~ |faq-24.1| 構文強調をオン・オフにするには? |faq-24.2| 背景色と文字色を変えるには? |faq-24.3| 暗い/明るい背景色に合うように色を変えるには? @@ -384,7 +380,7 @@ SECTION 24 - 構文強調 は? |faq-24.15| 現在の強調グループ定義を全て表示するには? *faq-vim-script-writing* -SECTION 25 - Vim script を書く +SECTION 25 - Vim script を書く ~ |faq-25.1| 読み込まれているスクリプトを全て表示するには? |faq-25.2| Vim scriptをデバッグするには? |faq-25.3| あるオプションを設定したスクリプト/プラグインを探すには? @@ -429,7 +425,7 @@ SECTION 25 - Vim script を書く |faq-25.30| 読み込んだスクリプトをun-sourceするには?言い替えると、スクリプト を読み込んだことによって実行されたコマンドを全て戻すには? *faq-plugins* -SECTION 26 - プラグイン +SECTION 26 - プラグイン ~ |faq-26.1| ファイル形式ごとに異なるオプションを設定するには? |faq-26.2| プラグイン/構文ファイル/インデントファイル/カラースキーム/ファイル タイププラグインをダウンロードしました。Vimがこれらのファイルを読 @@ -444,7 +440,7 @@ SECTION 26 - プラグイン タイプオプションを設定するには? *faq-editing-program-files* -SECTION 27 - プログラムファイルを編集する +SECTION 27 - プログラムファイルを編集する ~ |faq-27.1| C/C++のファイルに対してオートインデントを有効化するには? |faq-27.2| C/C++のファイルに対するインデントをカスタマイズするには? |faq-27.3| オートインデント機能を無効化するには? @@ -457,7 +453,7 @@ SECTION 27 - プログラムファイルを編集する |faq-27.9| Cのソースファイルに対応する名前のヘッダーファイルを開くには? |faq-27.10| コメントを入力しているとき、自動的にコメント文字を挿入するには? *faq-quickfix* -SECTION 28 - QuickFix +SECTION 28 - QuickFix ~ |faq-28.1| Vimの中からプログラムをビルドするには? |faq-28.2| Vim中からmakeコマンドを起動すると、コンパイラがプログラムをコンパ イルしてエラーメッセージを出力します。しかしコンパイルが終わると表 @@ -465,7 +461,7 @@ SECTION 28 - QuickFix ければなりません。このエラーメッセージを見るのに他の方法はありませ んか? *faq-folding* -SECTION 29 - 折り畳み +SECTION 29 - 折り畳み ~ |faq-29.1| 折り畳みの機能を拡張するには? |faq-29.2| 'foldmethod'をセットして折り畳みを有効化すると、全ての折り畳みが閉 じてしまいます。これを防ぐには? @@ -476,7 +472,7 @@ SECTION 29 - 折り畳み |faq-29.6| Vimを終了・再起動するとき、手動で作った折り畳みを保存・復元するに は? *faq-vim-with-external-applications* -SECTION 30 - 外部プログラムとの連携 +SECTION 30 - 外部プログラムとの連携 ~ |faq-30.1| Vimのウィンドウの中でシェルを起動することはできますか? |faq-30.2| カーソル下の単語を外部プログラムに渡すには? |faq-30.3| シェルコマンドの出力をVimのバッファに取り込むには? @@ -490,7 +486,7 @@ SECTION 30 - 外部プログラムとの連携 |faq-30.9| Vimのdiff機能で使われるdiffコマンドを変更するには? |faq-30.10| 折り畳みなしで差分モードを使うには? *faq-gui-vim* -SECTION 31 - GUIのVIM +SECTION 31 - GUIのVIM ~ |faq-31.1| バッファ固有のメニューを作るには? |faq-31.2| GUIのVimで使われるフォントを変更するには? |faq-31.3| GUIのVimが起動したときのウィンドウの位置を指定するには? @@ -518,7 +514,7 @@ SECTION 31 - GUIのVIM は? |faq-31.15| GVimウィンドウの位置とサイズを変更するには? *faq-vim-on-unix* -SECTION 32 - UNIX上のVim +SECTION 32 - UNIX上のVim ~ |faq-32.1| xtermでVimを実行しています。CTRL-Sを押すとVimがフリーズします。 どうすればいいですか? |faq-32.2| 画面の更新について奇妙な問題があります。これを解決するには? @@ -535,7 +531,7 @@ SECTION 32 - UNIX上のVim なCPU時間(99%)を食ってしまいます。なぜこうなるのですか? |faq-32.10| Unixターミナルで構文強調を使うには? *faq-vim-on-ms-windows* -SECTION 33 - MS-Windows上のVim +SECTION 33 - MS-Windows上のVim ~ |faq-33.1| MS-Windows上でCTRL-Vを押しても矩形ビジュアルモードが始まりません。 どうなっているのですか? |faq-33.2| CTRL-Yキーを押すとCTRL-Rのような動作をします。CTRL-YをCTRL-Yとして @@ -557,11 +553,11 @@ SECTION 33 - MS-Windows上のVim |faq-33.12| ファイルを保存する度に、そのファイルがVimの外部で変更されていると 警告が出ます。なぜですか? *faq-printing* -SECTION 34 - 印刷 +SECTION 34 - 印刷 ~ |faq-34.1| 全ての行に行番号をつけて印刷するには? |faq-34.2| 構文強調の色をつけてファイルを印刷するには? *faq-building-vim-from-source* -SECTION 35 - Vimをソースからビルドする +SECTION 35 - Vimをソースからビルドする ~ |faq-35.1| Unixシステム上でVimをソースからビルドするには? |faq-35.2| Unixでホームディレクトリなど、デフォルトのディレクトリ以外にVimを インストールするには? @@ -580,7 +576,7 @@ SECTION 35 - Vimをソースからビルドする ライブラリのリストを出力するpkg-configならありますが、なぜか configureスクリプトはこれを使ってくれません。 *faq-various* -SECTION 36 - 様々な事柄 +SECTION 36 - 様々な事柄 ~ |faq-36.1| Vimでバイナリフィルを編集するには? |faq-36.2| ビジュアルエラーフラッシュとエラービープを無効にするには? |faq-36.3| バッファに表示されている文字のASCIIコードを表示するには? @@ -591,7 +587,7 @@ SECTION 36 - 様々な事柄 ドを実行するには? |faq-36.8| 挿入モードから抜けることなくノーマルモードコマンドを実行するには? *faq-unicode* -SECTION 37 - Unicode +SECTION 37 - Unicode ~ |faq-37.1| VimでUnicodeのファイルを作ることはできますか? |faq-37.2| Unicodeのファイルを編集するにあたって特に重要な設定は? |faq-37.3| オプション'encoding'とは何ですか? @@ -607,7 +603,7 @@ SECTION 37 - Unicode ============================================================================= *faq-1* -SECTION 1 - 一般的な情報 +SECTION 1 - 一般的な情報 ~ *faq-1.1* 1.1. Vimとは何ですか? @@ -794,7 +790,7 @@ Vim はチャリティウェアです。Vim の使用や複製に関しては何 ============================================================================= *faq-2* -SECTION 2 - 情報源 +SECTION 2 - 情報源 ~ *faq-2.1* 2.1. どこに行けば Vim についてもっと学べるでしょうか? @@ -949,7 +945,7 @@ http://vim.sourceforge.netにあります。 ============================================================================= *faq-3* -SECTION 3 - 入手 +SECTION 3 - 入手 ~ *faq-3.1* 3.1. Vim の最新のバージョンは何ですか? @@ -1004,7 +1000,7 @@ ftpサイトのftp://ftp.vim.org/pub/vim/runtimeディレクトリでダウン ============================================================================= *faq-4* -SECTION 4 - ヘルプ +SECTION 4 - ヘルプ ~ *faq-4.1* 4.1. どうやってヘルプファイルを利用するんですか? @@ -1132,7 +1128,7 @@ Vimにおけるモードの違いについては、以下を読めば情報を ============================================================================= *faq-5* -SECTION 5 - ファイルの編集 +SECTION 5 - ファイルの編集 ~ *faq-5.1* 5.1. ファイルを編集用に読み込むには? @@ -1327,7 +1323,7 @@ Vimにはファイルを定期的に自動保存する機能はありません ============================================================================= *faq-6* -SECTION 6 - 複数のファイルを編集する +SECTION 6 - 複数のファイルを編集する ~ *faq-6.1* 6.1. Vim内で同時に複数のファイルを開くには? @@ -1472,7 +1468,7 @@ ftp/scp/rcp/httpごしのファイルを透過的に読み込み、保存しま ============================================================================= *faq-7* -SECTION 7 - バックアップ +SECTION 7 - バックアップ ~ *faq-7.1* 7.1. ファイルを保存したとき元のファイル名の末尾に"~"という文字をつけたファイル @@ -1485,7 +1481,7 @@ SECTION 7 - バックアップ :set nobackup < -Note デフォルトではこのオプションはオフにされています。初期設定ファイルのどこ +注記: デフォルトではこのオプションはオフにされています。初期設定ファイルのどこ かで明示的に'backup'オプションが有効化されています。'writebackup'オプションも オフにするとよいかもしれません: > @@ -1522,7 +1518,7 @@ Note デフォルトではこのオプションはオフにされています。 7.3. ファイルを保存するとファイルパーミッションが変更されます。ファイルパー ミッションを変更せずにファイルを保存するよう設定するには? -これは'backupcopy'が'no'または'auto'に設定されていると起こりえます。Note この +これは'backupcopy'が'no'または'auto'に設定されていると起こりえます。注記: この オプションのデフォルト値はほとんどの場合に正しく動作するように設定されていま す。もしそのデフォルト値が正しく機能しないなら、'backupcopy'オプションを'yes' にすればファイル保存時にパーミッションをそのままにすることができます: > @@ -1542,7 +1538,7 @@ Note デフォルトではこのオプションはオフにされています。 ============================================================================= *faq-8* -SECTION 8 - バッファ +SECTION 8 - バッファ ~ *faq-8.1* 8.1. バッファに対して変更を加えました。変更されたバッファを保存せずに、かつ変 @@ -1698,7 +1694,7 @@ CTRL-Gの前にカウントを指定することに注意してください。 ============================================================================= *faq-9* -SECTION 9 - ウィンドウ +SECTION 9 - ウィンドウ ~ *faq-9.1* 9.1. ウィンドウとバッファの違いは? @@ -1803,7 +1799,7 @@ http://vim.sourceforge.net/scripts/script.php?script_id=508 ============================================================================= *faq-10* -SECTION 10 - モーション +SECTION 10 - モーション ~ *faq-10.1* 10.1. ファイルの先頭や末尾に移動するには? @@ -2052,7 +2048,7 @@ g0コマンドでカーソルを画面上最初の文字へ、g$コマンドで ============================================================================= *faq-11* -SECTION 11 - テキストを検索する +SECTION 11 - テキストを検索する ~ *faq-11.1* 11.1. テキストを検索した後、マッチしたテキストが全て強調されます。この強調を一 @@ -2437,7 +2433,7 @@ SECTION 11 - テキストを検索する ============================================================================= *faq-12* -SECTION 12 - テキストを変更する +SECTION 12 - テキストを変更する ~ *faq-12.1* 12.1. 行末の空白文字(スペースとタブ)を全て削除するには? @@ -3010,7 +3006,7 @@ Uと16進の数字0-7FFFFFFFを入力すれば、印字不能文字を入力す < ============================================================================= -SECTION 13 - 挿入モードでの補完 +SECTION 13 - 挿入モードでの補完 ~ *faq-13.1* 13.1. 挿入モードで単語や行を補完するには? @@ -3065,7 +3061,7 @@ CTRL-X CTRL-NとCTRL-X CTRL-Pを使うと今補完した単語の後に続く単 ============================================================================= *faq-14* -SECTION 14 - テキストの整形 +SECTION 14 - テキストの整形 ~ *faq-14.1* 14.1. 折り返された行の末尾に改行を挿入するには? @@ -3401,7 +3397,7 @@ smartindent, textwidth)によります。テキストをVimに貼り付ける前 ============================================================================= *faq-15* -SECTION 15 - ビジュアルモード +SECTION 15 - ビジュアルモード ~ *faq-15.1* 15.1. 矩形範囲をコピーするには? @@ -3558,7 +3554,7 @@ ggVGでファイル全体をビジュアル選択することができます。 ============================================================================= *faq-16* -SECTION 16 - コマンドラインモード +SECTION 16 - コマンドラインモード ~ *faq-16.1* 16.1. コマンドモードまたはexコマンドモードでカレントファイル名を使うには? @@ -3698,7 +3694,7 @@ CTRL-R を使って特定のレジスタにヤンクしてからコマ ============================================================================= *faq-17* -SECTION 17 - VIMINFO +SECTION 17 - VIMINFO ~ *faq-17.1* 17.1. Vimを起動したときviminfoファイルに不正な文字があるとエラーメッセージが出 @@ -3746,7 +3742,7 @@ viminfoを使えばVimのセッションをまたいでマークを保存し、 ============================================================================= *faq-18* -SECTION 18 - リモート編集 +SECTION 18 - リモート編集 ~ *faq-18.1* 18.1. 既に起動しているgvimでファイルを開くには? Vim 5.xのOpenWithVim.exeと @@ -3789,7 +3785,7 @@ Vimのリモートサーバー機能についての情報はこれを読めば ============================================================================= *faq-19* -SECTION 19 - オプション +SECTION 19 - オプション ~ *faq-19.1* 19.1. Vimを設定する簡単な方法は? @@ -4066,7 +4062,7 @@ Vimは普通のエスケープとカーソルキーのシーケンスなどを ============================================================================= *faq-20* -SECTION 20 - キーマップ +SECTION 20 - キーマップ ~ *faq-20.1* 20.1. キーがどうマップされているかを知るには? @@ -4380,7 +4376,7 @@ Ctrl-Iとは同じキーコードを生成します。そのため、Vimは ============================================================================= *faq-21* -SECTION 21 - 短縮入力 +SECTION 21 - 短縮入力 ~ *faq-21.1* 21.1. スペリングを間違えた単語を自動的に修正するには? @@ -4476,7 +4472,7 @@ strftime()を使えば現在の日付・時刻のタイムスタンプを挿入 ============================================================================= *faq-22* -SECTION 22 - レコーディングと繰り返し +SECTION 22 - レコーディングと繰り返し ~ *faq-22.1* 22.1. 編集操作(挿入、削除、ペースト等)を繰り返すには? @@ -4565,7 +4561,7 @@ SECTION 22 - レコーディングと繰り返し ============================================================================= *faq-23* -SECTION 23 - 自動コマンド +SECTION 23 - 自動コマンド ~ *faq-23.1* 23.1. 読み込み専用ファイルを修正しようとしたときにコマンドを実行するには? @@ -4647,7 +4643,7 @@ VimLeaveイベントを使えば、Vimが終了する直前に関数を実行す ============================================================================= *faq-24* -SECTION 24 - 構文強調 +SECTION 24 - 構文強調 ~ *faq-24.1* 24.1. 構文強調をオン・オフにするには? @@ -4897,7 +4893,7 @@ $VIM/vimfiles/syntaxディレクトリに置きます。 ============================================================================= *faq-25* -SECTION 25 - Vim script を書く +SECTION 25 - Vim script を書く ~ *faq-25.1* 25.1. 読み込まれているスクリプトを全て表示するには? @@ -5395,7 +5391,7 @@ system()を使うと、外部コマンドを起動し、出力を取得するこ ============================================================================= *faq-26* -SECTION 26 - プラグイン +SECTION 26 - プラグイン ~ *faq-26.1* 26.1. ファイル形式ごとに異なるオプションを設定するには? @@ -5585,7 +5581,7 @@ Unixシステムでは、通常これは"$HOME/.vim"ディレクトリになり ============================================================================= *faq-27* -SECTION 27 - プログラムファイルを編集する +SECTION 27 - プログラムファイルを編集する ~ *faq-27.1* 27.1. C/C++のファイルに対してオートインデントを有効化するには? @@ -5762,7 +5758,7 @@ SECTION 27 - プログラムファイルを編集する ============================================================================= *faq-28* -SECTION 28 - QuickFix +SECTION 28 - QuickFix ~ *faq-28.1* 28.1. Vimの中からプログラムをビルドするには? @@ -5797,7 +5793,7 @@ SECTION 28 - QuickFix ============================================================================= *faq-29* -SECTION 29 - 折り畳み +SECTION 29 - 折り畳み ~ *faq-29.1* 29.1. 折り畳みの機能を拡張するには? @@ -5905,7 +5901,7 @@ SECTION 29 - 折り畳み ============================================================================= *faq-30* -SECTION 30 - 外部プログラムとの連携 +SECTION 30 - 外部プログラムとの連携 ~ *faq-30.1* 30.1. Vimのウィンドウの中でシェルを起動することはできますか? @@ -6063,7 +6059,7 @@ Vim標準ディストリビューションに同梱のman.vimを使えば、Vim ============================================================================= *faq-31* -SECTION 31 - GUIのVIM +SECTION 31 - GUIのVIM ~ *faq-31.1* 31.1. バッファ固有のメニューを作るには? @@ -6299,7 +6295,7 @@ Vimは等幅フォントのみサポートしています。プロポーショ < ============================================================================= -SECTION 32 - UNIX上のVim +SECTION 32 - UNIX上のVim ~ *faq-32.1* 32.1. xtermでVimを実行しています。CTRL-Sを押すとVimがフリーズします。 @@ -6487,7 +6483,7 @@ Xfree86 xtermはhttp://dickey.his.com/xterm/xterm.htmlからダウンロード ============================================================================= *faq-33* -SECTION 33 - MS-Windows上のVim +SECTION 33 - MS-Windows上のVim ~ *faq-33.1* 33.1. MS-Windows上でCTRL-Vを押しても矩形ビジュアルモードが始まりません。どう @@ -6649,7 +6645,7 @@ MS-Windowsでのサマータイム(daylight saving time)が始まる日につい ============================================================================= *faq-34* -SECTION 34 - 印刷 +SECTION 34 - 印刷 ~ *faq-34.1* 34.1. 全ての行に行番号をつけて印刷するには? @@ -6681,7 +6677,7 @@ SECTION 34 - 印刷 ============================================================================= *faq-35* -SECTION 35 - Vimをソースからビルドする +SECTION 35 - Vimをソースからビルドする ~ *faq-35.1* 35.1. Unixシステム上でVimをソースからビルドするには? @@ -6836,7 +6832,7 @@ Vimランタイムパッケージの一部です。Vimランタイムパッケ ============================================================================= *faq-36* -SECTION 36 - 様々な事柄 +SECTION 36 - 様々な事柄 ~ *faq-36.1* 36.1. Vimでバイナリフィルを編集するには? @@ -6990,7 +6986,7 @@ CTRL-Oに続けてノーマルモードコマンドを1つ入力すると、挿 ============================================================================= *faq-37* -SECTION 37 - Unicode +SECTION 37 - Unicode ~ Author: Tony Mechelynck *faq-37.1* From 3d0d87654654f58f1d453432e2d2170bc294edd6 Mon Sep 17 00:00:00 2001 From: Milly Date: Thu, 6 Sep 2018 16:47:37 +0900 Subject: [PATCH 02/12] Import upsteam 2018-09-05. --- vim_faq/vim_faq.txt | 6351 ++++++++++++++++++++++++++----------------- 1 file changed, 3865 insertions(+), 2486 deletions(-) diff --git a/vim_faq/vim_faq.txt b/vim_faq/vim_faq.txt index fe19704fc..6ffb3e355 100644 --- a/vim_faq/vim_faq.txt +++ b/vim_faq/vim_faq.txt @@ -1,738 +1,767 @@ *vim_faq.txt* Frequently Asked Questions -For instructions on installing this file, type > - :help add-local-help -inside Vim. +Last updated on: 05 September 2018 -Last updated on: 17 October 2004 + VIM FAQ by: Christian Brabandt - VIM REFERENCE MANUAL by: Yegappan Lakshmanan - -Frequently Asked Questions *faq* *FAQ* +Frequently Asked Questions *vim-faq* *Vim-FAQ* This Vim FAQ is created from the questions and answers posted to the vim@vim.org user mailing list and the comp.editors newsgroup. There are several ways to solve a problem in Vim. This FAQ gives one of those several possibilities. You can explore the other ways using the information and links given in this FAQ. The credit for the answers in this FAQ goes to -Peppe, Benji, Charles Campbell and numerous others. +Peppe, Benji, Charles Campbell and numerous others. An online version of +this FAQ is available at https://vimhelp.appspot.com/vim_faq.txt.html *faq-index* -INDEX +INDEX ~ *faq-general-information* -SECTION 1 - GENERAL INFORMATION +SECTION 1 - GENERAL INFORMATION ~ |faq-1.1| What is Vim? |faq-1.2| Who wrote Vim? |faq-1.3| Is Vim compatible with Vi? |faq-1.4| What are some of the improvements of Vim over Vi? |faq-1.5| Is Vim free? *faq-resources* -SECTION 2 - RESOURCES +SECTION 2 - RESOURCES ~ |faq-2.1| Where can I learn more about Vim? |faq-2.2| Is there a mailing list available? |faq-2.3| Is there an archive available for the Vim mailing lists? |faq-2.4| Where can I get the Vim user manual in HTML/PDF/PS format? -|faq-2.5| I have a "xyz" (some) problem with Vim. How do I determine it is a - problem with my setup or with Vim? +|faq-2.5| I have a "xyz" (some) problem with Vim. How do I determine if it is + a problem with my setup or with Vim? |faq-2.6| Where can I report bugs? |faq-2.7| Where can the FAQ be found? |faq-2.8| What if I don't find an answer in this FAQ? |faq-2.9| I have a patch for implementing a Vim feature. Where do I send the - patch? + patch? |faq-2.10| I have a Vim tip or developed a new Vim - syntax/indent/filetype/compiler plugin or developed a new script - or a colorscheme. Is there a public website where I can upload - this? + syntax/indent/filetype/compiler plugin or developed a new script + or a colorscheme. Is there a public website where I can upload + this? *faq-availability* -SECTION 3 - AVAILABILITY -|faq-3.1| What is the latest version of Vim? -|faq-3.2| Where can I find the latest version of Vim? +SECTION 3 - AVAILABILITY ~ +|faq-3.1| What is the latest version of Vim? +|faq-3.2| Where can I find the latest version of Vim? |faq-3.3| What platforms does it run on? |faq-3.4| Where can I download the latest version of the Vim runtime files? *faq-help* -SECTION 4 - HELP +SECTION 4 - HELP ~ |faq-4.1| How do I use the help files? |faq-4.2| How do I search for a keyword in the Vim help files? |faq-4.3| I am getting an error message E123, what did I do wrong? |faq-4.4| Where can I read about the various modes in Vim? |faq-4.5| How do I generate the Vim help tags file after adding a new Vim - help file? + help file? |faq-4.6| Can I use compressed versions of the help files? *faq-editing-a-file* -SECTION 5 - EDITING A FILE +SECTION 5 - EDITING A FILE ~ |faq-5.1| How do I load a file in Vim for editing? |faq-5.2| How do I save the current file in another name (save as) and edit - a new file? + a new file? |faq-5.3| How do I change the current directory to the directory of the - current file? + current file? |faq-5.4| How do I write a file without the line feed (EOL) at the end of - the file? + the file? |faq-5.5| How do I configure Vim to open a file at the last edited location? |faq-5.6| When editing a file in Vim, which is being changed by an external - application, Vim opens a warning window (like the confirm dialog) - each time a change is detected. How do I disable this warning? + application, Vim opens a warning window (like the confirm dialog) + each time a change is detected. How do I disable this warning? |faq-5.7| How do I edit a file whose name is under the cursor? |faq-5.8| How do I reload/re-edit the current file? |faq-5.9| How do I autosave a file periodically? |faq-5.10| How do I open a file in read-only mode? +|faq-5.11| How do I open a file for editing without saving the modifications + to the current file? +|faq-5.12| How do I reduce the loading time for very large files in Vim? *faq-editing-multiple-files* -SECTION 6 - EDITING MULTIPLE FILES +SECTION 6 - EDITING MULTIPLE FILES ~ |faq-6.1| How do I open multiple files at once from within Vim? |faq-6.2| How do I switch between multiple files/buffers in Vim? |faq-6.3| How do I open several files in Vim, with each file in a separate - window? + window/tabpage? |faq-6.4| How do I configure Vim to autoload several files at once similar - to "work-sets" or "projects"? + to "work-sets" or "projects"? |faq-6.5| Is it possible to open multiple top level windows in a single - instance of Vim similar to Nedit or emacs? + instance of Vim similar to Nedit or emacs? |faq-6.6| How do I browse/explore directories from within Vim? |faq-6.7| How do I edit files over a network using ftp/scp/rcp/http? *faq-backup* -SECTION 7 - BACKUP +SECTION 7 - BACKUP ~ |faq-7.1| When I edit and save files, Vim creates a file with the same name - as the original file and a "~" character at the end. How do I stop - Vim from creating this file (or) How do I disable the Vim backup - file feature? -|faq-7.2| How do I configure Vim to store all the backup files in a - particular directory? -|faq-7.3| When I save a file with Vim, the file permissions are changed. - How do I configure Vim to save a file without changing the file - permissions? + as the original file and a "~" character at the end. How do I stop + Vim from creating this file (or) How do I disable the Vim backup + file feature? +|faq-7.2| When I edit and save files, Vim creates a file with the same name + as the original file and a ".un~" extension at the end. How do I + stop Vim from creating this file (or) How do I disable the Vim + undofile feature. +|faq-7.3| How do I configure Vim to store all the backup files in a + particular directory? +|faq-7.4| When I save a file with Vim, the file permissions are changed. + How do I configure Vim to save a file without changing the file + permissions? *faq-buffers* -SECTION 8 - BUFFERS +SECTION 8 - BUFFERS ~ |faq-8.1| I have made some modifications to a buffer. How do I edit another - buffer without saving the modified buffer and also without losing - the modifications? + buffer without saving the modified buffer and also without losing + the modifications? |faq-8.2| How do I configure Vim to auto-save a modified buffer when - switching to another buffer? + switching to another buffer? |faq-8.3| How do I replace the buffer in the current window with a blank - buffer? + buffer? |faq-8.4| Is there a keyboard shortcut to load a buffer by the buffer - number? + number? |faq-8.5| How do I open all the current buffers in separate windows? |faq-8.6| How do I close (delete) a buffer without exiting Vim? -|faq-8.7| I have several buffers opened with ":e filename". How do I close - one of the buffers without exiting Vim? -|faq-8.8| When I use the command ":%bd" to delete all the buffers, not all - the buffers are deleted. Why? -|faq-8.9| How do I display the buffer number of the current buffer/file? -|faq-8.10| How do I delete a buffer without closing the window in which the - buffer is displayed? -|faq-8.11| How do I map the tab key to cycle through and open all the - buffers? +|faq-8.7| When I use the command ":%bd" to delete all the buffers, not all + the buffers are deleted. Why? +|faq-8.8| How do I display the buffer number of the current buffer/file? +|faq-8.9| How do I delete a buffer without closing the window in which the + buffer is displayed? +|faq-8.10| How do I map the tab key to cycle through and open all the + buffers? *faq-windows* -SECTION 9 - WINDOWS +SECTION 9 - WINDOWS ~ |faq-9.1| What is the difference between a Vim window and a buffer? |faq-9.2| How do I increase the width of a Vim window? -|faq-9.3| How do I zoom into or out of a window? +|faq-9.3| How do I zoom into or out of a window? |faq-9.4| How do I execute an ex command on all the open buffers or open - windows or all the files in the argument list? + windows or all the files in the argument list? *faq-motion* -SECTION 10 - MOTION +SECTION 10 - MOTION ~ |faq-10.1| How do I jump to the beginning (first line) or end (last line) of - a file? + a file? |faq-10.2| In insert mode, when I press the key to go to command mode, - the cursor moves one character to the left (except when the cursor - is on the first character of the line). Is it possible to change - this behavior to keep the cursor at the same column? + the cursor moves one character to the left (except when the + cursor is on the first character of the line). Is it possible to + change this behavior to keep the cursor at the same column? |faq-10.3| How do I configure Vim to maintain the horizontal cursor position - when scrolling with the , , etc keys? + when scrolling with the , , etc keys? |faq-10.4| Some lines in a file are more than the screen width and they are - all wrapped. When I use the j, k keys to move from one line to the - next, the cursor is moved to the next line in the file instead of - the next line on the screen. How do I move from one screen line to - the next? + all wrapped. When I use the j, k keys to move from one line to + the next, the cursor is moved to the next line in the file + instead of the next line on the screen. How do I move from one + screen line to the next? |faq-10.5| What is the definition of a sentence, paragraph and section in - Vim? + Vim? |faq-10.6| How do I jump to beginning or end of a sentence, paragraph or a - section? + section? |faq-10.7| I have lines in a file that extends beyond the right extent of the - screen. How do I move the Vim view to the right to see the text - off the screen? + screen. How do I move the Vim view to the right to see the text + off the screen? |faq-10.8| How do I scroll two or more buffers simultaneously? |faq-10.9| When I use my arrow keys, Vim changes modes, inserts weird - characters in my document but doesn't move the cursor properly. - What's going on? + characters in my document but doesn't move the cursor properly. + What's going on? |faq-10.10| How do I configure Vim to move the cursor to the end of the - previous line, when the left arrow key is pressed and the cursor - is currently at the beginning of a line? + previous line, when the left arrow key is pressed and the cursor + is currently at the beginning of a line? |faq-10.11| How do I configure Vim to stay only in insert mode (modeless - editing)? + editing)? |faq-10.12| How do I display some context lines when scrolling text? -|faq-10.13| How do I go back to previous cursor locations? +|faq-10.13| How do I go back to previous cursor locations? *faq-searching-text* -SECTION 11 - SEARCHING TEXT +SECTION 11 - SEARCHING TEXT ~ |faq-11.1| After I searched for a text with a pattern, all the matched text - stays highlighted. How do I turn off the highlighting - temporarily/permanently? + stays highlighted. How do I turn off the highlighting + temporarily/permanently? |faq-11.2| How do I enter a carriage return character in a search pattern? |faq-11.3| How do I search for the character ^M? |faq-11.4| How can I search/replace characters that display as '~R', '~S', - etc.? + etc.? |faq-11.5| How do I highlight all the non-printable characters in a file? |faq-11.6| How do I search for whole words in a file? |faq-11.7| How do I search for the current word under the cursor? |faq-11.8| How do I search for a word without regard to the case (uppercase - or lowercase)? + or lowercase)? |faq-11.9| How do I search for words that occur twice consecutively? |faq-11.10| How do I count the number of times a particular word occurs in a - buffer? + buffer? |faq-11.11| How do I place the cursor at the end of the matched word when - searching for a pattern? + searching for a pattern? |faq-11.12| How do I search for an empty line? |faq-11.13| How do I search for a line containing only a single character? |faq-11.14| How do I search and replace a string in multiple files? |faq-11.15| I am using the ":s" substitute command in a mapping. When a - search for a pattern fails, the map terminates. I would like the - map to continue processing the next command, even if the - substitute command fails. How do I do this? + search for a pattern fails, the map terminates. I would like the + map to continue processing the next command, even if the + substitute command fails. How do I do this? |faq-11.16| How do I search for the n-th occurrence of a character in a - line? + line? |faq-11.17| How do I replace a tab (or any other character) with a hard - return (newline) character? + return (newline) character? |faq-11.18| How do I search for a character by its ASCII value? |faq-11.19| How do I search for long lines? |faq-11.20| How do I display all the lines in the current buffer that - contain a specified pattern? + contain a specified pattern? |faq-11.21| How do I search for a text string that spans multiple lines? |faq-11.22| How do I search for a pattern only within a range of lines - in a buffer? + in a buffer? +|faq-11.23| How do I clear the last searched pattern? +|faq-11.24| Why does this pattern 'a.\{-}p\@!' not match? +|faq-11.25| How can I use '/' within a pattern, without escaping it? +|faq-11.26| How can I operate on a search match? *faq-changing-text* -SECTION 12 - CHANGING TEXT +SECTION 12 - CHANGING TEXT ~ |faq-12.1| How do I delete all the trailing white space characters (SPACE - and TAB) at the end of all the lines in a file? + and TAB) at the end of all the lines in a file? |faq-12.2| How do I replace all the occurrences of multiple consecutive - space characters to a single space? + space characters to a single space? |faq-12.3| How do I reduce a range of empty lines into one line only? |faq-12.4| How do I delete all blank lines in a file? How do I remove all - the lines containing only space characters? -|faq-12.5| How do I copy/yank the current word? + the lines containing only space characters? +|faq-12.5| How do I copy/yank the current word? |faq-12.6| How do I yank text from one position to another position within a - line, without yanking the entire line? + line, without yanking the entire line? |faq-12.7| When I yank some text into a register, how do I append the text - to the current contents of the register? + to the current contents of the register? |faq-12.8| How do I yank a complete sentence that spans over more than one - line? + line? |faq-12.9| How do I yank all the lines containing a pattern into a buffer? -|faq-12.10| How do I delete all the lines in a file that does not contain a - pattern? +|faq-12.10| How do I delete all the lines in a file that do not contain a + pattern? |faq-12.11| How do I add a line before each line with "pattern" in it? |faq-12.12| Is there a way to operate on a line if the previous line - contains a particular pattern? + contains a particular pattern? |faq-12.13| How do I execute a command on all the lines containing a - pattern? + pattern? |faq-12.14| Can I copy the character above the cursor to the current cursor - position? + position? |faq-12.15| How do I insert a blank line above/below the current line - without entering insert mode? -|faq-12.16| How do I insert the name of current file into the current - buffer? + without entering insert mode? +|faq-12.16| How do I insert the name of the current file into the current + buffer? |faq-12.17| How do I insert the contents of a Vim register into the current - buffer? + buffer? |faq-12.18| How do I move the cursor past the end of line and insert some - characters at some columns after the end of the line? + characters at some columns after the end of the line? |faq-12.19| How to replace the word under the cursor (say: junk) with - "foojunkbar" in Vim? + "foojunkbar" in Vim? |faq-12.20| How do I replace a particular text in all the files in a - directory? + directory? |faq-12.21| I have some numbers in a file. How do I increment or decrement - the numbers in the file? + the numbers in the file? |faq-12.22| How do I reuse the last used search pattern in a ":substitute" - command? + command? |faq-12.23| How do I change the case of a string using the ":substitute" - command? + command? |faq-12.24| How do I enter characters that are not present in the keyboard? |faq-12.25| Is there a command to remove any or all digraphs? |faq-12.26| In insert mode, when I press the backspace key, it erases only - the characters entered in this instance of insert mode. How do I - erase previously entered characters in insert mode using the - backspace key? + the characters entered in this instance of insert mode. How do I + erase previously entered characters in insert mode using the + backspace key? |faq-12.27| I have a file which has lines longer than 72 characters - terminated with "+" and wrapped to the next line. How can I - quickly join the lines? + terminated with "+" and wrapped to the next line. How can I + quickly join the lines? |faq-12.28| How do I paste characterwise yanked text into separate lines? |faq-12.29| How do I change the case (uppercase, lowercase) of a word or - a character or a block of text? + a character or a block of text? |faq-12.30| How do I enter ASCII characters that are not present in the - keyboard? + keyboard? |faq-12.31| How do I replace non-printable characters in a file? |faq-12.32| How do I remove duplicate lines from a buffer? |faq-12.33| How do I prefix all the lines in a file with the corresponding - line numbers? + line numbers? |faq-12.34| How do I exchange (swap) two characters or words or lines? +|faq-12.35| How do I change the characters used as word delimiters? *faq-completion-in-insert-mode* -SECTION 13 - COMPLETION IN INSERT MODE +SECTION 13 - COMPLETION IN INSERT MODE ~ |faq-13.1| How do I complete words or lines in insert mode? |faq-13.2| How do I complete file names in insert mode? |faq-13.3| I am using CTRL-P/CTRL-N to complete words in insert mode. How do - I complete words that occur after the just completed word? + I complete words that occur after the just completed word? *faq-text-formatting* -SECTION 14 - TEXT FORMATTING +SECTION 14 - TEXT FORMATTING ~ |faq-14.1| How do I format a text paragraph so that a new line is inserted - at the end of each wrapped line? + at the end of each wrapped line? |faq-14.2| How do I format long lines in a file so that each line contains - less than 'n' characters? + less than 'n' characters? |faq-14.3| How do I join short lines to the form a paragraph? |faq-14.4| How do I format bulleted and numbered lists? -|faq-14.5| How do I indent lines in insert mode? +|faq-14.5| How do I indent lines in insert mode? |faq-14.6| How do I format/indent an entire file? |faq-14.7| How do I increase or decrease the indentation of the current - line? + line? |faq-14.8| How do I indent a block/group of lines? |faq-14.9| When I indent lines using the > or < key, the standard 8-tabstops - are used instead of the current 'tabstop' setting. Why? + are used instead of the current 'tabstop' setting. Why? |faq-14.10| How do I turn off the automatic indentation of text? |faq-14.11| How do I configure Vim to automatically set the 'textwidth' - option to a particular value when I edit mails? + option to a particular value when I edit mails? |faq-14.12| Is there a way to make Vim auto-magically break lines? |faq-14.13| I am seeing a lot of ^M symbols in my file. I tried setting the - 'fileformat' option to 'dos' and then 'unix' and then 'mac'. - None of these helped. How can I hide these symbols? + 'fileformat' option to 'dos' and then 'unix' and then 'mac'. + None of these helped. How can I hide these symbols? |faq-14.14| When I paste some text into a Vim buffer from another - application, the alignment (indentation) of the new text is - messed up. How do I fix this? + application, the alignment (indentation) of the new text is + messed up. How do I fix this? |faq-14.15| When there is a very long wrapped line (wrap is "on") and a line - doesn't fit entirely on the screen it is not displayed at all. - There are blank lines beginning with '@' symbol instead of - wrapped line. If I scroll the screen to fit the line the '@' - symbols disappear and the line is displayed again. What Vim - setting control this behavior? + doesn't fit entirely on the screen it is not displayed at all. + There are blank lines beginning with '@' symbol instead of + wrapped line. If I scroll the screen to fit the line the '@' + symbols disappear and the line is displayed again. What Vim + setting control this behavior? |faq-14.16| How do I convert all the tab characters in a file to space - characters? + characters? |faq-14.17| What Vim options can I use to edit text that will later go to a - word processor? + word processor? +|faq-14.18| How do I join lines without adding or removing any space + characters? *faq-visual-mode* -SECTION 15 - VISUAL MODE +SECTION 15 - VISUAL MODE ~ |faq-15.1| How do I do rectangular block copying? |faq-15.2| How do I delete or change a column of text in a file? |faq-15.3| How do I apply an ex-command on a set of visually selected lines? |faq-15.4| How do I execute an ex command on a column of text selected in - Visual block mode? + Visual block mode? |faq-15.5| How do I select the entire file in visual mode? |faq-15.6| When I visually select a set of lines and press the > key to - indent the selected lines, the visual mode ends. How can I - reselect the region for further operation? (or) How do I - re-select the last selected visual area again? + indent the selected lines, the visual mode ends. How can I + reselect the region for further operation? (or) How do I + re-select the last selected visual area again? |faq-15.7| How do I jump to the beginning/end of a visually selected region? |faq-15.8| When I select text with mouse and then press : to enter an ex - command, the selected text is replaced with the : character. How - do I execute an ex command on a text selected using the mouse - similar to the text selected using the visual mode? + command, the selected text is replaced with the : character. How + do I execute an ex command on a text selected using the mouse + similar to the text selected using the visual mode? |faq-15.9| When I select a block of text using the mouse, Vim goes into - selection mode instead of Visual mode. Why? + selection mode instead of Visual mode. Why? *faq-command-line-mode* -SECTION 16 - COMMAND-LINE MODE +SECTION 16 - COMMAND-LINE MODE ~ |faq-16.1| How do I use the name of the current file in the command mode or - an ex command line? + an ex command line? |faq-16.2| How do I edit the text in the Vim command-line effectively? |faq-16.3| How do I switch from Vi mode to Ex mode? |faq-16.4| How do I copy the output from an ex-command into a buffer? |faq-16.5| When I press the tab key to complete the name of a file in the - command mode, if there are more than one matching file names, - then Vim completes the first matching file name and displays a - list of all matching filenames. How do I configure Vim to only - display the list of all the matching filenames and not complete - the first one? + command mode, if there are more than one matching file names, + then Vim completes the first matching file name and displays a + list of all matching filenames. How do I configure Vim to only + display the list of all the matching filenames and not complete + the first one? |faq-16.6| How do I copy text from a buffer to the command line and from the - command line to a buffer? + command line to a buffer? |faq-16.7| How do I put a command onto the command history without executing - it? -|faq-16.8| How do I increase the height of the command-line? + it? +|faq-16.8| How do I increase the height of the command-line? *faq-viminfo* -SECTION 17 - VIMINFO +SECTION 17 - VIMINFO ~ |faq-17.1| When I invoke Vim, I get error messages about illegal characters - in the viminfo file. What should I do to get rid of these - messages? + in the viminfo file. What should I do to get rid of these + messages? |faq-17.2| How do I disable the viminfo feature? -|faq-17.3| How do I save and use Vim marks across Vim sessions? +|faq-17.3| How do I save and use Vim marks/commands across Vim sessions? *faq-remote-editing* -SECTION 18 - REMOTE EDITING +SECTION 18 - REMOTE EDITING ~ |faq-18.1| How do I open a file with existing instance of gvim? What - happened to the Vim 5.x OpenWithVim.exe and SendToVim.exe files? + happened to the Vim 5.x OpenWithVim.exe and SendToVim.exe files? |faq-18.2| How do I send a command to a Vim server to write all buffers to - disk? + disk? |faq-18.3| Where can I get the documentation about the Vim remote server - functionality? + functionality? *faq-options* -SECTION 19 - OPTIONS +SECTION 19 - OPTIONS ~ |faq-19.1| How do I configure Vim in a simple way? |faq-19.2| How do I toggle the value of an option? |faq-19.3| How do I set an option that affects only the current - buffer/window? + buffer/window? |faq-19.4| How do I use space characters for a Vim option value? |faq-19.5| Can I add (embed) Vim option settings to the contents of a file? |faq-19.6| How do I display the line numbers of all the lines in a file? |faq-19.7| How do I change the width of the line numbers displayed using the - "number" option? + "number" option? |faq-19.8| How do I display (view) all the invisible characters like space, - tabs and newlines in a file? + tabs and newlines in a file? |faq-19.9| How do I configure Vim to always display the current line and - column number? + column number? |faq-19.10| How do I display the current Vim mode? |faq-19.11| How do I configure Vim to show pending/partial commands on the - status line? + status line? |faq-19.12| How do I configure the Vim status line to display different - settings/values? + settings/values? |faq-19.13| How do I configure Vim to display status line always? |faq-19.14| How do I make a Vim setting persistent across different Vim - invocations/instances/sessions? + invocations/instances/sessions? |faq-19.15| Why do I hear a beep (why does my window flash) about 1 second - after I hit the Escape key? + after I hit the Escape key? |faq-19.16| How do I make the 'c' and 's' commands display a '$' instead of - deleting the characters I'm changing? + deleting the characters I'm changing? |faq-19.17| How do I remove more than one flag using a single ":set" command - from a Vim option? + from a Vim option? *faq-mapping-keys* -SECTION 20 - MAPPING KEYS +SECTION 20 - MAPPING KEYS ~ |faq-20.1| How do I know what a key is mapped to? -|faq-20.2| How do list all the user-defined key mappings? +|faq-20.2| How do I list all the user-defined key mappings? |faq-20.3| How do I unmap a key? |faq-20.4| I am not able to create a mapping for the key. What is - wrong? -|faq-20.5| How do I map the numeric keypad keys? -|faq-20.6| How do I create a mapping that works only in visual mode? -|faq-20.7| In a Vim script, how do I know which keys to use for my mappings, - so that the mapped key will not collide with an already used key? -|faq-20.8| How do I map the escape key? -|faq-20.9| How do I map a key to perform nothing? -|faq-20.10| I want to use the Tab key to indent a block of text and - Shift-Tab key to unindent a block of text. How do I map the keys - to do this? This behavior is similar to textpad, visual studio, - etc. -|faq-20.11| In my mappings the special characters like are not - recognized. How can I configure Vim to recognize special - characters? -|faq-20.12| How do I use the '|' to separate multiple commands in a map? -|faq-20.13| If I have a mapping/abbreviation whose ending is the beginning of - another mapping/abbreviation, how do I keep the first from - expanding into the second one? -|faq-20.14| Why does it take a second or more for Vim to process a key, - sometimes when I press a key? -|faq-20.15| How do I map a key to run an external command using a visually - selected text? -|faq-20.16| How do I map the Ctrl-I key while still retaining the - functionality of the key? + wrong? +|faq-20.5| Why does mapping the key not work? +|faq-20.6| How do I map the numeric keypad keys? +|faq-20.7| How do I create a mapping that works only in visual mode? +|faq-20.8| How do I create a mapping that works only in normal and operator + pending mode (but not in visual mode)? +|faq-20.9| In a Vim script, how do I know which keys to use for my mappings, + so that the mapped key will not collide with an already used key? +|faq-20.10| How do I map the escape key? +|faq-20.11| How do I map a key to perform nothing? +|faq-20.12| I want to use the Tab key to indent a block of text and + Shift-Tab key to unindent a block of text. How do I map the keys + to do this? This behavior is similar to textpad, visual studio, + etc. +|faq-20.13| In my mappings the special characters like are not + recognized. How can I configure Vim to recognize special + characters? +|faq-20.14| How do I use the '|' to separate multiple commands in a map? +|faq-20.15| If I have a mapping/abbreviation whose ending is the beginning of + another mapping/abbreviation, how do I keep the first from + expanding into the second one? +|faq-20.16| Why does it take a second or more for Vim to process a key, + sometimes when I press a key? +|faq-20.17| How do I map a key to run an external command using a visually + selected text? +|faq-20.18| How do I map the Ctrl-I key while still retaining the + functionality of the key? +|faq-20.19| How do I define a map to accept a count? +|faq-20.20| How can I make my normal mode mapping work from within Insert + Mode? *faq-abbreviations* -SECTION 21 - ABBREVIATIONS -|faq-21.1| How do I auto correct misspelled words? +SECTION 21 - ABBREVIATIONS ~ +|faq-21.1| How do I auto correct misspelled words? |faq-21.2| How do I create multi-line abbreviations? |faq-21.3| When my abbreviations are expanded, an additional space character - is added at the end of the expanded text. How do I avoid this - character? + is added at the end of the expanded text. How do I avoid this + character? |faq-21.4| How do I insert the current date/time stamp into the file? |faq-21.5| How do I prevent an abbreviation from expanding in insert mode? *faq-record-and-playback* -SECTION 22 - RECORD AND PLAYBACK +SECTION 22 - RECORD AND PLAYBACK ~ |faq-22.1| How do I repeat an editing operation (insertion, deletion, paste, - etc)? + etc)? |faq-22.2| How I record and repeat a set of key sequences? |faq-22.3| How do I edit/modify a recorded set of key sequences? |faq-22.4| How do I write recorded key sequences to a file? |faq-22.5| I am using register 0 to record my key sequences (i.e. q0 .... - q). In the recorded key sequences, I am yanking some text. After - the first replay of the recorded key sequence, I am no longer - able to play it back. + q). In the recorded key sequences, I am yanking some text. After + the first replay of the recorded key sequence, I am no longer + able to play it back. *faq-autocommands* -SECTION 23 - AUTOCOMMANDS +SECTION 23 - AUTOCOMMANDS ~ |faq-23.1| How do I execute a command when I try to modify a read-only file? |faq-23.2| How do I execute a command every time when entering a buffer? |faq-23.3| How do I execute a command every time when entering a window? |faq-23.4| From an autocmd, how can I determine the name of the file or the - buffer number for which the autocommand is executed? + buffer number for which the autocommand is executed? |faq-23.5| How do I automatically save all the changed buffers whenever Vim - loses focus? + loses focus? |faq-23.6| How do I execute/run a function when Vim exits to do some - cleanup? + cleanup? *faq-syntax-highlight* -SECTION 24 - SYNTAX HIGHLIGHT +SECTION 24 - SYNTAX HIGHLIGHT ~ |faq-24.1| How do I turn off/on syntax highlighting? |faq-24.2| How do I change the background and foreground colors used by Vim? |faq-24.3| How do I change the highlight colors to suit a dark/light - background? + background? |faq-24.4| How do I change the color of the line numbers displayed when the - ":set number" command is used? + ":set number" command is used? |faq-24.5| How do I change the background color used for a Visually selected - block? + block? |faq-24.6| How do I highlight the special characters (tabs, trailing spaces, - end of line, etc) displayed by the 'list' option? + end of line, etc) displayed by the 'list' option? |faq-24.7| How do I specify a colorscheme in my .vimrc/.gvimrc file, so that - Vim uses the specified colorscheme everytime? + Vim uses the specified colorscheme every time? |faq-24.8| Vim syntax highlighting is broken. When I am editing a file, some - parts of the file is not syntax highlighted or syntax highlighted - incorrectly. + parts of the file is not syntax highlighted or syntax highlighted + incorrectly. |faq-24.9| Is there a built-in function to syntax-highlight the - corresponding matching bracket? + corresponding matching bracket? |faq-24.10| How do I turn off the C comment syntax highlighting? |faq-24.11| How do I add my own syntax extensions to the standard syntax - files supplied with Vim? + files supplied with Vim? |faq-24.12| How do I replace a standard syntax file that comes with the Vim - distribution with my own syntax file? + distribution with my own syntax file? |faq-24.13| How do I highlight all the characters after a particular column? |faq-24.14| How do I convert a source file (.c, .h, etc) with the Vim syntax - highlighting into a HTML file? + highlighting into a HTML file? |faq-24.15| How do I list the definition of all the current highlight - groups? + groups? +|faq-24.16| How can I embed one syntax highlighting language into another + one? *faq-vim-script-writing* -SECTION 25 - VIM SCRIPT WRITING +SECTION 25 - VIM SCRIPT WRITING ~ |faq-25.1| How do I list the names of all the scripts sourced by Vim? |faq-25.2| How do I debug Vim scripts? |faq-25.3| How do I locate the script/plugin which sets a Vim option? |faq-25.4| I am getting some error/informational messages from Vim (possibly - when running a script), the messages are cleared immediately. How - do I display the messages again? + when running a script), the messages are cleared immediately. How + do I display the messages again? |faq-25.5| How do I save and restore a plugin specific information across - Vim invocations? + Vim invocations? |faq-25.6| How do I start insert mode from a Vim function? |faq-25.7| How do I change the cursor position from within a Vim function? |faq-25.8| How do I check the value of an environment variable in the .vimrc - file? + file? |faq-25.9| How do I check whether an environment variable is set or not from - a Vim function? + a Vim function? |faq-25.10| How do I call/use the Vim built-in functions? |faq-25.11| I am using some normal mode commands in my Vim script. How do I - avoid using the user-defined mappings for these normal mode - commands and use the standard Vim functionality for these normal - mode commands? + avoid using the user-defined mappings for these normal mode + commands and use the standard Vim functionality for these normal + mode commands? |faq-25.12| How do I get a visually selected text into a Vim variable or - register? + register? |faq-25.13| I have some text in a Vim variable 'myvar'. I would like to use - this variable in a ":s" substitute command to replace a text - 'mytext'. How do I do this? + this variable in a ":s" substitute command to replace a text + 'mytext'. How do I do this? |faq-25.14| A Vim variable (bno) contains a buffer number. How do I use this - variable to open the corresponding buffer? + variable to open the corresponding buffer? |faq-25.15| How do I store the value of a Vim option into a Vim variable? |faq-25.16| I have copied and inserted some text into a buffer from a Vim - function. How do I indent the inserted text from the Vim - function? + function. How do I indent the inserted text from the Vim + function? |faq-25.17| How do I get the character under the cursor from a Vim script? |faq-25.18| How do I get the name of the current file without the extension? |faq-25.19| How do I get the basename of the current file? |faq-25.20| How do I get the output from a Vim function into the current - buffer? + buffer? |faq-25.21| How do I call external programs from a Vim function? |faq-25.22| How do I get the return status of a program executed using the - ":!" command? + ":!" command? |faq-25.23| How do I determine whether the current buffer is modified or - not? + not? |faq-25.24| I would like to use the carriage return character in a normal - command from a Vim script. How do I specify the carriage return - character? + command from a Vim script. How do I specify the carriage return + character? |faq-25.25| How do I split long lines in a Vim script? -|faq-25.26| When I try to "execute" my function using the "execute 'echo - Myfunc()'" command, the cursor is moved to the top of the - current buffer. Why? +|faq-25.26| When I try to "execute" my function using the "execute Myfunc()" + command, the cursor is moved to the top of the current buffer. + Why? |faq-25.27| How do I source/execute the contents of a register? |faq-25.28| After calling a Vim function or a mapping, when I press the 'u' - key to undo the last change, Vim undoes all the changes made by - the mapping/function. Why? + key to undo the last change, Vim undoes all the changes made by + the mapping/function. Why? |faq-25.29| How can I call a function defined with s: (script local - function) from another script/plugin? -|faq-25.30| Is it possible to un-source a sourced script? In otherwords, - reverse all the commands executed by sourcing a script. + function) from another script/plugin? +|faq-25.30| Is it possible to un-source a sourced script? In other words, + reverse all the commands executed by sourcing a script. *faq-plugins* -SECTION 26 - PLUGINS +SECTION 26 - PLUGINS ~ |faq-26.1| How do I set different options for different types of files? |faq-26.2| I have downloaded a Vim plugin or a syntax file or a indent file, - or a color scheme or a filetype plugin from the web. Where should - I copy these files so that Vim will find them? + or a color scheme or a filetype plugin from the web. Where should + I copy these files so that Vim will find them? |faq-26.3| How do I extend an existing filetype plugin? |faq-26.4| How do I turn off loading the Vim plugins? |faq-26.5| How do I turn on/off loading the filetype plugins? |faq-26.6| How do I override settings made in a file type plugin in the - global ftplugin directory for all the file types? + global ftplugin directory for all the file types? |faq-26.7| How do I disable the Vim directory browser plugin? |faq-26.8| How do I set the filetype option for files with names matching a - particular pattern or depending on the file extension? + particular pattern or depending on the file extension? *faq-editing-program-files* -SECTION 27 - EDITING PROGRAM FILES +SECTION 27 - EDITING PROGRAM FILES ~ |faq-27.1| How do I enable automatic indentation for C/C++ files? |faq-27.2| How do I configure the indentation used for C/C++ files? |faq-27.3| How do I turn off the automatic indentation feature? |faq-27.4| How do I change the number of space characters used for the - automatic indentation? + automatic indentation? |faq-27.5| I am editing a C program using Vim. How do I display the - definition of a macro or a variable? + definition of a macro or a variable? |faq-27.6| I am editing a C program using Vim. How do I jump to the - beginning or end of a code block from within the block? -|faq-27.7| Is there a way to turn off the "//" comment auto-insertion - behavior for C++ files? If I'm sitting on a line beginning with - "//", then I open a new line above or below it, Vim automatically - inserts new "//" chars. + beginning or end of a code block from within the block? +|faq-27.7| When editing C++ files and when inserting new lines above or + below a comment (//) line, Vim automatically inserts the C++ + comment character (//) at the beginning of the line. How do I + disable this? |faq-27.8| How do I add the comment character '#' to a set of lines at the - beginning of each line? + beginning of each line? |faq-27.9| How do I edit a header file with the same name as the - corresponding C source file? + corresponding C source file? |faq-27.10| How do I automatically insert comment leaders while typing - comments? + comments? *faq-quickfix* -SECTION 28 - QUICKFIX +SECTION 28 - QUICKFIX ~ |faq-28.1| How do I build programs from Vim? |faq-28.2| When I run the make command in Vim I get the errors listed as the - compiler compiles the program. When it finishes this list - disappears and I have to use the :clist command to see the error - message again. Is there any other way to see these error - messages? + compiler compiles the program. When it finishes this list + disappears and I have to use the :clist command to see the error + message again. Is there any other way to see these error + messages? +|faq-28.3| How can I perform a command for each item in the + quickfix/location list? *faq-folding* -SECTION 29 - FOLDING +SECTION 29 - FOLDING ~ |faq-29.1| How do I extend the Vim folding support? |faq-29.2| When I enable folding by setting the 'foldmethod' option, all the - folds are closed. How do I prevent this? + folds are closed. How do I prevent this? |faq-29.3| How do I control how many folds will be opened when I start - editing a file? + editing a file? |faq-29.4| How do I open and close folds using the mouse? |faq-29.5| How do I change the text displayed for a closed fold? |faq-29.6| How do I store and restore manually created folds across - different Vim invocations? + different Vim invocations? +|faq-29.7| I have enabled syntax based folding. Why is Vim so slow? + *faq-vim-with-external-applications* -SECTION 30 - VIM WITH EXTERNAL APPLICATIONS +SECTION 30 - VIM WITH EXTERNAL APPLICATIONS ~ |faq-30.1| Can I run a shell inside a Vim window? |faq-30.2| How do I pass the word under the cursor to an external command? |faq-30.3| How do I get the output of a shell command into a Vim buffer? |faq-30.4| How do I pipe the contents of the current buffer to an external - command and replace the contents of the buffer with the output - from the command? + command and replace the contents of the buffer with the output + from the command? |faq-30.5| How do I sort a section of my file? -|faq-30.6| Is there a step-by-step guide for using Vim with slrn? -|faq-30.7| How do I use Vim as a pager? -|faq-30.8| How do I view Unix man pages from inside Vim? -|faq-30.9| How do I change the diff command used by the Vim diff support? -|faq-30.10| How do I use the Vim diff mode without folding? +|faq-30.6| How do I use Vim as a pager? +|faq-30.7| How do I view Unix man pages from inside Vim? +|faq-30.8| How do I change the diff command used by the Vim diff support? +|faq-30.9| How do I use the Vim diff mode without folding? *faq-gui-vim* -SECTION 31 - GUI VIM +SECTION 31 - GUI VIM ~ |faq-31.1| How do I create buffer specific menus? |faq-31.2| How do I change the font used by GUI Vim? |faq-31.3| When starting GUI Vim, how do I specify the location of the GVIM - window? + window? |faq-31.4| How do I add a horizontal scrollbar in GVim? |faq-31.5| How do I make the scrollbar appear in the left side by default? |faq-31.6| How do I remove the Vim menubar? |faq-31.7| I am using GUI Vim. When I press the ALT key and a letter, the - menu starting with that letter is selected. I don't want this - behavior as I want to map the ALT- combination. How do I do - this? + menu starting with that letter is selected. I don't want this + behavior as I want to map the ALT- combination. How do I do + this? |faq-31.8| Is it possible to scroll the text by dragging the scrollbar so - that the cursor stays in the original location? + that the cursor stays in the original location? |faq-31.9| How do I get gvim to start browsing files in a particular - directory when using the ":browse" command? + directory when using the ":browse" command? |faq-31.10| For some questions, like when a file is changed outside of Vim, - Vim displays a GUI dialog box. How do I replace this GUI dialog - box with a console dialog box? + Vim displays a GUI dialog box. How do I replace this GUI dialog + box with a console dialog box? |faq-31.11| I am trying to use GUI Vim as the editor for my xxx application. - When the xxx application launches GUI Vim to edit a file, the - control immediately returns to the xxx application. How do I - start GUI Vim, so that the control returns to the xxx - application only after I quit Vim? + When the xxx application launches GUI Vim to edit a file, the + control immediately returns to the xxx application. How do I + start GUI Vim, so that the control returns to the xxx + application only after I quit Vim? |faq-31.12| Why does the "Select Font" dialog doesn't show all the fonts - installed in my system? + installed in my system? |faq-31.13| How do I use the mouse in Vim command-line mode? |faq-31.14| When I use the middle mouse button to scroll text, it pastes the - last copied text. How do I disable this behavior? + last copied text. How do I disable this behavior? |faq-31.15| How do I change the location and size of a GUI Vim window? +|faq-31.16| When splitting the Vim window vertically, Vim changes + the position. *faq-vim-on-unix* -SECTION 32 - VIM ON UNIX +SECTION 32 - VIM ON UNIX ~ |faq-32.1| I am running Vim in a xterm. When I press the CTRL-S key, Vim - freezes. What should I do now? + freezes. What should I do now? |faq-32.2| I am seeing weird screen update problems in Vim. What can I do to - solve this screen/display update problems? + solve this screen/display update problems? |faq-32.3| I am using the terminal/console version of Vim. In insertmode, - When I press the backspace key, the character before the cursor - is not erased. How do I configure Vim to do this? + When I press the backspace key, the character before the cursor + is not erased. How do I configure Vim to do this? |faq-32.4| I am using Vim in a xterm. When I quit Vim, the screen contents - are restored back to the original contents. How do I disable - this? + are restored back to the original contents. How do I disable + this? |faq-32.5| When I start Vim, it takes quite a few seconds to start. How do I - minimize the startup time? + minimize the startup time? |faq-32.6| How can I make the cursor in gvim in unix stop blinking? |faq-32.7| How do I change the menu font on GTK Vim? |faq-32.8| How do I prevent from suspending Vim? |faq-32.9| When I kill the xterm running Vim, the Vim process continues to - run and takes up a lot of CPU (99%) time. Why is this happening? + run and takes up a lot of CPU (99%) time. Why is this happening? |faq-32.10| How do I get the Vim syntax highlighting to work in a Unix - terminal? + terminal? *faq-vim-on-ms-windows* -SECTION 33 - VIM ON MS-WINDOWS +SECTION 33 - VIM ON MS-WINDOWS ~ |faq-33.1| In MS-Windows, CTRL-V doesn't start the blockwise visual mode. - What happened? + What happened? |faq-33.2| When I press the CTRL-Y key, it acts like the CTRL-R key. How do - I configure Vim to treat CTRL-Y as CTRL-Y? + I configure Vim to treat CTRL-Y as CTRL-Y? |faq-33.3| How do I start GUI Vim in a maximized window always? |faq-33.4| After doing some editing operations, Vim freezes. The cursor - becomes an empty rectangle. I am not able enter any characters. - What is happening? + becomes an empty rectangle. I am not able enter any characters. + What is happening? |faq-33.5| I am using Windows XP, the display speed of maximized GVim is - very slow. What can I do to speed the display updates? + very slow. What can I do to speed the display updates? |faq-33.6| What are the recommended settings for using Vim with cygwin? |faq-33.7| I am trying to use GNU diff with Vim diff mode. When I run the - diff from command line, it works. When I try to use the diff with - Vim it doesn't work. What should I do now? + diff from command line, it works. When I try to use the diff with + Vim it doesn't work. What should I do now? |faq-33.8| Is it possible to use Vim as an external editor for MS-Windows - Outlook email client? + Outlook email client? |faq-33.9| I am using Vim to edit HTML files. How do I start internet - explorer with the current file to preview the HTML file? + explorer with the current file to preview the HTML file? |faq-33.10| I would like to use Vim with Microsoft Visual Studio. How do I - do this? + do this? |faq-33.11| Where do I place the _vimrc and _gvimrc files? -|faq-33.12| Everytime I save a file, Vim warns about the file being changed - outside of Vim. Why? +|faq-33.12| Every time I save a file, Vim warns about the file being changed + outside of Vim. Why? *faq-printing* -SECTION 34 - PRINTING +SECTION 34 - PRINTING ~ |faq-34.1| How do I print a file along with line numbers for all the lines? |faq-34.2| How do I print a file with the Vim syntax highlighting colors? *faq-building-vim-from-source* -SECTION 35 - BUILDING VIM FROM SOURCE +SECTION 35 - BUILDING VIM FROM SOURCE ~ |faq-35.1| How do I build Vim from the sources on a Unix system? |faq-35.2| How do I install Vim in my home directory or a directory other - than the default installation directory in Unix? + than the default installation directory in Unix? |faq-35.3| How do I build Vim from the sources on a MS-Windows system? |faq-35.4| The Vim help, syntax, indent files are missing from my Vim - installation. How do I install these files? + installation. How do I install these files? |faq-35.5| I have built Vim from the source and installed the Vim package - using "make install". Do I need to keep the Vim source directory? + using "make install". Do I need to keep the Vim source directory? |faq-35.6| How do I determine the Vim features which are enabled at compile - time? + time? |faq-35.7| Can I build Vim without the GUI support? |faq-35.8| When building Vim on a Unix system, I am getting "undefined - reference to term_set_winsize' error. How do I resolve this - error? + reference to term_set_winsize" error. How do I resolve this + error? |faq-35.9| Vim configure keeps complaining about the lack of gtk-config - while trying to use GTK 2.03. This is correct, since in GTK 2 - they moved to using the generic pkg-config. I can get pkg-config - to list the various includes and libs for gtk, but for some - reason the configure script still isn't picking this up. + while trying to use GTK 2.03. This is correct, since in GTK 2 + they moved to using the generic pkg-config. I can get pkg-config + to list the various includes and libs for gtk, but for some + reason the configure script still isn't picking this up. +|faq-35.10| I did successfully download the sources and compiled Vim on + Unix. But feature ... still does not work. What is wrong and + how can I fix it? *faq-various* -SECTION 36 - VARIOUS +SECTION 36 - VARIOUS ~ |faq-36.1| How do I edit binary files with Vim? |faq-36.2| How do I disable the visual error flash and the error beep? |faq-36.3| How do I display the ascii value of a character displayed in a - buffer? + buffer? |faq-36.4| Can I use zero as a count for a Vim command? |faq-36.5| How do I disable the Vim welcome screen? |faq-36.6| How do I avoid the "hit enter to continue" prompt? |faq-36.7| How do I invoke Vim from command line to run a group of commands - on a group of files? + on a group of files? |faq-36.8| How do I use a normal mode command from insert mode without - leaving the insert mode? + leaving the insert mode? +|faq-36.9| How do I start Vim in insert mode? +|faq-36.10| How do I use Copy and Paste with Vim? +|faq-36.11| Why shouldn't I modify the files in the system runtime + directory? *faq-unicode* -SECTION 37 - UNICODE +SECTION 37 - UNICODE ~ |faq-37.1| Is it possible to create Unicode files using Vim? |faq-37.2| Which Vim settings are particularly important for editing Unicode - files? + files? |faq-37.3| What is the 'encoding' option? |faq-37.4| How does Vim name the various Unicode encodings? |faq-37.5| How does Vim specify the presence or absence of a byte-order - mark? + mark? |faq-37.6| What is the 'fileencoding' option? |faq-37.7| What is the 'fileencodings' option? |faq-37.8| What is the 'termencoding' option? |faq-37.9| What is the 'bomb' option? |faq-37.10| Where can I find an example of a typical use of all these - options? + options? |faq-37.11| How can I insert Unicode characters into a file using Vim? |faq-37.12| How can I know which digraphs are defined and for which - characters? + characters? ============================================================================= *faq-1* -SECTION 1 - GENERAL INFORMATION +SECTION 1 - GENERAL INFORMATION ~ *faq-1.1* 1.1. What is Vim? @@ -745,35 +774,33 @@ advantage that you can keep your fingers on the keyboard and your eyes on the screen. For those who want it, there is mouse support and a GUI version with scrollbars and menus. -Vim is an editor, not a word processor. A word processor is used mainly to -do layout of text. This means positioning it, changing the way it appears -on output. More often than not, the final document is meant to be printed -or typeset or what have you, in order to present it in a pleasing manner to -others. Examples of word processors are Microsoft Word, WordPerfect, -FrameMaker, and AmiPro. +Vim is an editor, not a word processor. A word processor is used mainly +to do layout of text. This means positioning it, changing the way it +appears on output. More often than not, the final document is meant to +be printed or typeset or what have you, in order to present it in a +pleasing manner to others. Examples of word processors are Microsoft +Word, FrameMaker, and OpenOffice Writer. An editor is simply for entering text. Any typesetting or laying out of the document is secondary. With an editor, one's main concern is entering text, not making the text look good. Examples of editors other than Vim and Vi -are Emacs, Crisp, Brief, and xedit. And Notepad. +are Emacs, TextMate, Ultraedit and gedit. And Notepad. -For more information, read > +For more information, read: + + |intro| - :help intro -< *faq-1.2* 1.2. Who wrote Vim? -Most of Vim was written by Bram Moolenar, with contributions from too many -people to mention here. See ":h credits" for a complete list. +Most of Vim is based on Stevie and was written by Bram Moolenaar, with +contributions from too many people to mention here. -Vim is based on Stevie, worked on by Tim Thompson, Tony Andrews and G.R. -(Fred) Walter. +For more information, read: -For more information, read > + |author| + |credits| - :help author -< *faq-1.3* 1.3. Is Vim compatible with Vi? @@ -790,12 +817,18 @@ You can also set the 'compatible' option to enable Vi compatibility: > :set compatible < -For more information, read > +If you want to make sure, to start Vim in a 'nocompatible' mode to +original Vi, supply the -N command line argument: > - :help -C - :help 'compatible' - :help compatible-default + $ vim -N < +For more information, read: + + |-C| + |-N| + |'compatible'| + |compatible-default| + *faq-1.4* 1.4. What are some of the improvements of Vim over Vi? @@ -804,112 +837,223 @@ list shows that Vim is a thoroughly modern and feature-packed editor. Standard features of modern editors are implemented, and there is an equal emphasis on general power-user features and features for programmers. -Features to modernise Vi: +Features to modernise Vi: ~ + + Multi-level undo ~ - Multi-level undo Allows you to set the number of times you can undo your changes in a file buffer. You can also redo an undone change. - Multiple windows and buffers + Also starting with version 7.3 Vim can permanently store your undo + information, so that you can undo your changes which you have done + in a previous editing session. + + Tabs, Multiple windows and buffers ~ + Each file can be displayed in its own window. You can move easily from one window to another. Each file opened during a Vim session also has an associated buffer and you can easily jump from one to the other. - Flexible insert mode + Also like any modern GUI, Vim supports opening several files in tabs. + You can do batch processing for tabs, buffers, windows and the + argumentlist. + + Flexible insert mode ~ + Vim allows you to use the arrow keys while in insert mode to move around in the file. No more hitting , moving around, then hitting `i' or `a'. - Macros + + Macros ~ + Vim has a facility which allows you to record a sequence of typed characters and repeat them any number of times. - Visual mode + + Visual mode ~ + You can highlight sections of text and execute operations on this section of text only. - Block operators + + Block operators ~ + Allow selection and highlighting of rectangular blocks of text in order do execute specific operations on them. - Online help system + + Online help system ~ + You can easily find help on any aspect of using Vim. Help is displayed in its own window. - Command-line editing and history + + Command-line editing and history ~ + History allows you to use the arrow keys to repeat or search for a command that has already been typed. Allows you to match the beginning of a command with the beginning of another similar command in the history buffer. You can also edit a command to correct typos or change a few values. - Command line completion. + + Command line completion. ~ + Using the key, you can complete commands, options, filenames, etc. as needed. - Horizontal scrolling. + + Horizontal scrolling. ~ + Long lines can be scrolled horizontally (with or without the GUI). -Advanced user features: + Unicode and internationalization improvements. ~ + + Vim is able to edit files in unicode encoding and uses internally an + utf-8 encoding. Additionally Vim can display text right to left + oriented. + +Advanced user features: ~ + + Text formatting ~ - Text formatting. With two keystrokes, you can format large sections of text, without the use of external programs. - Word completion in Insert mode - Vim can complete words while you are typing, by matching the current - word with other similar words in the file. - Jump tags + + Completion in Insert mode ~ + + Vim provides several different possibilities to complete your text. + For example Vim can complete words while you are typing, by matching + the current word with other similar words in the file. + + Jump tags ~ + Just like in an internet browser, you can jump back to previous parts of the text you were editing, and then forward again. Your brain is thus free to edit instead of navigate. - Automatic commands + + Automatic commands ~ + Commands automatically executed when reading or writing a file, jumping to another buffer, etc. - Viminfo + + Viminfo ~ + Allows storing of the command line history, marks and registers in a file to be read on startup. Therefore, you can recall old search patterns, macros, etc., in a new Vim session. - Mouse support + + Mouse support ~ + The mouse is supported in an xterm and for MS-DOS. It can be used to position the cursor, select the visual area, paste a register, etc. - Graphical User Interface (GUI) - Just like any modern editor. Also, it's very easy to add your own - menus. Of course, console vim is still supported, and very widely - used. - Scripting language + + Graphical User Interface (GUI) ~ + + There are several different graphical user interfaces available. + Also, it's very easy to add your own menus. Of course, console vim is + still supported, and very widely used. + + Scripting language ~ + Vim has a powerful scripting language so new commands can be created. - You can also use Perl, Python, TCL and Ruby to achieve the same thing! - Plugins + You can also use Perl, Python, TCL, Lua and Ruby to achieve the same + thing! + + Plugins ~ + Extra functionality implemented via vim commands (regular commands or the scripting language) that is automatically loaded on startup. - Examples: file explorer, network editing. More are being developed - and shared on VimOnline all the time. - Syntax highlighting for many programming languages - Syntax highlighting for hundreds of programming languages is - supported. Support for others can be added. - Extended regular expressions + Examples: file explorer, network editing, enhanced autocompletion, + syntax checks. + More are being developed and shared on VimOnline all the time. + + Syntax highlighting for many programming languages ~ + + Syntax highlighting (including concealing items) for hundreds of + programming languages is supported. Support for others can be + added. + + Extended regular expressions ~ + Vim supports extended regular expressions which are similar in - functionality to that of perl regular expressions. + functionality to that of Perl regular expressions. + + Integrated Spell checking ~ + + Spell checking has been integrated into Vim. + + Diff mode ~ + + Vim can highlight the differences between two, three or four files. + Identical lines will be folded away and hidden. + + Encryption using the blowfish algorithm ~ + + Vim allows to encrypt your files using the symmetric block cipher + blowfish as well as the swap file. + + Extensive customizable ~ -Programming performance features: + Vim can be tuned and customized to work like you want by setting + options. You can define your own commands, macros and even plugins + to extend its capabilities + + Packages ~ + + Packages have been added to keep the installation of the growing + number of plugins manageable. This is a convenient way to get one + or more plugins, drop them in a directory and keep them updated. + Vim will load them automatically, or only when desired. + +Programming performance features: ~ + + Edit-compile-edit speedup ~ - Edit-compile-edit speedup You can compile within Vim and automatically jump to the location of errors in the source code. - Indenting for many programming languages + + Indenting for many programming languages ~ + C, C++, Java, Perl, XML and many other languages can be automatically indented by vim while you type. Support for others can be added. - Searching for words in include files + + Searching for words in include files ~ + Vim allows you to search for a match of the word under the cursor in the current and included files. - Advance text objects - Instantly select, or delete, or copy, or indent, or format, or change - case, or ... to all the text between ( and ), or { and }, or < and >, - or [ and ]. Or a word, sentence, or paragraph. Very powerful. - Folding + + Advanced text objects ~ + + Instantly select, delete, copy, indent, format, change case, or ... + to all the text between ( and ), or { and }, or < and >, or [ and + ]. Or a word, sentence, or paragraph. Very powerful. + + Folding ~ + Certain parts of the text can be "folded" away. The best example is the body of a function. You can get an overview of the code, and then open the fold of the function whose detail you need to see. - ctags and cscope integration + + ctags and cscope integration ~ + Using these two powerful programs, you can jump to a definition of a function from a calling instance of it, and use other tricks to navigate source code. -For more information, read > + Integration of several programming languages ~ + + If you find the internal scripting language not powerful enough, you + can extend Vim using Lua, Ruby, Tcl, Perl and Python 2 and 3. + + Asynchronous I/O support ~ + + Vim uses jobs and channels to talk to other programs + asynchronously. This allows to have e.g. a compiler run in the + background and open the quickfix list as soon as it is finished to + fix warnings and errors. + + Timers ~ + + Timers are asynchronous and can fire once or repeatedly to invoke a + function to do any work. + +For more information, read: ~ + + |vi-differences| - :help vi-differences -< *faq-1.5* 1.5. Is Vim free? @@ -917,14 +1061,13 @@ Vim is Charityware. There are no restrictions on using or copying Vim, but the author encourages you to make a donation to charity. A document explaining how to do so is included in the distribution. -For more information, read > +For more information, read: - :help copyright -< + |copyright| ============================================================================= *faq-2* -SECTION 2 - RESOURCES +SECTION 2 - RESOURCES ~ *faq-2.1* 2.1. Where can I learn more about Vim? @@ -936,45 +1079,55 @@ newsgroup to post to is comp.editors. "VimOnline" is a web page that serves as a de facto homepage for vim, although the main purpose of it is to gather tips and scripts from -everywhere. Get involved! The URL is vim.sourceforge.net or vim.sf.net. +everywhere. Get involved! The URL is https://www.vim.org -Finally, read the Vi FAQ: > +Finally, read the Vi FAQ: http://www.faqs.org/faqs/editor-faq/vi/part1/index.html -< -For more information, read > - :help mail-list - :help internet -< +Finally, there are also some communities, where you can discuss features +or ask questions: + + https://vi.stackexchange.com + https://vim.reddit.com + +For more information, read: + + |mail-list| + |internet| + *faq-2.2* 2.2. Is there a mailing list available? -There are several: > +There are several: - NAME DESCRIPTION -< + NAME DESCRIPTION ~ + ---------------- --------------------------------------------- ~ vim-announce Announcements of new releases vim General discussion vim-dev Patches, bug reports, development discussions vim-mac Macintosh discussion vim-fr General discussion in French - vim-multibyte Multibyte development issues - vim-vms Development on VMS -Of these, only vim and vim-dev are of general interest. vim-announce is +Of these, only vim and vim-dev are of general interest. vim-announce is read-only to most people, and its messages are sent to the other lists as -well. The remaining four are very low volume. +well. The remaining four are very low volume. + + ACTION EMAIL SEND TO ~ + ---------------- -------------------------- ~ + To subscribe: -subscribe@vim.org + To unsubscribe: -unsubscribe@vim.org + To get help: -help@vim.org + +The available mailing lists are also mentioned here: -To subscribe: send an email to -subscribe@vim.org -To unsubscribe: send an email to -unsubscribe@vim.org -To get help: send an email to -help@vim.org + https://www.vim.org/maillist.php *faq-2.3* 2.3. Is there an archive available for the Vim mailing lists? -Yes. Visit http://www.yahoogroups.com/list/, where name is one of: -vimannounce, vim, vimdev, vim-fr, vim-mac, vim-multibyte, vim-vms. +Yes. Visit https://groups.yahoo.com/, where name is one of: +vimannounce, vim, vimdev, vim-fr, vim-mac, vim-vms. Alternatively, visit www.gmane.org to find out about GMANE, which allows you to access the mailing lists as though they were newsgroups. This @@ -984,44 +1137,100 @@ observe the current threads. *faq-2.4* 2.4. Where can I get the Vim user manual in HTML/PDF/PS format? -You can download the HTML/PDF/PS format of the Vim user manual from: > +You can download the HTML/PDF/PS format of the Vim user manual from: - http://vimdoc.sourceforge.net/ -< - *faq-2.5* -2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a - problem with my setup or with Vim? + https://vimdoc.sourceforge.net/ -First, you have to determine that the problem is not with your .vimrc or -.gvimrc or system vimrc or your personal plugin files or in any of your -setup files. To do this, use > +Note, the user manual from that page is currently pretty outdated. It's +best to either use the documentation that comes with vim or use the +online version at https://vimhelp.appspot.com - $ vim -N -u NONE -U NONE -< -This will start Vim in 'nocompatible" mode and will not source your -personal .vimrc and .gvimrc files. It will also not load your personal -plugins. In this invocation of Vim, try to reproduce your problem. If you -are not able to reproduce the problem, then the problem is related to some -setting in one of your local setup files or plugins. To locate the problem -in your setup files, you have to use trial and error and try commenting out -the lines in your setup files one by one. You can also use the -V command -line argument to Vim to get more debug information and analyze the problem: > +You can find a pdf version of the full English help, including this faq +(in letter, A4 and Ipad format) at: + + https://nathangrigg.com/vimhelp/ - $ vim -V2 +This document is cross-referenced, so you can use the hyperlink +functionality. + + *faq-2.5* +2.5. I have a "xyz" (some) problem with Vim. How do I determine if it is a + problem with my setup or with Vim? / Have I found a bug in Vim? + +First, you need to find out, whether the error is in the actual runtime +files or any plugin that is distributed with Vim or whether it is a +simple side effect of any configuration option from your .vimrc or +.gvimrc. So first, start vim like this: > + + vim -u NONE -U NONE -N -i NONE +< +This starts Vim in nocompatible mode (-N), without reading your viminfo +file (-i NONE), without reading any configuration file (-u NONE for not +reading .vimrc file and -U NONE for not reading a .gvimrc file) or even +plugin. + +In this invocation, try to reproduce your problem. If the error +persists, the chance is good you've found a bug in Vim (see also +Question 2.6. |faq-2.6|) + +If the error does not occur when starting Vim this way, then the problem +is either related to some plugin of yours or some setting in one of your +local setup files. You need to find out, what triggers the error, you +try starting Vim this way: > + + vim -u NONE -U NONE -N +< +If the error occurs, the problem is your .viminfo file. Simply delete +the viminfo file then. If the error does not occur, try: > + + vim -u ~/.vimrc --noplugin -N -i NONE +< +This will simply use your .vimrc as configuration file, but not load any +plugins. If the error occurs this time, the error is possibly caused by +some configuration option inside your .vimrc file. Depending on the +length of your vimrc file, it can be quite hard to trace the origin +within that file. + +The best way is to add :finish command in the middle of your .vimrc. +Then restart again using the same command line. If the error still +occurs, the bug must be caused because of a setting in the first half of +your .vimrc. If it doesn't happen, the problematic setting must be in +the second half of your .vimrc. So move the :finish command to the +middle of that half, of which you know that triggers the error and move +your way along, until you find the problematic option. If your .vimrc is +350 lines long, you need at a maximum 9 tries to find the offending line +(in practise, this can often be further reduced, since often lines +depend on each other). + +If the problem does not occur, when only loading your .vimrc file, the +error must be caused by a plugin or another runtime file (indent +autoload or syntax script). Check the output of the :scriptnames command +to see what files have been loaded and for each one try to disable each +one by one and see which one triggers the bug. Often files that are +loaded by vim, have a simple configuration variable to disable them, but +you need to check inside each file separately. + +You can also use the -V command line argument to get more debug +information to analyze the problem: > + + $ vim -V2logfile < You can increase the value passed to the -V argument to get more debug -information. +information. By also specifying a logfile name, this makes sure, the +debug messages don't appear on the screen and won't disturb you when +trying to reproduce the problem. -For more information, read > - :help -u - :help -U - :help -N - :help -V - :help 'verbose' - :help :verbose - :help set-verbose -< +For more information, read: + + |-u| + |-U| + |-N| + |-V| + |'verbose'| + |:verbose| + |:set-verbose| + *faq-2.6* 2.6. Where can I report bugs? @@ -1030,36 +1239,47 @@ First collect the required information using the following command: > :source $VIMRUNTIME/bugreport.vim < Now send the resulting text from the above command to the bugs@vim.org -e-mail address. +e-mail address. There is also a public bug tracker available at +https://github.com/vim/vim/issues. A copy of each message there +will be forwarded to the Vim Development list. -The Vim Development mailing list (see above) is a good place to discuss -general bugs. If the bug you find is with syntax highlighting or some -other "added feature" (i.e. not directly programmed into vim), attempt to -inform the maintainer of that feature. +The Vim Development mailing list (see Question 2.2 |faq-2.2|) is a good place to +discuss general bugs. If the bug you find is with syntax highlighting, +a runtime file, or some other "added feature" (i.e. not directly +programmed into vim), attempt to inform the maintainer of that feature. +His e-mail address will be mentioned at the top of the corresponding +runtime file. -For more information, read > +For more information, read: + + |bug-reports| - :help bug-reports -< *faq-2.7* 2.7. Where can the FAQ be found? -The FAQ can be found at VimOnline (vim.sf.net). Other places will be -decided in the future. +The FAQ can be found at https://vimhelp.appspot.com/vim_faq.txt.html. +It will be auto-generated from the source that is managed in the github +repository https://www.github.com/chrisbra/vim_faq (Patches are welcome). + +The repository also includes the faq in different formats, e.g. manpage, +pdf file, html file, plain text version and a version in vim help format. + +A slightly older version (which doesn't seem to get updated anymore) can +still be found at VimOnline (https://www.vim.org/). *faq-2.8* 2.8. What if I don't find an answer in this FAQ? This FAQ covers mainly Vim-specific questions. You may find more information suitable for most Vi clones by reading the Vi FAQ. It is posted -regularly on comp.editors. You can also find a copy at > +regularly on comp.editors. You can also find a copy at http://www.faqs.org/faqs/editor-faq/vi/part1/index.html -< + Also, since Vim has gathered so many features in the last few years, successfully documenting the frequently asked questions here is a -near-impossible task. To make it possible, please email the maintainer if -you have a good question. A good question is one that you've tried to +near-impossible task. To make it possible, please email the maintainer if +you have a good question. A good question is one that you've tried to answer yourself (remember, Vim has great documentation) but struggled. *faq-2.9* @@ -1069,64 +1289,103 @@ answer yourself (remember, Vim has great documentation) but struggled. You can send your patches to the Vim developer mailing list vim-dev@vim.org. -For more information, read > +For more information, read: + + |vim-dev| - :help vim-dev -< *faq-2.10* -2.10. I have a Vim tip or developed a new Vim - syntax/indent/filetype/compiler plugin or developed a new script or a - colorscheme. Is there a public website where I can upload this? +2.10. I have a Vim tip or developed a new Vim syntax/indent/filetype/ + compiler plugin or developed a new script or a colorscheme. + Is there a public website where I can upload this? Yes. You can use the Vim Online website to upload your plugins/scripts, -colorschemes, tips, etc. The site is at http://vim.sourceforge.net +colorschemes, etc. The site is at https://www.vim.org +Nowadays people also seem to share their plugins/runtime files at +github. + +Tips can also be shared in the Wiki which you can find at + + http://vim.wikia.com ============================================================================= *faq-3* -SECTION 3 - AVAILABILITY +SECTION 3 - AVAILABILITY ~ *faq-3.1* 3.1. What is the latest version of Vim? -The latest version of Vim is 6.3 released on 8th June 2004. - -The release-history of different versions of Vim is below: - -Version 6.3 8th June 2004 -Version 6.2 1st June 2003 -Version 6.1 24th March 2002 -Version 6.0 27th September, 2001 -Version 5.8 31st May, 2001 -Version 5.7 24th June, 2000 -Version 5.6 16th January, 2000 -Version 5.5 21st September, 1999 -Version 5.4 26th July, 1999 -Version 5.3 31st August, 1998 -Version 5.2 24th August, 1998 -Version 5.1 7th April, 1998 -Version 5.0 19th February, 1998 -Version 4.6 13th March,1997 -Version 4.5 17th October, 1996 -Version 4.2 5th July,1996 -Version 4.0 21st May, 1996 -Version 3.0 16th August, 1994 -Version 2.0 21st December, 1993 -Version 1.27 23rd April, 1993 -Version 1.17 21st April, 1992 +The latest version of Vim is 8.1 released on 17th May 2018. + +The release history of different versions of Vim is below: + + VERSION RELEASE DATE ~ + -------------- -------------------- ~ + Version 8.1 17th May, 2018 + Version 8.0 12th September, 2016 + Version 7.4 10th August, 2013 + Version 7.3 15th August, 2010 + Version 7.2 9th August, 2008 + Version 7.1 12th May, 2007 + Version 7.0 8th May, 2006 + Version 6.4 15th October, 2005 + Version 6.3 8th June, 2004 + Version 6.2 1st June, 2003 + Version 6.1 24th March, 2002 + Version 6.0 27th September, 2001 + Version 5.8 31st May, 2001 + Version 5.7 24th June, 2000 + Version 5.6 16th January, 2000 + Version 5.5 21st September, 1999 + Version 5.4 26th July, 1999 + Version 5.3 31st August, 1998 + Version 5.2 24th August, 1998 + Version 5.1 7th April, 1998 + Version 5.0 19th February, 1998 + Version 4.6 13th March, 1997 + Version 4.5 17th October, 1996 + Version 4.2 5th July, 1996 + Version 4.0 21st May, 1996 + Version 3.0 16th August, 1994 + Version 2.0 21st December, 1993 + Version 1.27 23rd April, 1993 + Version 1.17 21st April, 1992 + Version 1.14 2nd November, 1991 + +For more information, read: + + |new-8| + |new-7| + |new-6| + |new-5| + |changed-8.1| + |changed-7.4| + |changed-7.3| + |changed-7.2| + |changed-7.1| *faq-3.2* 3.2. Where can I find the latest version of Vim? You can download the sources for the latest version of Vim from the -VimOnline website. The URL for this site is -http://vim.sourceforge.net/download.php. +Github repository. The URL for this site is + + https://github.com/vim/vim + +A mirror is available at bitbucket: + + https://bitbucket.org/vim-mirror/vim + +Some users keep updated repositories for distributing latest binary +versions of Vim. You can find those repositories here: + + http://vim.wikia.com/wiki/Where_to_download_Vim *faq-3.3* 3.3. What platforms does it run on? All Unix platforms. -All Windows platforms. -Amiga, Atari, BeOS, DOS, Macintosh, MachTen, OS/2, RiscOS, VMS. +All Windows platforms (XP and later). +Amiga, Atari, BeOS, DOS, Macintosh, MachTen, OS/2, RiscOS, VMS, IBM z/OS. *faq-3.4* 3.4. Where can I download the latest version of the Vim runtime files? @@ -1136,9 +1395,14 @@ filetype plugins, compiler files, color schemes, documentation, indentation files and keymaps) from the Vim ftp site from the ftp://ftp.vim.org/pub/vim/runtime directory. +Alternatively, the runtime files can be downloaded from the git +repository that holds Vim source code at: + + https://github.com/vim/vim/tree/master/runtime + ============================================================================= *faq-4* -SECTION 4 - HELP +SECTION 4 - HELP ~ *faq-4.1* 4.1. How do I use the help files? @@ -1150,9 +1414,10 @@ around in the help pages the same way you would in a read-only document. You can jump to specific subjects by using tags. This can be done in two ways: - * Use the "" command while standing on the name of a command or - option. This only works when the tag is a keyword. "" - and "g" work just like "". + * Use the "" command while standing on the name of a command + or option. This only works when the tag is a keyword. + "" and "g" work just like "". + * use the ":tag " command. This works with all characters. Use "" to jump back to previous positions in the help files. Use @@ -1163,77 +1428,86 @@ If you want to jump to a specific subject on the help pages, use ":help list of all available subjects. Use the standard search keys to locate the information you want. You can abbreviate the ":help" command as ":h". -For more information, read > +For searching the help, see the next Question 4.2. |faq-4.2| + +For more information, read: + + |online-help| - :help online-help -< *faq-4.2* 4.2. How do I search for a keyword in the Vim help files? -You can press the CTRL-D key after typing the help keyword to get a list of -all the help keywords containing the supplied pattern. You can also use the -meta characters like *, \+, etc to specify the help search pattern: > +a) You can press the CTRL-D key after typing the help keyword to get a + list of all the help keywords containing the supplied pattern. You can + also use the meta characters like *, \+, etc to specify the help + search pattern: > :help init :help str*() :help '*indent < -You can press the Tab key after typing a partial help keyword to expand to -the matching keyword. You can continue to press the Tab key to see other -keyword matches. +b) You can press the Tab key after typing a partial help keyword to expand + to the matching keyword. You can continue to press the Tab key to see + other keyword matches. -From the help window, you can use the ":tag" command to search for -keywords. For example, > +c) From the help window, you can use the ":tag" command to search for + keywords. For example, > :tselect /window < -This command will list all the help keywords containing the text "window". -You can select one from the list and jump to it. + This command will list all the help keywords containing the text + "window". You can select one from the list and jump to it. -You can use the ":helpgrep" command to search for the given text in all the -help files. The quickfix window will be opened with all the matching lines. +d) You can use the ":helpgrep" command to search for the given text in + all the help files. The quickfix window will be opened with all the + matching lines. -For more information, read > +For more information, read: + + |help-summary| + |c_CTRL-D| + |c_| + |:tselect| + |:help| + |:helpgrep| - :help c_CTRL-D - :help c_ - :help :tselect - :help :help - :help :helpgrep -< *faq-4.3* 4.3. I am getting an error message E123, what did I do wrong? -You can get more information about the error and the error message using: > +You can get more information about the error and the error message using: - :help E123 -< -For more information, read > + |E123| + +For more information, read: + + |error-messages| - :help error-messages -< *faq-4.4* 4.4. Where can I read about the various modes in Vim? -You can get information about the different modes in Vim by reading > +You can get information about the different modes in Vim by reading + + |vim-modes| - :help vim-modes -< *faq-4.5* 4.5. How do I generate the Vim help tags file after adding a new Vim help file? -You can use the ":helptags" command to regenerate the Vim help tag file. -For example: > +You can use the ":helptags" command to regenerate the Vim help tag file +from within Vim. For example: > :cd $VIMRUNTIME/doc :helptags . < -For more information, read > +To update all "doc" directories in your 'runtimepath', you can use + + :helptags ALL + +For more information, read: + + |:helptags| + |add-local-help| - :help :helptags - :help add-local-help -< *faq-4.6* 4.6. Can I use compressed versions of the help files? @@ -1241,9 +1515,9 @@ Yes. You can compress the help files and still be able to view them with Vim. This makes accessing the help files a bit slower and requires the "gzip" utility. Follow these steps to compress and use the Vim help files: -- Compress all the help files using "gzip ddoc/*.txt". +- Compress all the help files using "gzip doc/*.txt". -- Edit the "doc/tags" file and change the "".txt" to ".txt.gz" using +- Edit the "doc/tags" file and change the ".txt" to ".txt.gz" using :%s=\(\t.*\.txt\)\t=\1.gz\t= - Add the following line to your vimrc: @@ -1255,17 +1529,18 @@ decompressing the files. You must make sure that $VIMRUNTIME is set to where the other Vim files are, when they are not in the same location as the compressed "doc" directory. -For more information, read > +Note, that the :helpgrep command does not work with compressed help pages. - :help gzip-helpfile - :help 'helpfile' - :help gzip - :help $VIMRUNTIME -< +For more information, read: + + |gzip-helpfile| + |'helpfile'| + |gzip| + |$VIMRUNTIME| ============================================================================= *faq-5* -SECTION 5 - EDITING A FILE +SECTION 5 - EDITING A FILE ~ *faq-5.1* 5.1. How do I load a file in Vim for editing? @@ -1283,14 +1558,14 @@ You can also use the ":args" command to load files into Vim: > :args < -For more information, read > +For more information, read: + + |usr_07.txt| + |edit-files| + |:edit| + |:next_f| + |:args_f| - :help usr_07 - :help edit-files - :help :edit - :help :next_f - :help :args_f -< *faq-5.2* 5.2. How do I save the current file in another name (save as) and edit a new file? @@ -1309,13 +1584,13 @@ You can also use the ":file" command, followed by ":w" command: > :file :w < -For more information, read > +For more information, read: + + |07.7| + |:saveas| + |:file_f| + |:w| - :help 07.7 - :help :saveas - :help :file_f - :help :w -< *faq-5.3* 5.3. How do I change the current directory to the directory of the current file? @@ -1326,17 +1601,19 @@ directory of the current file: > :cd %:p:h < To automatically change the current directory to the directory of the -current file, use the following autocmd: > +current file, simply set the option 'autochdir'. > - :autocmd BufEnter * cd %:p:h + :set autochdir < -For more information, read > +For more information, read: + + |:cd| + |:lcd| + |filename-modifiers| + |autocommand| + |'acd'| + |getcwd()| - :help :cd - :help :lcd - :help filename-modifiers - :help autocommand -< *faq-5.4* 5.4. How do I write a file without the line feed (EOL) at the end of the file? @@ -1348,12 +1625,29 @@ a file without the EOL at the end of the file: > :set noeol :w < -For more information, read > +Alternatively, you can use: > + + :set noeol + :w ++bin +< +If you rather only like Vim not to write missing EOLs, you can reset the +'fixeol' option. This needs a Vim newer 7.4.785, so you should wrap this +in an if condition in your .vimrc like this: > - :help 'endofline' - :help 'binary' - :help 23.4 + if exists('+fixeol') + set nofixeol + endif < +This has the advantage of avoiding the many side effects that the +'binary' option has. + +For more information, read: + + |'endofline'| + |'fixeol'| + |'binary'| + |23.4| + *faq-5.5* 5.5. How do I configure Vim to open a file at the last edited location? @@ -1362,13 +1656,17 @@ in the '"' register. You can use the following autocmd in your .vimrc or .gvimrc file to open a file at the last edited location: > au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal g'\"" | endif + \ exe "normal! g`\"" | endif < -For more information, read > +Alternatively, you can simply source the vimrc_example.vim file, which is +distributed with Vim. + +For more information, read: + + |'quote| + |last-position-jump| + |vimrc_example.vim| - :help '" - :help last-position-jump -< *faq-5.6* 5.6. When editing a file in Vim, which is being changed by an external application, Vim opens a warning window (like the confirm dialog) each @@ -1386,53 +1684,58 @@ You can also use the following autocommand: > \ echo "File has been changed outside of vim." | \ echohl None < -For more information, read > +For more information, read: + + |'autoread'| + |FileChangedShell| + |timestamp| + |:checktime| - :help 'autoread' - :help FileChangedShell - :help timestamp - :help :checktime -< *faq-5.7* 5.7. How do I edit a file whose name is under the cursor? You can use the gf command to edit a file whose name is under the cursor. -You can use the CTRL-W f command to edit the file in a new window. +You can use the CTRL-W f command to edit the file in a new window and +finally you can use CTRL-W gf top open a new tab page that contains the +file name under the cursor. -For more information, read > +For more information, read: + + |gf| + |CTRL-W_f| + |CTRL-W_gf| + |'isfname'| + |'path'| + |'suffixesadd'| + |'includeexpr'| - :help gf - :help CTRL-W_f - :help 'isfname' - :help 'path' - :help 'suffixesadd' - :help 'includeexpr' -< *faq-5.8* 5.8. How do I reload/re-edit the current file? You can use the ":edit" command, without specifying a file name, to reload the current file. If you have made modifications to the file, you can use ":edit!" to force the reload of the current file (you will lose your -modifications). +modifications, but depending on your 'undoreload' settings, those +changes might be saved into the undo history). -For more information, read > +For more information, read: + + |:edit| + |:edit!| + |'confirm'| + |'undoreload'| - :help :edit - :help :edit! - :help 'confirm' -< *faq-5.9* 5.9. How do I autosave a file periodically? Vim doesn't support auto-saving a file periodically. -For more information, read > +For more information, read: + + |'updatetime'| + |CursorHold| + |swap-file| - :help 'updatetime' - :help CursorHold - :help swap-file -< *faq-5.10* 5.10. How do I open a file in read-only mode? @@ -1450,25 +1753,84 @@ read-only mode from the command-line: > $ view < -For more information, read > +For more information, read: + + |07.6| + |'readonly'| + |'modifiable'| + |:view| + |:sview| + |view| + |-R| + |-M| + + *faq-5.11* +5.11. How do I open a file for editing without saving the modifications to + the current file? + +You can open a file for editing without saving the modifications to the +current file and without losing the changes using one of the following +methods: > + + :split + :new +< +You can also set the 'hidden' option and edit a new file: > + + :set hidden + :e +< +If you want to discard the changes made to the current file and load +another file for editing, then you can use the following command: > + + :e! +< +For more information, read: + + |:edit!_f| + |'hidden'| + |:split| + |:new| - :help 07.6 - :help 'readonly' - :help 'modifiable' - :help :view - :help :sview - :help view - :help -R - :help -M + *faq-5.12* +5.12. How do I reduce the loading time for very large files in Vim? + +You can use the following settings to reduce the loading time for +very large files in Vim: > + + :set lazyredraw + :set noswapfile + :set undolevels=-1 + :set eventignore=all + :set nohidden + :set syntax=off < +Note that the above settings will disable many Vim features including the +following: Swap files support for crash recovery, undo support, syntax +highlighting, filetype detection and other autocommand based features. + +There is also the LargeFile plugin available at + + https://www.vim.org/scripts/script.php?script_id=1506 + +which automatically sets these options, when working with large files +(it is configurable, what is considered to be a large file, by default, +it is 100MB). ============================================================================= *faq-6* -SECTION 6 - EDITING MULTIPLE FILES +SECTION 6 - EDITING MULTIPLE FILES ~ *faq-6.1* 6.1. How do I open multiple files at once from within Vim? +Make a difference between args, buffers, tabs and windows. They are all +different things in VIM. + +args is a list of arguments. Buffers are place to edit text, almost +always attached to a file but not necessarily. Window is a place for a +buffer and tab is set of windows, better name would be 'layout'. + There are several ways to open multiple files at once from within Vim. You can use the ":next" command to specify a group of files: > @@ -1483,22 +1845,34 @@ You can use the :args command to specify a group of files as arguments: > After loading the files, you can use the ":next" and ":prev" command to switch between the files. -For more information, read > +To execute command for all files in argument-list use ":argdo" + +For more information, read: + + |07.2| + |:next| + |:args_f| + |argument-list| - :help 07.2 - :help :next - :help :args_f - :help argument-list -< *faq-6.2* 6.2. How do I switch between multiple files/buffers in Vim? +To list all buffers use ":ls", to list buffers without file attached to +(also known as unlisted buffers, ex. scratch buffer and help-window) use +":ls!" + There are several ways to switch between multiple files. You can use the -":buffer" command to switch between multiple files. For example, > +":buffer" command to switch between multiple files. You can also shorten +command as ":b" and use only part of the filename. For example, > :buffer file1 :buffer file2 + :b e2 < +You can also use after ":b" for autocompletion. Try also ":b" +followed by to see all available buffers. This works also for +":e". + You can also use the CTRL-^ key to switch between buffers. By specifying a count before pressing the key, you can edit the buffer with that number. Without the count, you can edit the alternate buffer by pressing CTRL-^ @@ -1507,18 +1881,22 @@ You can also use the ":e #" command to edit a particular buffer: > :e #5 < -For more information, read > +To close a buffer use ":bd" -command. + +To execute command for all files in buffer-list use ":bufdo" + +For more information, read: + + |edit-files| + |:buffer| + |CTRL-^| + |alternate-file| + |22.4| + |07.3| - :help edit-files - :help :buffer - :help CTRL-^ - :help alternate-file - :help 22.4 - :help 07.3 -< *faq-6.3* 6.3. How do I open several files in Vim, with each file in a separate - window? + window/tab? You can use the -o and -O Vim command line arguments to open multiple files in separate horizontally or vertically split Vim windows. For example: > @@ -1531,14 +1909,22 @@ separate horizontally split Vim windows. > $ vim -O3 f1.txt f2.txt f3.txt < The above command will open the files f1.txt, f2.txt and f3.txt in three -separate vertically split Vim windows. +separate vertically split Vim windows. > -For more information, read > - - :help -o - :help -O - :help startup-options + $ vim -p f1.txt f2.txt f3.txt < +The above command will open the files f1.txt, f2.txt and f3.txt in three +separate tab windows. The option 'tabpagemax' defines, how many tabpages +can be opened at the same time, by default it is set to 10. + +For more information, read: + + |-o| + |-O| + |-p| + |startup-options| + |'tabpagemax'| + *faq-6.4* 6.4. How do I configure Vim to autoload several files at once similar to "work-sets" or "projects"? @@ -1554,23 +1940,23 @@ The ":mkview" command creates a Vim script that restores the contents of the current window. You can use the ":loadview" command to load the view for the current file. -For more information, read > +For more information, read: + + |21.4| + |21.5| + |views-sessions| + |'sessionoptions'| + |:mksession| + |:source| + |v:this_session| + |:mkview| + |:loadview| + |'viewdir'| + |buffers| - :help 21.4 - :help 21.5 - :help views-sessions - :help 'sessionoptions' - :help :mksession - :help :source - :help v:this_session - :help :mkview - :help :loadview - :help 'viewdir' - :help buffers -< *faq-6.5* 6.5. Is it possible to open multiple top level windows in a single instance - of Vim similar to Nedit or emacs? + of Vim similar to Nedit or Emacs? No. It is currently not possible to open multiple top-level windows in a single instance of Vim. This feature is in the todo list. @@ -1578,22 +1964,24 @@ single instance of Vim. This feature is in the todo list. *faq-6.6* 6.6. How do I browse/explore directories from within Vim? -You can use the explorer.vim plugin, supplied with the standard Vim +You can use the netrw.vim plugin, supplied with the standard Vim installation, to browse/explore directories from within Vim. You can start the file explorer using one of the following commands: > :e :Explore - :SExplore + :Sexplore + :Vexplore + :Texplore < From the file explorer, you can browse through directories, rename, delete and edit files. -For more information, read > +For more information, read: + + |netrw.vim| + |22.1| - :help file-explorer - :help 22.1 -< *faq-6.7* 6.7. How do I edit files over a network using ftp/scp/rcp/http? @@ -1604,14 +1992,13 @@ example, to edit a file over ftp, you can use the following command: > $ vim ftp://machine/path < -For more information, read > +For more information, read: - :help netrw.vim -< + |netrw.vim| ============================================================================= *faq-7* -SECTION 7 - BACKUP +SECTION 7 - BACKUP ~ *faq-7.1* 7.1. When I edit and save files, Vim creates a file with the same name as @@ -1631,20 +2018,45 @@ also have to turn off the 'writebackup' option: > :set nowritebackup < -For more information, read > +For more information, read: + + |07.4| + |backup-table| + |'backup'| + |'writebackup'| + |'backupskip'| + |'backupdir'| + |'backupext'| + |'backupcopy'| + |backup| - :help 07.4 - :help backup-table - :help 'backup' - :help 'writebackup' - :help 'backupskip' - :help 'backupdir' - :help 'backupext' - :help 'backupcopy' - :help backup -< *faq-7.2* -7.2. How do I configure Vim to store all the backup files in a particular +7.2. When I edit and save files, Vim creates a file with the same name as + the original file and a "un~" extension at the end. How do I stop Vim + from creating this file (or) How do I disable the Vim undofile feature? + +Vim 7.3 contains as new feature persistent undo, that is, undo information +won't be lost when quitting Vim and be stored in a file that ends with .un~ +You have set the 'undofile' option, so Vim creates an undo file when saving +the original file. You can stop Vim from creating the backup file, by +clearing the option: > + + :set noundofile +< +Note that, by default this option is turned off. You have explicitly +enabled the 'undofile' option in one of the initialization files. If you +want your undofiles to be stored only in a particular directory, you can +point the 'undodir' option to a directory that will contain all your +aggregated undofiles. + +For more information, read: + + |'undodir'| + |'undofile'| + |undo-persistence| + + *faq-7.3* +7.3. How do I configure Vim to store all the backup files in a particular directory? You can configure Vim to store all the backup files in a particular @@ -1653,14 +2065,14 @@ backup files in the ~/backup directory, you can use the following command: > :set backupdir=~/backup < -For more information, read > +For more information, read: - :help 07.4 - :help 'backupdir' - :help backup -< - *faq-7.3* -7.3. When I save a file with Vim, the file permissions are changed. + |07.4| + |'backupdir'| + |backup| + + *faq-7.4* +7.4. When I save a file with Vim, the file permissions are changed. How do I configure Vim to save a file without changing the file permissions? @@ -1675,17 +2087,16 @@ when saving a file: > This applies, only if you have configured Vim to make a backup whenever overwriting a file. By default, Vim will not backup files. -For more information, read > +For more information, read: - :help 'backupcopy' - :help backup - :help 'backup' - :help 'writebackup' -< + |'backupcopy'| + |backup| + |'backup'| + |'writebackup'| ============================================================================= *faq-8* -SECTION 8 - BUFFERS +SECTION 8 - BUFFERS ~ *faq-8.1* 8.1. I have made some modifications to a buffer. How do I edit another @@ -1699,14 +2110,14 @@ to the current file: > < By setting the 'hidden' option, you can also save the modification history (undo-history) for the buffer. Otherwise, as you switch between files, the -undo-history will be lost. +undo-history will be lost (unless you use persistent undofiles). -For more information, read > +For more information, read: + + |'hidden'| + |hidden-quit| + |:hide| - :help 'hidden' - :help hidden-quit - :help :hide -< *faq-8.2* 8.2. How do I configure Vim to auto-save a modified buffer when switching to another buffer? @@ -1716,22 +2127,22 @@ switching to another buffer: > :set autowrite < -For more information, read > +For more information, read: + + |'autowrite'| + |'autowriteall'| + |'hidden'| - :help 'autowrite' - :help 'autowriteall' - :help 'hidden' -< *faq-8.3* 8.3. How do I replace the buffer in the current window with a blank buffer? You can use the ":enew" command to load an empty buffer in place of the buffer in the current window. -For more information, read > +For more information, read: + + |:enew| - :help :enew -< *faq-8.4* 8.4. Is there a keyboard shortcut to load a buffer by the buffer number? @@ -1739,10 +2150,10 @@ You can use the CTRL-^ command to load a buffer by specifying the buffer number. For example, to load buffer number 5, you have to use the 5 CTRL-^ command. -For more information, read > +For more information, read: + + |CTRL-^| - :help CTRL-^ -< *faq-8.5* 8.5. How do I open all the current buffers in separate windows? @@ -1751,37 +2162,31 @@ in the buffer list: > :ball < -For more information, read > +If you want all buffers to be opened in new tabs, simply prefix the :tab +command: > - :help :ball + :tab :sball < +For more information, read: + + |:ball| + *faq-8.6* 8.6. How do I close (delete) a buffer without exiting Vim? -You can use the ":bdelete" command to delete a buffer without exiting Vim. -For example: > +You can use any of ":bdelete", ":bwipeout" or ":bunload" commands to +delete a buffer without exiting Vim. For example: > :bdelete file1 < -For more information, read > - - :help :bdelete - :help :bwipeout -< - *faq-8.7* -8.7. I have several buffers opened with :e filename. How do I close one of - the buffers without exiting Vim? - -You can use the ":bdelete " command to close the buffer. +For more information, read: -For more information, read > + |:bdelete| + |:bwipeout| + |:bunload| - :help :bdelelete - :help :bunload - :help :bwipeout -< - *faq-8.8* -8.8. When I use the command ":%bd" to delete all the buffers, not all the + *faq-8.7* +8.7. When I use the command ":%bd" to delete all the buffers, not all the buffers are deleted. Why? In the ":%bd" command, the '%' range will be replaced with the starting and @@ -1789,12 +2194,14 @@ ending line numbers in the current buffer. Instead of using '%' as the range, you should specify numbers for the range. For example, to delete all the buffers, you can use the command ":1,9999bd". -For more information, read > +For more information, read: - :help :bd -< - *faq-8.9* -8.9. How do I display the buffer number of the current buffer/file? + |:bd| + +(This behaviour has been fixed with patch 7.4.530) + + *faq-8.8* +8.8. How do I display the buffer number of the current buffer/file? You can use 2 command to display the buffer number for the current file/buffer. Note the use of count before the CTRL-G command. If the count @@ -1808,30 +2215,30 @@ number: > You can also include the "%n" field to the 'statusline' option to display the current buffer number on the statusline. -For more information read, > +For more information, read: - :help CTRL-G - :help bufnr() - :help :echo - :help 'statusline' -< - *faq-8.10* -8.10. How do I delete a buffer without closing the window in which the - buffer is displayed? + |CTRL-G| + |bufnr()| + |:echo| + |'statusline'| + + *faq-8.9* +8.9. How do I delete a buffer without closing the window in which the + buffer is displayed? You can use the following command to open the next buffer and delete the current buffer. > :bnext | bdelete # < -For more information read, > +For more information, read: - :help :bnext - :help :bdelete - :help :buffers -< - *faq-8.11* -8.11. How do I map the tab key to cycle through and open all the buffers? + |:bnext| + |:bdelete| + |:buffers| + + *faq-8.10* +8.10. How do I map the tab key to cycle through and open all the buffers? You can use the following two map commands, to map the CTRL-Tab key to open the next buffer and the CTRL-SHIFT-Tab key to open the previous buffer: > @@ -1839,15 +2246,16 @@ the next buffer and the CTRL-SHIFT-Tab key to open the previous buffer: > :nnoremap :bnext :nnoremap :bprevious < -For more information read, > +Note, this might not work in the terminal version of Vim. - :help :bnext - :help :previous -< +For more information, read: + + |:bnext| + |:bprevious| ============================================================================= *faq-9* -SECTION 9 - WINDOWS +SECTION 9 - WINDOWS ~ *faq-9.1* 9.1. What is the difference between a Vim window and a buffer? @@ -1857,13 +2265,13 @@ remains unchanged until you write the buffer to the file. A Vim window is a viewport onto a buffer. You can use multiple windows on one buffer or several windows on different buffers. -For more information, read > +For more information, read: + + |usr_08.txt| + |22.4| + |windows-intro| + |Q_wi| - :help usr_08.txt - :help 22.4 - :help windows-intro - :help Q_wi -< *faq-9.2* 9.2. How do I increase the width of a Vim window? @@ -1876,13 +2284,13 @@ commands: > < You can also use CTRL-W < or CTRL-W > or CTRL-W | commands. -For more information, read > +For more information, read: + + |:vertical-resize| + |CTRL-W_>| + |CTRL-W_<| + |window-resize| - :help vertical-resize - :help CTRL-W_> - :help CTRL-W_< - :help window-resize -< *faq-9.3* 9.3. How do I zoom into or out of a window? @@ -1928,17 +2336,17 @@ layout after zooming into a window. If you want to restore the Vim window layout after zooming into a window, you can use the ZoomWin plugin. You can download this plugin from the Vim online website at: -http://vim.sourceforge.net/scripts/script.php?script_id=508 + https://www.vim.org/scripts/script.php?script_id=508 -For more information, read > +For more information, read: + + |CTRL-W_o| + |window-resize| + |'winminheight'| + |'equalalways'| + |'winheight'| + |08.3| - :help CTRL-W_o - :help window-resize - :help 'winminheight' - :help 'equalalways' - :help 'winheight' - :help 08.3 -< *faq-9.4* 9.4. How do I execute an ex command on all the open buffers or open windows or all the files in the argument list? @@ -1946,19 +2354,20 @@ For more information, read > You can use the ":bufdo" command to execute an ex command on all the open buffers. You can use the ":windo" command to execute an ex command on all the open windows. You can use the ":argdo" command to execute an ex -command on all the files specified in the argument list. +command on all the files specified in the argument list. And finally you +can use the ":tabdo" command to execute an ex command in all open tab pages. -For more information, read > +For more information, read: - :help :windo - :help :bufdo - :help :argdo - :help 26.3 -< + |:windo| + |:bufdo| + |:argdo| + |:tabdo| + |26.3| ============================================================================= *faq-10* -SECTION 10 - MOTION +SECTION 10 - MOTION ~ *faq-10.1* 10.1. How do I jump to the beginning (first line) or end (last line) of a @@ -1967,32 +2376,34 @@ SECTION 10 - MOTION You can use 'G' command to jump to the last line in the file and the 'gg' command to jump to the first line in the file. -For more information, read > +For more information, read: + + |G| + |gg| - :help G - :help gg -< *faq-10.2* 10.2. In insert mode, when I press the key to go to command mode, the cursor moves one character to the left (except when the cursor is on the first character of the line). Is it possible to change this behavior to keep the cursor at the same column? -No. It is not possible to change this behavior. The cursor is *always* +No. It is not possible to change this behavior. The cursor is always positioned on a valid character (unless you have virtual-edit mode enabled). So, if you are appending text to the end of a line, when you return to command mode the cursor *must* drop back onto the last character you typed. For consistency sake, the cursor drops back everywhere, even if you are in the middle of a line. -You can use the CTRL-O command in insert mode to execute a single ex -command and return back to insert mode without moving the cursor column. +You can use the CTRL-O or CTRL-\ CTRL-O command in insert mode to execute a +single ex command and return back to insert mode without moving the cursor +column. -For more information, read > +For more information, read: + + |'virtualedit'| + |i_CTRL-O| + |i_CTRL-\_CTRL-O| - :help 'virtual' - :help i_CTRL-O -< *faq-10.3* 10.3. How do I configure Vim to maintain the horizontal cursor position when scrolling with the , , etc keys? @@ -2002,10 +2413,10 @@ horizontal location when scrolling text: > :set nostartofline < -For more information, read > +For more information, read: + + |'startofline'| - :help 'startofline' -< *faq-10.4* 10.4. Some lines in a file are more than the screen width and they are all wrapped. When I use the j, k keys to move from one line to the next, @@ -2019,18 +2430,20 @@ resetting the 'wrap' option: > :set nowrap < -For more information, read > +For more information, read: + + |gj| + |gk| + |'wrap'| - :help gj - :help gk - :help 'wrap' -< You can use the following mappings: > :map gk :imap gk :map gj :imap gj + :noremap j gj + :noremap k gk < *faq-10.5* 10.5. What is the definition of a sentence, paragraph and section in Vim? @@ -2048,23 +2461,24 @@ A section begins after a form-feed () in the first column and at each of a set of section macros, specified by the pairs of characters in the 'sections' option. -For more information, read > +For more information, read: + + |sentence| + |'joinspaces'| + |'cpoptions'| + |paragraph| + |section| + |word| - :help sentence - :help 'joinspaces' - :help 'cpoptions' | /^\s*j\> - :help paragraph - :help section - :help word -< *faq-10.6* 10.6. How do I jump to beginning or end of a sentence, paragraph or a section? You can use the following motion commands to jump to the beginning or end -of a sentence or a paragraph or a section: > +of a sentence or a paragraph or a section: - motion position where + motion position where ~ + ------ --------- ----------------- ~ ( beginning current sentence ) end current sentence { beginning current paragraph @@ -2073,49 +2487,52 @@ of a sentence or a paragraph or a section: > [[ beginning current section ][ end current section ]] beginning next section -< + Each of these motions can be preceded by a number which will extend the jump forward (or backward). -For more information, read > +For more information, read: + + |object-motions| - :help object-motions -< *faq-10.7* 10.7. I have lines in a file that extends beyond the right extent of the screen. How do I move the Vim view to the right to see the text off the screen? You can use one of the following commands to horizontally scroll the screen -to the left or right: > +to the left or right: + + cmd scroll to ~ + --- -------------------------- ~ + zl scroll to the left + zh scroll to the right + zL scroll half a screenwidth to the left + zH scroll half a screenwidth to the right + zs scroll to position the cursor at the start of the screen + ze scroll to position the cursor at the end of the screen - zl - scroll to the left - zh - scroll to the right - zL - scroll half a screenwidth to the left - zH - scroll half a screenwidth to the right - zs - scroll to position the cursor at the start of the screen - ze - scroll to position the cursor at the end of the screen -< You can use the g0 command to move the cursor to the first character of the screen line and the g$ command to move the cursor to the last character of the screen line without scrolling the screen. -For more information, read > +For more information, read: + + |scroll-horizontal| - :help scroll-horizontal -< *faq-10.8* 10.8. How do I scroll two or more buffers simultaneously? -You can set the "scrollbind" option for each of the buffer to scroll them +You can set the "scrollbind" option for each of the buffers to scroll them simultaneously. -For more information, read > +For more information, read: + + |'scrollbind'| + |scroll-binding| + |'scrollopt'| + |'cursorbind'| - :help 'scrollbind' - :help scroll-binding - :help 'scrollopt' -< *faq-10.9* 10.9. When I use my arrow keys, Vim changes modes, inserts weird characters in my document but doesn't move the cursor properly. What's going on? @@ -2134,15 +2551,15 @@ to map your key sequence to a matching cursor movement command and save these mappings in a file. You can then ":source" the file whenever you work from that terminal. -For more information, read > +For more information, read: + + |'timeout'| + |'ttimeout'| + |'timeoutlen'| + |'ttimeoutlen'| + |:map| + |vt100-cursor-keys| - :help 'timeout' - :help 'ttimeout' - :help 'timeoutlen' - :help 'ttimeoutlen' - :help :map - :help vt100-cursor-keys -< *faq-10.10* 10.10. How do I configure Vim to move the cursor to the end of the previous line, when the left arrow key is pressed and the cursor is currently @@ -2163,11 +2580,11 @@ line, add the '>' flag to the 'whichwrap' option: > The above will work only in normal and visual modes. To use this in insert and replace modes, add the '[' and ']' flags respectively. -For more information, read > +For more information, read: + + |'whichwrap'| + |05.7| - :help 'whichwrap' - :help 05.7 -< *faq-10.11* 10.11. How do I configure Vim to stay only in insert mode (modeless editing)? @@ -2189,14 +2606,18 @@ disable this option, reset the 'insertmode' option: > You can also start vim using the "evim" command or you can use "vim -y" to use Vim as a modeless editor. -For more information, read > +You can also start Vim in insert mode using the ":startinsert" ex command. + +For more information, read: + + |'insertmode'| + |:startinsert| + |:stopinsert| + |i_CTRL-O| + |i_CTRL-L| + |evim| + |evim-keys| - :help 'insertmode' - :help i_CTRL-O - :help i_CTRL-L - :help evim - :help evim-keys -< *faq-10.12* 10.12. How do I display some context lines when scrolling text? @@ -2205,11 +2626,11 @@ lines (context) above and below the cursor. > :set scrolloff=10 < -For more information, read > +For more information, read: + + |'scrolloff'| + |'sidescrolloff'| - :help 'scrolloff' - :help 'sidescrolloff' -< *faq-10.13* 10.13. How do I go back to previous cursor locations? @@ -2218,16 +2639,15 @@ or `` command. You can use the CTRL-O command to go back to older cursor positions and the CTRL-I command to go to the newer cursor positions in the jump list. -For more information, read > +For more information, read: - :help 03.10 - :help mark-motions - :help jump-motions -< + |03.10| + |mark-motions| + |jump-motions| ============================================================================= *faq-11* -SECTION 11 - SEARCHING TEXT +SECTION 11 - SEARCHING TEXT ~ *faq-11.1* 11.1. After I searched for a text with a pattern, all the matched text @@ -2248,11 +2668,17 @@ To temporarily turn off the search highlighting, use > You can also clear the search highlighting, by searching for a pattern that is not in the current file (for example, search for the pattern 'asdf'). -For more information, read > +You can use this mapping, to clear the search highlighting when +redrawing the window pressing > - :help 'hlsearch' - :help :nohlsearch + :nnoremap :nohls < + +For more information, read: + + |'hlsearch'| + |:nohlsearch| + *faq-11.2* 11.2. How do I enter a carriage return character in a search pattern? @@ -2260,10 +2686,10 @@ You can either use '\r' or to enter a carriage return character in a pattern. In Vim scripts, it is better to use '\r' for the carriage return character. -For more information, read > +For more information, read: + + |sub-replace-special| - :help sub-replace-special -< *faq-11.3* 11.3. How do I search for the character ^M? @@ -2274,12 +2700,12 @@ CTRL-V key and then pressing the CTRL-M key. > < You can also use the "\r" character. In Vim scripts, "\r" is preferred. -For more information, read > +For more information, read: + + |c_CTRL-V| + |using_CTRL-V| + |/\r| - :help c_CTRL-V - :help using_CTRL-V - :help /\r -< *faq-11.4* 11.4. How can I search/replace characters that display as '~R', '~S', etc.? @@ -2291,12 +2717,12 @@ can use the following command to search for the special character: > < where, ^V is entered by pressing CTRL-V. -For more information, read > +For more information, read: + + |ga| + |using_CTRL_V| + |24.8| - :help ga - :help using_CTRL_V - :help 24.8 -< *faq-11.5* 11.5. How do I highlight all the non-printable characters in a file? @@ -2306,15 +2732,15 @@ non-printable characters in a file: > :set hlsearch /\(\p\|$\)\@!. < -For more information, read > +For more information, read: + + |/\p| + |/bar| + |/$| + |/\(| + |/\@!| + |'hlsearch'| - :help /\p - :help /bar - :help /$ - :help /\( - :help /\@! - :help 'hlsearch' -< *faq-11.6* 11.6. How do I search for whole words in a file? @@ -2326,11 +2752,11 @@ example: > The \< atom matches the beginning of the word and the \> atom matches the end of the word. -For more information, read > +For more information, read: + + |/\<| + |/\>| - :help /\< - :help /\> -< *faq-11.7* 11.7. How do I search for the current word under the cursor? @@ -2338,15 +2764,15 @@ You can press the * key to search forward for the current word under the cursor. To search backward, you can press the # key. Note that only whole keywords will be searched using these commands. -For more information, read > +For more information, read: + + |star| + |#| + |gstar| + |g#| + |03.8| + |search-commands| - :help star - :help # - :help g* - :help g# - :help 03.8 - :help search-commands -< *faq-11.8* 11.8. How do I search for a word without regard to the case (uppercase or lowercase)? @@ -2361,12 +2787,12 @@ directive: > /\c < -For more information, read > +For more information, read: + + |'ignorecase'| + |/ignorecase| + |/\c| - :help 'ignorecase' - :help /ignorecase - :help /\c -< *faq-11.9* 11.9. How do I search for words that occur twice consecutively? @@ -2380,19 +2806,19 @@ The main difference is the use of '\w' and '\k', where the latter is based on the 'iskeyword' option which may include accented and other language specific characters. -For more information, read > +For more information, read: + + |/\1| + |/\(| + |/\)| + |/\<| + |/\>| + |/\w| + |/\k| + |/\+| + |/\_x| + |'iskeyword'| - :help /\1 - :help /\( - :help /\) - :help /\< - :help /\> - :help /\w - :help /\k - :help /\+ - :help /\_x - :help 'iskeyword' -< *faq-11.10* 11.10. How do I count the number of times a particular word occurs in a buffer? @@ -2407,23 +2833,24 @@ particular word occurs in a buffer: > This only counts the number of lines where the word occurs. You can also use the following command: > - :%s/\/&/g + :%s/\/&/gn < To count the number of alphabetic words in a file, you can use > - :%s/\a\+/&/g + :%s/\a\+/&/gn < To count the number of words made up of non-space characters, you can use > - :%s/\S\+/&/g + :%s/\S\+/&/gn < -For more information, read > +For more information, read: + + |count-items| + |word-count| + |v_g_CTRL-G| + |12.5| + |:s_flags| - :help count-items - :help word-count - :help v_g_CTRL-G - :help 12.5 -< *faq-11.11* 11.11. How do I place the cursor at the end of the matched word when searching for a pattern? @@ -2433,11 +2860,11 @@ end of the matched word. For example > /mypattern/e < -For more information about search offsets, read > +For more information about search offsets, read: + + |search-offset| + |/| - :help search-offset - :help / -< *faq-11.12* 11.12. How do I search for an empty line? @@ -2449,14 +2876,15 @@ You can search for an empty line using: > /^\s*$ < -For more information, read > +The latter also matches lines, that consist only of white space, while the +former only matches true empty lines. For more information, read: + + |/^| + |/$| + |/\s| + |/star| + |search-commands| - :help /^ - :help /$ - :help /\s - :help /* - :help search-commands -< *faq-11.13* 11.13. How do I search for a line containing only a single character? @@ -2464,28 +2892,29 @@ You can search for a line containing only a single character using: > /^\s*\a\s*$ < -For more information, read > +For more information, read: + + |/^| + |/\a| + |/\s| + |/star| + |/$| - :help /^ - :help /\a - :help /\s - :help /* - :help /$ -< *faq-11.14* 11.14. How do I search and replace a string in multiple files? -You can use the 'argdo' or 'bufdo' or 'windo' commands to execute an ex -command on multiple files. For example: > +You can use the 'argdo', 'bufdo', 'windo' or 'tabdo' commands to execute an +ex command on multiple files. For example: > - :argdo %s/foo/bar/g + :argdo %s/foo/bar/g|upd < -For more information, read > +For more information, read: + + |:argdo| + |:bufdo| + |:windo| + |:tabdo| - :help :argdo - :help :bufdo - :help :windo -< *faq-11.15* 11.15. I am using the ":s" substitute command in a mapping. When a search for a pattern fails, the map terminates. I would like the map to @@ -2495,10 +2924,10 @@ For more information, read > You can use the 'e' flag to the substitute command to continue processing other commands in a map, when a pattern is not found. -For more information, read > +For more information, read: + + |:s_flags| - :help :s_flags -< *faq-11.16* 11.16. How do I search for the n-th occurrence of a character in a line? @@ -2508,15 +2937,15 @@ occurrence of the character @ in a line, you can use the command 5f@. This assumes the cursor is at the beginning of the line - and that this first character is not the one your are looking for. -For more information, read > +For more information, read: + + |f| + |F| + |t| + |T| + |;| + |,| - :help f - :help F - :help t - :help T - :help ; - :help , -< *faq-11.17* 11.17. How do I replace a tab (or any other character) with a hard return (newline) character? @@ -2529,12 +2958,12 @@ character using the following command: > Note that in the above command, if you use \n instead of \r, then the tab characters will not be replaced by a new-line character. -For more information, read > +For more information, read: + + |sub-replace-special| + |NL-used-for-Nul| + |CR-used-for-NL| - :help sub-replace-special - :help NL-used-for-Nul - :help CR-used-for-NL -< *faq-11.18* 11.18. How do I search for a character by its ASCII value? @@ -2543,12 +2972,44 @@ followed by the decimal or hexadecimal or octal value of that character in the search "/" command. To determine the ASCII value of a character you can use the ":ascii" or the "ga" command. -For more information, read > +For example, to search for the ASCII character with value 188 (??), you can +use one of the following search commands: > + + /188 + /o274 + /xBC + /u00bc +< +You can also search for the character with the decimal/octal/hex number +using a collation [] like this: > + + /[\d188] + /[\o274] + /[\xbc] + /[\u00bc] +< +Alternatively, you can use the special atom \%d \%o \%x \%u: > + + /\%d188 + /\%o274 + /\%xbc + /\%u00bc +< +Or you use digraphs to enter the character. For example enter: > - :help i_CTRL-V_digit - :help :ascii - :help ga + /CTRL-K14 < +to search for the above character. + +For more information, read: + + |i_CTRL-V_digit| + |:ascii| + |ga| + |/\]| + |/\%d| + |digraphs| + *faq-11.19* 11.19. How do I search for long lines? @@ -2557,14 +3018,16 @@ number of characters using the Vim regular-expressions in the search command. For example, to search for all the lines containing more than 80 characters, you can use one of the following commands: > - /^.\{80}.*$ - /^.*\%80c.*$ + /^.\{80}.\+$ + /^.*\%>80c.*$ + /^.*\%>80v.*$ < -For more information, read > +For more information, read: + + |/\{| + |/\%c| + |/\%v| - :help /\{ - :help /\%c -< *faq-11.20* 11.20. How do I display all the lines in the current buffer that contain a specified pattern? @@ -2579,17 +3042,22 @@ current buffer that contain "vim": > :g/vim/p < +Since :p is the default command to be executed for the ex command :g, you +can also use: > + + :g/vim +< If you also want the corresponding line numbers, then you can use the following command: > :g//# < -For more information, read > +For more information, read: + + |:global| + |:print| + |:number| - :help :global - :help :print - :help :number -< *faq-11.21* 11.21. How do I search for a text string that spans multiple lines? @@ -2608,13 +3076,13 @@ following search command: > /Hello\_s\+World < -For more information, read > +For more information, read: + + |27.8| + |pattern-atoms| + |/\_| + |pattern-searches| - :help 27.8 - :help pattern-atoms - :help /\_ - :help pattern-searches -< *faq-11.22* 11.22. How do I search for a pattern within the specified range of lines in a buffer? @@ -2625,16 +3093,107 @@ and \% - /white\%>10l\%<20l + /white\%>9l\%<31l +< +For more information, read: + + |/\%l| + + *faq-11.23* +11.23. How do I clear the last searched pattern? + +The last searched pattern is stored in the "/" register. You can clear +this register using the following command: > + + :let @/="" < -For more information, read > +To clear the last search pattern whenever a buffer is unloaded, you can use +the following command: > - :help /\%l + :autocmd BufUnload * let @/ = "" < +For more information, read: + + |@/| + |:let-@| + |autocmd-searchpat| + |last-pattern| + + *faq-11.24* +11.24. Why does this pattern 'a.\{-}p\@!' not match? + +"\{-}" doesn't just mean "as few as possible", it means "as few as +possible to make the whole pattern succeed". If it didn't match the 'p', +the whole pattern would fail (because of the "p\@!") so it does match +the "p". It is a longer match, but it is the shortest match that makes +the whole pattern succeed. + +If you wanted "as few as possible regardless" you would use "\@>", which +basically divides a pattern up so that the pieces either side behave +independently. If the pattern were "a.\{-}\@>p\@!" then ".\{-}" would +always match nothing because that's the smallest match that can succeed +when there are not other restrictions. The whole pattern then would +behave the same as "ap\@!", i.e. it would match any "a" not followed by +a "p"). + +This means, it matches as few as possible 'a's without trying to keep +going until Vim finds the longest match. This means, it will still match +'ap'. + + *faq-11.25* +11.25. How can I use '/' within a pattern, without escaping it? + +When using / to search for a pattern, you need to escape all '/' within +the pattern, because they would otherwise terminate the pattern. So you +can't directly search for /usr/share/doc/ but need to search for +\/usr\/share\/doc\/ + +The easiest solution around that, would be to use '?' to start a +backward search and afterwards use / to use the last search-pattern +in forward direction. + +If you have a Vim, that has the eval-feature built in (which needs at +least a normal built or higher), you can also directly paste the pattern +into the search register: + +:let @/ = '/usr/share/doc/' + +Then use 'n' to jump to the next occurrence. + +See also the help at + + |@/| + |/| + + *faq-11.26* +11.26. How can I operate on a search match? + +The 'gn' command makes it easy to operate on regions of text that match +the current search pattern. By default, it will search forward for the +last used search pattern and visually select the match. If the cursor is +already on the match, it will be visually selected. If you used the 'gn' +command after an operator (e.g. 'c' to change text), it will be applied +on the match. + +If Visual mode is active before using gn, the visual selection will be +extended until the end of the next match. + +The 'gN' commands works similar but searches backwards. + +This allows to repeat simple operations on each match. For example, you +might want to change each occurence of apples by peaches. So you search +using '/apple' then you can use 'cgnpeach' to replace the current +match by peach. Now you can use the dot '.' command to redo the +replacement for the rest of the buffer. + +See also the help at + + |gn| + |gN| ============================================================================= *faq-12* -SECTION 12 - CHANGING TEXT +SECTION 12 - CHANGING TEXT ~ *faq-12.1* 12.1. How do I delete all the trailing white space characters (SPACE and @@ -2645,14 +3204,14 @@ remove all the trailing white space characters: > :%s/\s\+$// < -For more information, read > +For more information, read: + + |:%| + |:s| + |/\s| + |/\+| + |/$| - :help :% - :help :s - :help /\s - :help /\+ - :help /$ -< *faq-12.2* 12.2. How do I replace all the occurrences of multiple consecutive space characters to a single space? @@ -2662,13 +3221,17 @@ multiple consecutive space characters to a single space: > :%s/ \{2,}/ /g < -For more information, read > +Alternatively use: > - :help :% - :help :s - :help /\{ - :help :s_flags + :%s/ \+/ /g < +For more information, read: + + |:%| + |:s| + |/\{| + |:s_flags| + *faq-12.3* 12.3. How do I reduce a range of empty lines into one line only? @@ -2677,28 +3240,30 @@ line only: > :v/./.,/./-1join < -The explanation for this command is below: > +The explanation for this command is below: + part description ~ + ----- -------------------------- ~ :v/./ Execute the following command for all lines not containing a character (empty lines). - ., Use the current line as the start of the range of + ., Use the current line as the start of the range of lines. - /./ Use the line containing a character as the last line. - -1 Adjust the range of lines to end with the line before + /./ Use the line containing a character as the last line. + -1 Adjust the range of lines to end with the line before the last line. - j Join the lines in the range. -< + j Join the lines in the range. + Note that this will give an error message if the empty lines are at the end of the file. To correct this, you have to add a temporary line at the end of the file, execute the command and then remove the temporary line. -For more information, read > +For more information, read: + + |:v| + |:join| + |cmdline-ranges| + |collapse| - :help :v - :help :join - :help cmdline-ranges - :help collapse -< *faq-12.4* 12.4. How do I delete all blank lines in a file? How do I remove all the lines containing only space characters? @@ -2724,15 +3289,15 @@ You can use the "yiw" (yank inner word without whitespace) command or the "yaw" (yank a word with whitespace) command to copy/yank the current word. -For more information, read > +For more information, read: + + |04.6| + |04.8| + |iw| + |yank| + |text-objects| + |objects| - :help 04.6 - :help 04.8 - :help iw - :help yank - :help text-objects - :help objects -< *faq-12.6* 12.6. How do I yank text from one position to another position within a line, without yanking the entire line? @@ -2746,12 +3311,12 @@ another line, first mark the position using the 'ma' command, go to the start of the yank position, and then yank till the mark using y`a (note the direction of the quote) -For more information, read > +For more information, read: + + |yank| + |motion.txt| + |04.6| - :help yank - :help motion.txt - :help 4.6 -< *faq-12.7* 12.7. When I yank some text into a register, how do I append the text to the current contents of the register? @@ -2763,12 +3328,12 @@ want to append some new text to this, you have to use the "A" register name. If you use the lowercase register name, then the contents of the register will be overwritten with the new text. -For more information, read > +For more information, read: + + |quote| + |quote_alpha| + |10.1| - :help quote - :help quote_alpha - :help 10.1 -< *faq-12.8* 12.8. How do I yank a complete sentence that spans over more than one line? @@ -2779,13 +3344,13 @@ use the yank operator followed by a motion command. For example: > < From inside the sentence you can use 'yi)' to yank the sentence. -For more information, read > +For more information, read: + + |yank| + |{motion}| + |object-motions| + |04.6| - :help yank - :help {motion} - :help object-motions - :help 4.6 -< *faq-12.9* 12.9. How do I yank all the lines containing a pattern into a buffer? @@ -2800,21 +3365,35 @@ The first command, clears the contents of the register "a". The second command copies all the lines containing "mypattern" into the register "a". Note that the capital letter "A" is used to append the matched lines. Now you can paste the contents of register "a" to a buffer using "ap command. -For more information, read > - :help :g - :help :y - :help let-register - :help quote_alpha - :help put - :help registers - :help :registers +If you only want to collect all matches, you can use a different +approach. For that run the ':s' command with the flags 'gn' so that it +won't actually change the buffer ('n' flag) but select each match ('g' +flag). Combining this with the '\=' part in the replacement part, you +can copy each match to e.g. a list. Altogether this looks like this: > + + :let list=[] + :%s/pattern/\=add(list, submatch(0))/gn < +Now all matches will be in the list and you can post process them as +wanted. + +For more information, read: + + |:g| + |:y| + |:let-register| + |quote_alpha| + |put| + |registers| + |:registers| + |sub-replace-\=| + *faq-12.10* -12.10. How do I delete all the lines in a file that does not contain a +12.10. How do I delete all the lines in a file that do not contain a pattern? -You can use ":v" command to delete all the lines that does not contain a +You can use ":v" command to delete all the lines that do not contain a pattern: > :v/pattern/d @@ -2823,31 +3402,31 @@ or > :g!/pattern/d < -For more information, read > +For more information, read: + + |:v| + |:g| - :help :v - :help :g -< *faq-12.11* 12.11. How do I add a line before each line with "pattern" in it? You can use the following command to add a line before each line with "pattern" in it: > - :g/pattern/normal Oi + :g/pattern/normal! Oi < Alternatively you can yank the line using the Y command and then insert the line using the following command: > :g/pattern/put! < -For more information, read > +For more information, read: + + |:g| + |:put| + |insert| + |0| - :help :g - :help :put - :help insert - :help 0 -< *faq-12.12* 12.12. Is there a way to operate on a line if the previous line contains a particular pattern? @@ -2857,11 +3436,11 @@ line contains a particular pattern: > :g//+{cmd} < -For more information, read > +For more information, read: + + |:g| + |:range| - :help :g - :help :range -< *faq-12.13* 12.13. How do I execute a command on all the lines containing a pattern? @@ -2878,12 +3457,12 @@ command: > Unless you want the normal mode commands to be remapped, consider using a ":normal!" command instead (note the "!"). -For more information, read > +For more information, read: + + |:global| + |:v| + |:normal| - :help :global - :help :v - :help :normal -< *faq-12.14* 12.14. Can I copy the character above the cursor to the current cursor position? @@ -2892,11 +3471,11 @@ In Insert mode, you can copy the character above the cursor to the current cursor position by typing . The same can be done with the characters below the cursor by typing . -For more information, read > +For more information, read: + + |i_CTRL-Y| + |i_CTRL-E| - :help i_CTRL-Y - :help i_CTRL-E -< *faq-12.15* 12.15. How do I insert a blank line above/below the current line without entering insert mode? @@ -2906,24 +3485,24 @@ You can use the ":put" ex command to insert blank lines. For example, try > :put ='' :put! ='' < -For more information, read > +For more information, read: + + |:put| - :help :put -< *faq-12.16* -12.16. How do I insert the name of current file into the current buffer? +12.16. How do I insert the name of the current file into the current buffer? There are several ways to insert the name of the current file into the current buffer. In insert mode, you can use the % or the =expand("%") command. In normal mode, you can use the ":put =@%" command. -For more information, read > +For more information, read: + + |i_CTRL-R| + |expand()| + |!!| - :help i_CTRL-R - :help expand() - :help !! -< *faq-12.17* 12.17. How do I insert the contents of a Vim register into the current buffer? @@ -2936,11 +3515,14 @@ In normal mode, you can use the ":put " command to insert the contents of . For example, use the ":put d" command to insert the contents of register "d" into the current buffer. -For more information, read > +For more information, read: + + |i_CTRL-R| + |i_CTRL-R_CTRL-R| + |i_CTRL-R_CTRL-O| + |i_CTRL-R_CTRL-P| + |:put| - :help i_CTRL-R - :help :put -< *faq-12.18* 12.18. How do I move the cursor past the end of line and insert some characters at some columns after the end of the line? @@ -2951,10 +3533,10 @@ start the virtual mode, use > :set virtualedit=all < -For more information, read > +For more information, read: + + |'virtualedit'| - :help 'virtualedit' -< *faq-12.19* 12.19. How to replace the word under the cursor (say: junk) with "foojunkbar" in Vim? @@ -2964,19 +3546,19 @@ the line, use the following command: > :exe "s/".expand("")."/foo&bar/" < -Too match specifically you could use a more complex substitution like this: > +To match specifically you could use a more complex substitution like this: > :exe 's/\<'.expand("").'\%>'.(col(".")-1).'c\>/foo&bar/' < You can also use the command: ciwfoo"bar -For more information, read > +For more information, read: + + |:substitute| + |expand()| + |col()| + |/\%c| - :help :substitute - :help expand() - :help col() - :help /\%c -< *faq-12.20* 12.20. How do I replace a particular text in all the files in a directory? @@ -2986,12 +3568,12 @@ the files specified as arguments: > :args * :argdo %s///ge | update < -For more information, read > +For more information, read: + + |:args_f| + |:argdo| + |:s_flags| - :help :args_f - :help :argdo - :help :s_flags -< *faq-12.21* 12.21. I have some numbers in a file. How do I increment or decrement the numbers in the file? @@ -2999,14 +3581,16 @@ For more information, read > You can use the CTRL-A key to increment the number and the CTRL-X key to decrement the number. You can also specify the number to increment/decrement from the number by specifying a count to the key. This -works for decimal, octal and hexadecimal numbers. +works for decimal, octal and hexadecimal numbers. You can change the base +used by Vim for this operation by modifying the 'nrformats' option. -For more information, read > +For more information, read: + + |26.2| + |CTRL-A| + |CTRL-X| + |'nrformats'| - :help CTRL-A - :help CTRL-X - :help 'nrformats' -< *faq-12.22* 12.22. How do I reuse the last used search pattern in a ":substitute" command? @@ -3026,14 +3610,14 @@ character: > :s/newpattern/~/ < -For more information, read > +For more information, read: + + |:s| + |:&| + |:~| + |&| + |sub-replace-special| - :help :s - :help :& - :help :~ - :help & - :help sub-replace-special -< *faq-12.23* 12.23. How do I change the case of a string using the ":substitute" command? @@ -3054,14 +3638,14 @@ line to uppercase, you can use the following command: > :s/\<\(.\)\(\k*\)\>/\u\1\L\2/g < -For more information, read > +For more information, read: + + |sub-replace-special| + |:substitute| + |/\U| + |/\L| + |/\u| - :help sub-replace-special - :help :substitute - :help \U - :help \L - :help \u -< *faq-12.24* 12.24. How do I enter characters that are not present in the keyboard? @@ -3070,12 +3654,12 @@ keyboard. You can use the ":digraphs" command to display all the currently defined digraphs. You can add a new digraph to the list using the ":digraphs" command. -For more information, read > +For more information, read: + + |digraphs| + |'digraph'| + |24.9| - :help digraphs - :help 'digraphs' - :help 24.9 -< *faq-12.25* 12.25. Is there a command to remove any or all digraphs? @@ -3088,15 +3672,16 @@ ones. Adding a command to remove digraphs is on the todo list. previously entered characters in insert mode using the backspace key? -You can set the 'backspace' option to erase previously entered characters -in insert mode: > +This is traditional vi behaviour. You can set the 'backspace' option to +erase previously entered characters in insert mode: > :set backspace=indent,eol,start < -For more information, read > +For more information, read: + + |'backspace'| + |i_backspacing| - :help 'backspace' -< *faq-12.27* 12.27. I have a file which has lines longer than 72 characters terminated with "+" and wrapped to the next line. How can I quickly join the @@ -3109,15 +3694,15 @@ You can use the ":global" command to search and join the lines: > This will, however, only join every second line. A couple of more complex examples which will join all consecutive lines with a "+" at the end are: > - :g/*$/,/\(^\|[^+]\)$/j + :g/+$/,/\(^\|[^+]\)$/j :g/+$/mark a | .,/\(^\|[^+]\)$/s/+$// | 'a,.j < -For more information, read > +For more information, read: + + |:g| + |:j| + |:mark| - :help :g - :help :j - :help :mark -< *faq-12.28* 12.28. How do I paste characterwise yanked text into separate lines? @@ -3126,11 +3711,11 @@ lines: > :put =@" < -For more information, read > +For more information, read: + + |:put| + |quote_=| - :help :put - :help quote_= -< *faq-12.29* 12.29. How do I change the case (uppercase, lowercase) of a word or a character or a block of text? @@ -3151,10 +3736,19 @@ You can use the "g~g~" command to switch the case of the current line. You can use the "g~{motion}" or "{Visual}~" commands to switch the case of a block of text. -For more information, read > +If you set 'tildeop' the "~" command behaves like an operator and expects +a motion command to act on. If you have > - :help case + :set tildeop < +and you want to change the case from the current cursor position to the end +of line, simply use "~$". + +For more information, read: + + |case| + |'tildeop'| + *faq-12.30* 12.30. How do I enter ASCII characters that are not present in the keyboard? @@ -3163,12 +3757,12 @@ You can enter ASCII characters that are not present in the keyboard by pressing CTRL-V and then the ASCII character number. You can also use digraphs to enter special ASCII characters. -For more information, read > +For more information, read: + + |i_CTRL-V_digit| + |digraphs| + |45.5| - :help i_CTRL-V_digit - :help digraphs - :help 45.5 -< *faq-12.31* 12.31. How do I replace non-printable characters in a file? @@ -3187,13 +3781,13 @@ digraphs for all characters, together with their value in decimal and alpha. You can enter a non-printable character by entering CTRL-K followed by two alphanumeric characters (a digraph). -For more information, read > +For more information, read: + + |:ascii| + |i_CTRL-V| + |i_CTRL-V_digit| + |:digraphs| - :help :ascii - :help i_CTRL-V - :help i_CTRL-V_digit - :help :digraphs -< *faq-12.32* 12.32. How do I remove duplicate lines from a buffer? @@ -3209,22 +3803,39 @@ the duplicate lines. 12.33. How do I prefix all the lines in a file with the corresponding line numbers? -You can prefix the lines with the corresponding line number in several -ways. Some of them are listed below: > +You can prefix the lines in a file with the corresponding line number in +several ways. Some of them are listed below: > :%s/^/\=line('.'). ' ' - :%s/^/\=strpart(line(".")." ", 0, 5) - :g/^/exec "s/^/".strpart(line(".")." ", 0, 4) + :%s/^/\=printf('%5d ', line('.'))/ + :%s/^/\=strpart(line('.').'. ', 0, 5) + :%s/^/\=strpart(' ', strlen(line('.'))).line('.').'. ' < -For more information, read > +The last two commands will pad the line numbers with space characters. The +last command will right align the numbers and the command before that will +left align the numbers. - :help sub-replace-special - :help line() - :help expr6 - :help strpart() - :help :execute - :help :global +If you don't want to number consecutive lines but rather non-consecutive +regions, you can also use this idiom: > + + :let i = 1 + :g/TODO/s/^/\=printf('%2d.',i)|let i+=1 < +This first initializes the variable i with 1. In the next line, a :g +command is used to perform a substitute command only on lines, that +match 'TODO'. After the substitute command has taken place, the variable +i will be incremented by 1. + +For more information, read: + + |sub-replace-special| + |line()| + |expr6| + |strpart()| + |printf()| + |:execute| + |:global| + *faq-12.34* 12.34. How do I exchange (swap) two characters or words or lines? @@ -3238,28 +3849,46 @@ cursor in the blank space before the first word). You can exchange two lines with the "ddp" command sequence. The 'dd' will delete the current line and 'p' will paste the just deleted line after the -current line. This will result in exchanging the two lines. +current line. This will result in exchanging the two lines. All of the above operations will change the " unnamed register. You can use the ":m +" ex command to exchange two lines without changing the unnamed register. -For more information, read > +For more information, read: + + |x| + |p| + |dd| + |d| + |e| + |linewise-register| + |quotequote| + |:move| + + *faq-12.35* +12.35. How do I change the characters used as word delimiters? + +Vim uses the characters specified by the 'iskeyword' option as word +delimiters. The default setting for this option is "@,48-57,_,192-255". + +For example, to add ':' as a word delimiter, you can use > + + :set iskeyword+=: +< +To remove '_' as a word delimiter, you can use > - :help x - :help p - :help dd - :help d - :help e - :help linewise-register - :help quotequote - :help :move + :set iskeyword-=_ < +For more information, read: + + |'iskeyword'| + |word| ============================================================================= *faq-13* -SECTION 13 - COMPLETION IN INSERT MODE +SECTION 13 - COMPLETION IN INSERT MODE ~ *faq-13.1* 13.1. How do I complete words or lines in insert mode? @@ -3276,20 +3905,26 @@ mode. Vim supports completion of the following items: > - CTRL-X CTRL-F file names CTRL-X CTRL-L whole lines - CTRL-X CTRL-D macro definitions (also in included files) - CTRL-X CTRL-I current and included files + CTRL-X CTRL-N keywords in the current file CTRL-X CTRL-K words from a dictionary CTRL-X CTRL-T words from a thesaurus + CTRL-X CTRL-I current and included files CTRL-X CTRL-] tags + CTRL-X CTRL-F file names + CTRL-X CTRL-D macro definitions (also in included files) CTRL-X CTRL-V Vim command line + CTRL-X CTRL-U User defined completion + CTRL-X CTRL-O Omni completion < -For more information, read > +User defined completions and omni completions are often set by filetype +plugins. + +For more information, read: + + |24.3| + |ins-completion| - :help 24.3 - :help ins-completion -< *faq-13.2* 13.2. How do I complete file names in insert mode? @@ -3297,10 +3932,10 @@ In insert mode, you can use the CTRL-X CTRL-F command sequence to complete filenames that start with the same characters as in the current line before the cursor. -For more information, read > +For more information, read: + + |compl-filename| - :help compl-filename -< *faq-13.3* 13.3. I am using CTRL-P/CTRL-N to complete words in insert mode. How do I complete words that occur after the just completed word? @@ -3308,55 +3943,61 @@ For more information, read > You can use CTRL-X CTRL-N and CTRL-X CTRL-P keys to complete words that are present after the just completed word. -For more information, read > +For more information, read: - :help i_CTRL-X_CTRL-P - :help i_CTRL-X_CTRL-N - :help ins-completion -< + |i_CTRL-X_CTRL-P| + |i_CTRL-X_CTRL-N| + |ins-completion| ============================================================================= *faq-14* -SECTION 14 - TEXT FORMATTING +SECTION 14 - TEXT FORMATTING ~ *faq-14.1* 14.1. How do I format a text paragraph so that a new line is inserted at the end of each wrapped line? You can use the 'gq' command to format a paragraph. This will format the -text according to the current 'textwidth' setting. +text according to the current 'textwidth' setting. An alternative would be +to use the 'gw' command that formats like 'gq' but does not move the +cursor. Note that the gq operator can be used with a motion command to operate on a range of text. For example: > gqgq - Format the current line gqap - Format current paragraph + gwap - Format current paragraph (and don't move cursor) gq3j - Format the current and the next 3 lines < -For more information, read > +For more information, read: + + |gq| + |gw| + |formatting| + |usr_25.txt| + |motion.txt| - :help gq - :help formatting - :help usr_25.txt - :help motion.txt -< *faq-14.2* 14.2. How do I format long lines in a file so that each line contains less than 'n' characters? -First set the 'textwidth' option to the desired value: > +You can set the 'textwidth' option to control the number of characters that +can be present in a line. For example, to set the maximum width of a line +to 70 characters, you can use the following command: > set textwidth=70 < -Now to break the long lines to the length defined by the 'textwidth' -option, use > +Now to break the long lines in a file to the length defined by the +'textwidth' option, you can use > :g/./normal gqq < -For more information, read > +For more information, read: + + |'textwidth'| + |gq| - :help gq -< *faq-14.3* 14.3. How do I join short lines to form a paragraph? @@ -3373,12 +4014,12 @@ all paragraphs in a specific range, use: > :'a,'bg/\S/normal gq} < -For more information, read > +For more information, read: + + |gq| + |G| + |gqq| - :help gq - :help G - :help gqq -< *faq-14.4* 14.4. How do I format bulleted and numbered lists? @@ -3401,11 +4042,12 @@ You can use the 'n' flag in the 'formatoptions' to align the text. > With this option, when formatting text, Vim will recognize numbered lists. For this option to work, the 'autoindent' option also must be set. -For more information, read > +For more information, read: + + |'formatoptions'| + |fo-table| + |format-comments| - :help 'formatoptions' - :help fo-table -< *faq-14.5* 14.5. How do I indent lines in insert mode? @@ -3415,15 +4057,15 @@ CTRL-D key to delete on shiftwidth of indent at the start of the current line. You can also use the CTRL-O >> and CTRL-O << commands to indent the current line in insert mode. -For more information, read > +For more information, read: + + |i_CTRL-T| + |i_CTRL-D| + |i_0_CTRL-D| + |i_CTRL-O| + |>>| + |<<| - :help i_CTRL-T - :help i_CTRL-D - :help i_0_CTRL-D - :help i_CTRL-O - :help >> - :help << -< *faq-14.6* 14.6. How do I format/indent an entire file? @@ -3433,27 +4075,27 @@ You can format/indent an entire file using the gg=G command, where > = - apply indentation G - till end of file < -For more information, read > +For more information, read: + + |gg| + |=| + |G| + |'formatprg'| + |C-indenting| - :help gg - :help = - :help G - :help 'formatprg' - :help C-indenting -< *faq-14.7* 14.7. How do I increase or decrease the indentation of the current line? You can use the '>>' and '<<' commands to increase or decrease the indentation of the current line. -For more information, read > +For more information, read: + + |shift-left-right| + |>>| + |<<| + |'shiftwidth'| - :help shift-left-right - :help >> - :help << - :help 'shiftwidth' -< *faq-14.8* 14.8. How do I indent a block/group of lines? @@ -3463,31 +4105,30 @@ indent the lines > :10,20> < -For more information, read > +For more information, read: + + |shift-left-right| + |v_>| + |v_<| + |:<| + |:>| - :help shift-left-right - :help v_> - :help v_< - :help :< - :help :> -< *faq-14.9* 14.9. When I indent lines using the > or < key, the standard 8-tabstops are - used instead of the current 'tabstop' setting. Why? + used instead of the current 'tabstop' setting. Why? The number of spaces used when lines are indented using the ">" operator is -controlled by the 'shiftwidth' option. The 'tabstop' setting is not used -for indentation. To change the amount of spaces used for indentation, use -the command: > +controlled by the 'shiftwidth' option. The 'tabstop' setting is only +used, when the 'shiftwidth' option is zero. > :set shiftwidth=4 < -For more information, read > +For more information, read: + + |'shiftwidth'| + |>>| + |'softtabstop'| - :help 'shiftwidth' - :help >> - :help 'softtabstop' -< *faq-14.10* 14.10. How do I turn off the automatic indentation of text? @@ -3498,14 +4139,14 @@ present, remove it. Also, depending on your preference, you may also want to check the value of the 'autoindent', 'smartindent', 'cindent' and 'indentexpr' options and turn them off as needed. -For more information, read > +For more information, read: + + |:filetype-indent-off| + |'autoindent'| + |'smartindent'| + |'cindent'| + |'indentexpr'| - :help :filetype-indent-off - :help 'autoindent' - :help 'smartindent' - :help 'cindent' - :help 'indentexpr' -< *faq-14.11* 14.11. How do I configure Vim to automatically set the 'textwidth' option to a particular value when I edit mails? @@ -3514,12 +4155,12 @@ You can use the 'FileType' autocommand to set the 'textwidth' option: > autocmd FileType mail set tw= < -For more information, read > +For more information, read: + + |:autocmd| + |FileType| + |usr_43.txt| - :help :autocmd - :help FileType - :help usr_43.txt -< *faq-14.12* 14.12. Is there a way to make Vim auto-magically break lines? @@ -3528,14 +4169,14 @@ Vim will auto-magically break the newly entered lines. For example: > :set textwidth=75 < -For more information, read > +For more information, read: + + |'textwidth'| + |ins-textwidth| + |'formatoptions'| + |fo-table| + |formatting| - :help textwidth - :help ins-textwidth - :help 'formatoptions' - :help fo-table - :help formatting -< *faq-14.13* 14.13. I am seeing a lot of ^M symbols in my file. I tried setting the 'fileformat' option to 'dos' and then 'unix' and then 'mac'. None of @@ -3544,21 +4185,20 @@ For more information, read > When a file is loaded in Vim, the format of the file is determined as below: -- If all the lines end with a new line (), then the fileformat is +- If all the lines end with a new line (), then the fileformat is 'unix'. -- If all the lines end with a carriage retuurn () followed by a new line +- If all the lines end with a carriage return () followed by a new line (), then the fileformat is 'dos'. -- If all the lines end with carriage returnn (), then the fileformat is +- If all the lines end with carriage return (), then the fileformat is 'mac'. If the file has some lines ending with and some lines ending with followed by a , then the fileformat is set to 'unix'. -You can change the format of the current file, by modifying the -'fileformat' option and then saving the file: > +You can change the format of the current file, by saving it explicitly in +dos format: > - :set fileformat=dos - :w + :w ++ff=dos < To display the format of the current file, use > @@ -3572,48 +4212,133 @@ try the following commands: > :set fileformat=unix :w < -For more information, read > +To remove the carriage return () character at the end of all the lines +in the current file, you can use the following command: > + + :%s/\r$// +< +To force Vim to use a particular file format, when editing a file, you can +use the following command: > - :help 'fileformats' - :help 'fileformat' - :help file-formats - :help DOS-format-write - :help Unix-format-write - :help Mac-format-write - :help dos-file-formats - :help 23.1 + :e ++ff=dos filename < +For more information, read: + + |'fileformats'| + |'fileformat'| + |file-formats| + |DOS-format-write| + |Unix-format-write| + |Mac-format-write| + |dos-file-formats| + |23.1| + |++ff| + *faq-14.14* 14.14. When I paste some text into a Vim buffer from another application, the alignment (indentation) of the new text is messed up. How do I fix this? -The indentation of the text is messed up due to various Vim settings -related to indentation (like autoindent, smartindent, textwidth etc). -Before pasting text into Vim, you can set the 'paste' option: > +When you paste text into a GUI Vim using the mouse, Vim is able to +detect that you are pasting text. So all the indentation related +settings (like autoindent, smartindent, cindent, etc.) are ignored and +the text is pasted literally. + +When pasting text into a Vim running in a terminal (like xterm) using +the mouse, Vim may not be able to detect that you are pasting text. This +depends on several things: the capability of the terminal to pass the +mouse events to Vim, Vim is compiled to handle mouse events and access +the clipboard, the DISPLAY variable is set properly, the Vim 'mouse' +option is set correctly. + +If Vim is able to detect that you are pasting text using the mouse, then +the pasted text will be inserted literally. + +If Vim is not able to detect that you are pasting using the mouse, then +it will see the pasted text as though you literally typed the text. +After the first line from the pasted text is inserted, when Vim +encounters the newline character, because of the indentation settings, +the next line will start indented. The spaces at the beginning of the +second line in the pasted text will be inserted leading to additional +indentation. This will be repeated for subsequent lines. So the pasted +text will be inserted with stair case indentation. + +You can fix this problem in a terminal Vim in several ways: - :set paste +1. Build Vim with the +mouse and +xterm_clipboard compile-time options. + The normal or big or huge build of Vim includes these options. Set + the 'mouse' option to either 'a' or include 'i'. When pasting text + using the mouse, don't press the Shift key. This will work only if + Vim can access the X display. For more information, read the + following Vim help topics: + + |+feature-list| + |'mouse'| + || + |x11-selection| + |xterm-clipboard| + +1.1 Some Linux distributions build their terminal vim packages + without X support. This makes no sense and leaves many users + with the impression that Vim in terminal mode doesn't support + some operations such as properly pasting text with a mouse. > + + If your distribution includes gvim, which it almost certainly + does these days, the solutions to this include the following. < -After pasting the text, you can turn off the option using: > + a) Start Vim as > - :set nopaste + gvim -v < -You can also toggle the paste option using: > + b) Put this alias in your shell's configuration file, e.g. + ~/.bashrc: > - :set paste! + alias vim='gvim -v' < -If you can access the clipboard through the * register, then you can paste -the text without indentation using CTRL-R CTRL-O *. + c) Put the following command in a file named 'vim' and put that + file in your ~/bin directory: > -For more information, read > + gvim -v "$@" +< + d) Link the distribution's gvim to ~/bin/vim with the following + command, which needs to be executed only once. > - :help 'paste' - :help 'pastetoggle' - :help i_CTRL-R_CTRL_O - :help clipboard - :help xterm-clipboard - :help gui-clipboard + ln -s $(which gvim) ~/bin/vim < + For c) and d), make sure that ~/bin precedes /usr/bin in your + PATH. + +2. Paste the text using the CTRL-R CTRL-O * command. This will paste + the text literally without any automatic indentation. If you want to + paste the text and then fix the indentation, then you can use CTRL-R + CTRL-P *. These commands will work only if Vim can access the X + display. For more information, read the following Vim help topics: + + |i_CTRL-R_CTRL-O| + |i_CTRL-R_CTRL-P| + |quotestar| + +3. Set the 'paste' option before pasting the text. This option will + disable the effect of all the indentation related settings. Make + sure to turn off this option using ':set nopaste' after pasting the + text. Otherwise the Vim indentation feature will not work. Do not + permanently set the 'paste' option in your .vimrc file. If you are + going to repeat these steps often, then you can set the + 'pastetoggle' option to a key. When you press the specified key, + the 'paste' option will be toggled. You can press the key once + before pasting the text and the press the key once after pasting + the text. Note that when the 'paste' option is set, all the + mappings and abbreviations are disabled. For more information, + read the following Vim help topics: + + |'paste'| + |'pastetoggle'| + +You can also refer to the following topics in the user manual: + + |04.7| + |09.3| + *faq-14.15* 14.15. When there is a very long wrapped line (wrap is "on") and a line doesn't fit entirely on the screen it is not displayed at all. There @@ -3627,10 +4352,10 @@ symbols. > :set display=lastline < -For more information, read > +For more information, read: + + |'display'| - :help 'display' -< *faq-14.16* 14.16. How do I convert all the tab characters in a file to space characters? @@ -3642,16 +4367,16 @@ example, to convert all the tabs to white spaces, use > :set expandtab :retab < -For more information, read > +For more information, read: + + |:retab| + |'expandtab'| + |'tabstop'| + |25.3| - :help :retab - :help 'expandtab' - :help 'tabstop' - :help 25.3 -< *faq-14.17* 14.17. What Vim options can I use to edit text that will later go to a word - processor? + processor? You can set the following options to edit text that will later go into a word processor: > @@ -3662,19 +4387,40 @@ word processor: > :set showbreak=>>> < You can use the 'gk' and 'gj' commands to move one screen line up and down. -For more information, read > +For more information, read: + + |'wrap'| + |'linebreak'| + |'textwidth'| + |'showbreak'| + |gk| + |gj| + + *faq-14.18* +14.18. How do I join lines without adding or removing any space characters? + +By default, when you join lines using the "J" or ":join" command, Vim will +replace the line break, leading white space and trailing white space with a +single space character. If there are space characters at the end of a line +or a line starts with the ')' character, then Vim will not add a space +character. - :help 'wrap' - :help 'linebreak' - :help 'textwidth' - :help 'showbreak' - :help gk - :help gj -< +To join lines without adding or removing any space characters, you can use +the gJ or ":join!" commands. + +For more information, read: + + |gJ| + |:join| + |J| + |10.5| + |'joinspaces'| + |'cpoptions'| + |'formatoptions'| ============================================================================= *faq-15* -SECTION 15 - VISUAL MODE +SECTION 15 - VISUAL MODE ~ *faq-15.1* 15.1. How do I do rectangular block copying? @@ -3688,24 +4434,24 @@ If CTRL-V does not work as expected, it may have been remapped to CTRL-Q by the mswin.vim script which is often sourced by a vimrc on Windows machines to mimic some common short cuts from other programs. -For more information, read > +For more information, read: + + |04.4| + |blockwise-visual| + |visual-mode| + |Q_vi| - :help 04.4 - :help blockwise-visual - :help visual-mode - :help Q_vi -< *faq-15.2* 15.2. How do I delete or change a column of text in a file? You can use the Vim block-wise visual mode to select the column of text and apply an operator (delete, change, copy, etc) on it. -For more information, read > +For more information, read: + + |visual-block| + |visual-operators| - :help visual-block - :help visual-operators -< *faq-15.3* 15.3. How do I apply an ex-command on a set of visually selected lines? @@ -3716,28 +4462,28 @@ command. After visually selecting the lines, press ":" to go to the command mode. Vim will automatically insert the visual range '<,'>. You can run any ex-command on the visual range. -For more information, read > +For more information, read: + + |v_:| + |'<| + |'>| - :help v_: - :help '< - :help '> -< *faq-15.4* 15.4. How do I execute an ex command on a column of text selected in Visual block mode? -All the ex commands operate on whole lines only. If you try to execute an -ex command on a column of text selected in visual block mode, Vim will -operate on all the selected lines (instead of the selected columns). You -can use the vis.vim plugin script from http://vim.sourceforge.net scripts -archive to do this. +All the ex commands operate on whole lines only. If you try to execute +an ex command on a column of text selected in visual block mode, Vim +will operate on all the selected lines (instead of the selected +columns). You can use the vis.vim or NrrwRgn plugin script from +https://www.vim.org scripts archive to do this. -For more information, read > +For more information, read: + + |cmdline-ranges| + |10.3| + |cmdline-lines| - :help cmdline-ranges - :help 10.3 - :help cmdline-lines -< *faq-15.5* 15.5. How do I select the entire file in visual mode? @@ -3747,12 +4493,12 @@ You can select the entire file in visual mode using ggVG. > V - Start linewise visual mode G - goto the end of the file. < -For more information, read > +For more information, read: + + |gg| + |linewise-visual| + |G| - :help gg - :help linewise-visual - :help G -< *faq-15.6* 15.6. When I visually select a set of lines and press the > key to indent the selected lines, the visual mode ends. How can I reselect the @@ -3763,22 +4509,22 @@ You can use the 'gv' command to reselect the last selected visual area. You can also use the marks '< and '> to jump to the beginning or the end of the last selected visual area. -For more information, read > +For more information, read: + + |gv| + |'<| + |'>| - :help gv - :help '< - :help '> -< *faq-15.7* 15.7. How do I jump to the beginning/end of a visually selected region? You can use the 'o' command to jump to the beginning/end of a visually selected region. -For more information, read > +For more information, read: + + |v_o| - :help v_o -< *faq-15.8* 15.8. When I select text with mouse and then press : to enter an ex command, the selected text is replaced with the : character. How do I @@ -3796,13 +4542,13 @@ option is also automatically set when you use the "behave mswin" command. Select mode looks like visual mode, but it is similar to the selection mode in MS-Windows. -For more information, read > +For more information, read: + + |Select-mode| + |'selectmode'| + |09.4| + |:behave| - :help Select-mode - :help 'selectmode' - :help 9.4 - :help :behave -< *faq-15.9* 15.9. When I select a block of text using the mouse, Vim goes into selection mode instead of Visual mode. Why? @@ -3817,12 +4563,12 @@ option: > Note that by default, the 'selectmode' option will be set to empty, so that always visual mode is used. -For more information, read > +For more information, read: + + |'selectmode'| + |Select-mode| + |:behave| - :help 'selectmode' - :help Select-mode - :help :behave -< *faq-15.10* 15.10. How do I visually select the last copy/pasted text? @@ -3831,17 +4577,16 @@ text. The '[ mark is set to the beginning of the last changed/yanked text and the '] mark is set to the end of the last changed/yanked text. To visually select this block of text use the command '[v'] -For more information, read > +For more information, read: - :help '[ - :help '] - :help `a - :help v -< + |'[| + |']| + |`a| + |v| ============================================================================= *faq-16* -SECTION 16 - COMMAND-LINE MODE +SECTION 16 - COMMAND-LINE MODE ~ *faq-16.1* 16.1. How do I use the name of the current file in the command mode or an @@ -3852,12 +4597,17 @@ file. In some commands, you have to use expand("%") to get the filename: > :!perl % < -For more information, read > +Another example is to load the latex generated pdf file from the file you +are currently editing: > - :help :_% - :help cmdline-special - :help expand() + :!xpdf %<.pdf < +For more information, read: + + |:_%| + |cmdline-special| + |expand()| + *faq-16.2* 16.2. How do I edit the text in the Vim command-line effectively? @@ -3871,23 +4621,23 @@ enter/return key. In a similar vain, the search history can be edited with "q/" and "q?" commands. -For more information, read > +For more information, read: + + |cmdline-window| - :help cmdline-window -< *faq-16.3* 16.3. How do I switch from Vi mode to Ex mode? You can use the Q command to switch from Vi mode to Ex mode. To switch from Ex mode back to the Vi mode, use the :vi command. -For more information, read > +For more information, read: + + |Q| + |gQ| + |Ex-mode| + |:vi| - :help Q - :help gQ - :help Ex-mode - :help :vi -< *faq-16.4* 16.4. How do I copy the output from an ex-command into a buffer? @@ -3914,11 +4664,11 @@ following set of commands: > :g/HelloWord/p :redir END < -For more information, read > +For more information, read: + + |:redir| + |:silent| - :help :redir - :help :silent -< *faq-16.5* 16.5. When I press the tab key to complete the name of a file in the command mode, if there are more than one matching file names, then @@ -3932,10 +4682,10 @@ option to 'list': > :set wildmode=list < -For more information, read > +For more information, read: + + |'wildmode'| - :help 'wildmode' -< *faq-16.6* 16.6. How do I copy text from a buffer to the command line and from the command line to a buffer? @@ -3955,22 +4705,27 @@ is to open the command line window using q: from normal mode or CTRL-F from the command-line mode. In the command line window you can use all the Vim commands to edit the command line. -For more information, read > +For more information, read: + + |c_CTRL-R| + |quote_:| + |cmdline-window| - :help c_CTRL-R - :help quote_: - :help cmdline-window -< *faq-16.7* 16.7. How do I put a command onto the command history without executing it? To put a command onto the command history without executing it, press the key to cancel the command. -For more information, read > +An alternative solution, is to use the histadd() function like this: > - :help c_ + :call histadd(':', 'echo strftime("%c")') < +For more information, read: + + |c_| + |histadd()| + *faq-16.8* 16.8. How do I increase the height of the command-line? @@ -3979,16 +4734,15 @@ option: > :set cmdheight=2 < -For more information, read > +For more information, read: - :help 'cmdheight' - :help hit-enter - :help 05.7 -< + |'cmdheight'| + |hit-enter| + |05.7| ============================================================================= *faq-17* -SECTION 17 - VIMINFO +SECTION 17 - VIMINFO ~ *faq-17.1* 17.1. When I invoke Vim, I get error messages about illegal characters in @@ -3997,13 +4751,13 @@ SECTION 17 - VIMINFO You can remove the $HOME/.viminfo or the $HOME/_viminfo file to get rid of these error messages. -For more information, read > +For more information, read: + + |viminfo-errors| + |viminfo-file-name| + |viminfo| + |21.3| - :help viminfo-errors - :help viminfo-file-name - :help viminfo - :help 21.3 -< *faq-17.2* 17.2. How do I disable the viminfo feature? @@ -4014,30 +4768,45 @@ feature by setting the 'viminfo' option to an empty string in your local :set viminfo="" < -For more information, read > +For more information, read: + + |'viminfo'| - :help 'viminfo' -< *faq-17.3* -17.3. How do I save and use Vim marks across Vim sessions? +17.3. How do I save and use Vim marks/commands across Vim sessions? You can save and restore Vim marks across Vim sessions using the viminfo file. To use the viminfo file, make sure the 'viminfo' option is not empty. To save and restore Vim marks, the 'viminfo' option should not contain the 'f' flag or should have a value greater than zero for the 'f' option. -For more information, read > +You can also use the viminfo file to synchronize the commandline history +across different sessions using :wvimfo and :rviminfo commands together +with the FocusGained and FocusLost autocommands: > - :help 21.3 - :help viminfo - :help 'viminfo' - :help :wviminfo - :help :rviminfo + augroup viminfo + au! + au FocusLost * wviminfo + au FocusGained * rviminfo + augroup end < +Note, this will only work reliably, when Vim can detect the FocusLost +and FocusGained autocommands correctly. This means it should work with +GVim but might depend on your terminal for konsole vim. + +For more information, read: + + |21.3| + |viminfo| + |'viminfo'| + |:wviminfo| + |:rviminfo| + |FocusLost| + |FocusGained| ============================================================================= *faq-18* -SECTION 18 - REMOTE EDITING +SECTION 18 - REMOTE EDITING ~ *faq-18.1* 18.1. How do I open a file with existing instance of gvim? What happened to @@ -4053,10 +4822,10 @@ To list the server names of all the currently running Vim instances, use > $ vim --serverlist < -To get more information about client-server feature, read > +To get more information about client-server feature, read + + |client-server| - :help client-server -< *faq-18.2* 18.2. How do I send a command to a Vim server to write all buffers to disk? @@ -4064,25 +4833,24 @@ You can use the Vim remote server functionality to do this: > $ gvim --servername myVIM --remote-send ":wall" < -For more information, read > +For more information, read: + + |client-server| + |CTRL-\_CTRL-N| + |:wall| - :help client-server - :help CTRL-\_CTRL-N - :help :wall -< *faq-18.3* 18.3. Where can I get the documentation about the Vim remote server functionality? You can get more information about the Vim remote server functionality by -reading > +reading - :help client-server -< + |client-server| ============================================================================= *faq-19* -SECTION 19 - OPTIONS +SECTION 19 - OPTIONS ~ *faq-19.1* 19.1. How do I configure Vim in a simple way? @@ -4093,10 +4861,10 @@ You can use the ":options" command to open the Vim option window: > < This window can be used for viewing and setting all the options. -For more information, read > +For more information, read: + + |:options| - :help :options -< *faq-19.2* 19.2. How do I toggle the value of an option? @@ -4110,13 +4878,22 @@ You can also suffix the option with "!" to toggle the value: > :set ignorecase! :set hlsearch! < -For more information, read > +For more information, read: + + |set-option| - :help set-option -< *faq-19.3* 19.3. How do I set an option that affects only the current buffer/window? +Some of the Vim options can have a local or global value. A local value +applies only to a specific buffer or window. A global value applies to all +the buffers or windows. + +When a Vim option is modified using the ":set" command, both the global and +local values for the option are changed. You can use the ":setlocal" +command to modify only the local value for the option and the ":setglobal" +command to modify only the global value. + You can use the ":setlocal" command to set an option that will affect only the current file/buffer: > @@ -4126,15 +4903,15 @@ Note that not all options can have a local value. You can use ":setlocal" command to set an option locally to a buffer/window only if the option is allowed to have a local value. -You can also use the following command to set a option locally: > +You can also use the following command to set an option locally: > :let &l:{option-name} = < -For more information, read > +For more information, read: + + |:setlocal| + |local-options| - :help :setlocal - :help local-options -< *faq-19.4* 19.4. How do I use space characters for a Vim option value? @@ -4143,10 +4920,10 @@ character. For example: > :set tags=tags\ /usr/tags < -For more information, read > +For more information, read: + + |option-backslash| - :help option-backslash -< *faq-19.5* 19.5. Can I add (embed) Vim option settings to the contents of a file? @@ -4158,17 +4935,20 @@ bottom of the file: > < This will set the 'shiftwidth' option to 4, when editing that C file. For this to work, the 'modeline' option should be set. By default, the -'modeline' option is set. The 'modelines' settings specifies the number of +'modeline' option is set. An alternative example is given in this document +in the first line. + +The 'modelines' settings specifies the number of lines that will be checked for the Vim set commands. -For more information, read > +For more information, read: + + |21.6| + |modeline| + |auto-setting| + |'modeline'| + |'modelines'| - :help 21.6 - :help modeline - :help auto-setting - :help 'modeline' - :help 'modelines' -< *faq-19.6* 19.6. How do I display the line numbers of all the lines in a file? @@ -4177,28 +4957,24 @@ lines. > :set number < -For more information, read > +For more information, read: + + |'number'| - :help 'number' -< *faq-19.7* 19.7. How do I change the width of the line numbers displayed using the "number" option? -The width used for displaying the line numbers for the 'number' option is -hard-coded in Vim. It is not possible to change this width by setting some -option. - -The request and the patch to add an option to change the number of columns -used for the 'number' option is in the Vim todo list: > +You can set the minimum number of columns to be used for line numbering by +setting the 'numberwidth' option: > - "Add an option to set the width of the 'number' column. Eight - positions is often more than needed. Or adjust the width to the length - of the file? - Add patch that adds 'numberlen' option. (James Harvey) - Other patch with min and max from Emmanuel Renieris (2002 Jul 24) - Other patch without an option by Gilles Roy (2002 Jul 25)" + :set numberwidth=3 < +This set's the width for the line number to 3 digits, which is enough, if +your buffer contains less than 999 lines. However, if your current buffer +contains more lines than 999, the 'numberwidth' will be adjusted accordingly, +so that the maximum line number will fit on the screen. + *faq-19.8* 19.8. How do I display (view) all the invisible characters like space, tabs and newlines in a file? @@ -4227,11 +5003,11 @@ trailing space characters will be displayed with a '.' character. > :set listchars=trail:. < -For more information, read > +For more information, read: + + |'listchars'| + |'list'| - :help 'listchars' - :help 'list' -< *faq-19.9* 19.9. How do I configure Vim to always display the current line and column number? @@ -4241,10 +5017,10 @@ the status line: > :set ruler < -For more information, read > +For more information, read: + + |'ruler'| - :help 'ruler' -< *faq-19.10* 19.10. How do I display the current Vim mode? @@ -4254,10 +5030,10 @@ last line. > :set showmode < -For more information, read > +For more information, read: + + |'showmode'| - :help 'showmode' -< *faq-19.11* 19.11. How do I configure Vim to show pending/partial commands on the status line? @@ -4267,10 +5043,10 @@ status line: > :set showcmd < -For more information, read > +For more information, read: + + |'showcmd'| - :help 'showcmd' -< *faq-19.12* 19.12. How do I configure the Vim status line to display different settings/values? @@ -4278,13 +5054,13 @@ For more information, read > You can set the 'statusline' option to display different values/settings in the Vim status line. -For more information, read > +For more information, read: + + |'statusline'| + |'laststatus'| + |'rulerformat'| + |'ruler'| - :help 'statusline' - :help 'laststatus' - :help 'rulerformat' - :help 'ruler' -< *faq-19.13* 19.13. How do I configure Vim to display status line always? @@ -4292,10 +5068,10 @@ You can set the 'laststatus' option to 2 to display the status line always. > :set laststatus=2 < -For more information, read > +For more information, read: + + |'laststatus'| - :help 'laststatus' -< *faq-19.14* 19.14. How do I make a Vim setting persistent across different Vim invocations/instances/sessions? @@ -4304,15 +5080,15 @@ To make a Vim option setting persistent across different Vim instances, add your setting to the .vimrc or .gvimrc file. You can also use the ":mkvimrc" command to generate a vimrc file for the current settings. -For more information, read > +For more information, read: + + |save-settings| + |vimrc| + |gvimrc| + |vimrc-intro| + |:mkvimrc| + |initialization| - :help save-settings - :help vimrc - :help gvimrc - :help vimrc-intro - :help :mkvimrc - :help initialization -< *faq-19.15* 19.15. Why do I hear a beep (why does my window flash) about 1 second after I hit the Escape key? @@ -4336,10 +5112,10 @@ than the value for the timeout option. Setting the timeout option to a larger value can help alleviate problems that appear when using function keys over a slow line. -For more information, read > +For more information, read: + + |'ttimeout'| - :help ttimeout -< *faq-19.16* 19.16. How do I make the 'c' and 's' commands display a '$' instead of deleting the characters I'm changing? @@ -4349,10 +5125,10 @@ characters, add the $ flag to the 'cpoptions' option: > :set cpoptions+=$ < -For more information, read > +For more information, read: + + |'cpoptions'| - :help 'cpoptions' -< *faq-19.17* 19.17. How do I remove more than one flag using a single ":set" command from a Vim option? @@ -4371,14 +5147,13 @@ remove the flags one by one: > :set formatoptions-=t formatoptions-=n < -For more information, read > +For more information, read: - :help :set-= -< + |:set-=| ============================================================================= *faq-20* -SECTION 20 - MAPPING KEYS +SECTION 20 - MAPPING KEYS ~ *faq-20.1* 20.1. How do I know what a key is mapped to? @@ -4391,22 +5166,26 @@ To see what a key is mapped to, use the following commands: > You can also check the mappings in a particular mode using one of the ":cmap", ":nmap", ":vmap", ":imap", ":omap", etc commands. -For more information, read > +To find out, where the key has been mapped, prefix the :verbose command: > - :help map-listing - :help map-overview + :verbose :map < +For more information, read: + + |map-listing| + |map-overview| + *faq-20.2* -20.2. How do list all the user-defined key mappings? +20.2. How do I list all the user-defined key mappings? You can list all the user-defined key mappings using: > :map < -For more information, read > +For more information, read: + + |map-listing| - :help map-listing -< *faq-20.3* 20.3. How do I unmap a previously mapped key? @@ -4428,31 +5207,107 @@ the unmap command: > :unmap :unmap! < -For more information, read > +For more information, read: + + |:unmap| + |map-modes| + |:map-local| + |mapleader| - :help :unmap - :help map-modes - :help map-local - :help 'mapleader' -< *faq-20.4* 20.4. I am not able to create a mapping for the key. What is wrong? -First make sure that the key is passed to Vim. In insert mode, press CTRL-V -followed by the desired key. You should see the keycode corresponding to -the key . If you do see the keycode, then you can create a mapping for the -key using the following command: > - - :map +1) First make sure, the key is passed correctly to Vim. To determine if + this is the case, put Vim in Insert mode and then hit Ctrl-V (or + Ctrl-Q if your Ctrl-V is remapped to the paste operation (e.g. on + Windows if you are using the mswin.vim script file) followed by your + key. + + If nothing appears in the buffer (and assuming that you have + 'showcmd' on, ^V remains displayed near the bottom right of the Vim + screen), then Vim doesn't get your key correctly and there is nothing + to be done, other than selecting a different key for your mapping or + using GVim, which should recognise the key correctly. + +2) Possibly, Vim gets your key, but sees it as no different than + something else. Say you want to map Ctrl-Right, then in Insert mode + hit Ctrl-K followed by Ctrl-Right. If Vim displays it has + correctly seen the keystroke and you should be able to map it (by + using as your {lhs}). If it displays it has seen + the keystroke but as if you hadn't held Ctrl down: this means your + temrinal passes Ctrl-Right as if it were just . Anything else + means the key has been misidentified. + +3) If the key is seen, but not as itself and not as some recognizable + key, then there is probably an error in the terminal library for the + current terminal (termcap or terminfo database). In that case > + + :set term? +< + will tell you which termcap or terminfo Vim is using. You can try to + tell vim, what termcode to use in that terminal, by adding the + following to your vimrc: > + + if &term == + set = + endif < -For more information, read > + where above should be replaced by the value of 'term' + (with quotes around it) and by what you get when hitting + Ctrl-V followed by Ctrl-Right in Insert mode (with nothing around + it). should be left as-is (9 characters). Don't forget that + in a :set command, white space is not allowed between the equal sign + and the value, and any space, double quote, vertical bar or backslash + present as part of the value must be backslash-escaped. + + Now you should be able to see the keycode corresponding to the key + and you can create a mapping for the key using the following command: > - :help map-keys-fails - :help :map-special-keys - :help key-codes + :map < +For more information, read: + + |map-keys-fails| + |:map-special-keys| + |key-codes| + *faq-20.5* -20.5. How do I map the numeric keypad keys? +20.5. Why does mapping the key not work? + +The only Ctrl-printable-key chords which Vim can reliably detect (because they +are defined in the ASCII standard) are the following: > + + Ctrl-@ 0x00 NUL + Ctrl-A to Ctrl-Z 0x01 to 0x1A + Ctrl-a to Ctrl-z 0x01 to 0x1A + Ctrl-[ 0x1B ESC + Ctrl-\ 0x1C + Ctrl-] 0x1D + Ctrl-^ 0x1E + Ctrl-_ 0x1F + Ctrl-? 0x7F DEL +< +Most of these, however, already have a function in Vim (and some are +aliases of other keys: Ctrl-H and Bsp, Ctrl-I and Tab, Ctrl-M and Enter, +Ctrl-[ and Esc, Ctrl-? and Del). + +The "safest" keys to use in Vim for the {lhs} of a mapping are the F +keys, with or without Shift: to and to . (Some +OSes, including mine, intercept Ctrl-Fn and Alt-Fn, which never reach an +application program such as vim or gvim). + +You can try other combinations of Ctrl + any key, but they may either +not work everywhere (e.g. the terminal might not pass that key to Vim, +or they might have unintended side effects (e.g. mapping means +also to map ). + +This is a known issue, that has been discussed and might be implemented +in the future to enable Vim to distinguish between various keys even in +console mode. (e.g. +https://groups.google.com/d/msg/vim_dev/2bp9UdfZ63M/sajb9KM0pNYJ) + + *faq-20.6* +20.6. How do I map the numeric keypad keys? First make sure that the numeric keypad keys are passed to Vim. Next, you can use the following command to map the numeric keypad keys: > @@ -4462,28 +5317,59 @@ can use the following command to map the numeric keypad keys: > where, can be kHome, kEnd, kPageUp, kPageDown, kPlus, kMinus, kDivide, kMultiply, kEnter, etc. -For more information, read > +For more information, read: - :help key-codes - :help terminal-options -< - *faq-20.6* -20.6. How do I create a mapping that works only in visual mode? + |key-codes| + |terminal-options| -You can create mappings that work only in specific mode (normal, command, + *faq-20.7* +20.7. How do I create a mapping that works only in visual mode? + +You can create mappings that work only in specific modes (normal, command, insert, visual, etc). To create a mapping that works only in the visual mode, use the ":vmap" command: > :vmap < -For more information, read > +This mapping will work in visual and select mode. If you want the map to +work only in visual mode (excluding select mode), use: + > - :help :vmap - :help map-modes - :help 40.1 + :xmap < - *faq-20.7* -20.7. In a Vim script, how do I know which keys to use for my mappings, so +and to have the mapping only work in select mode (but not visual mode), +use: > + + :smap +< +For more information, read: + + |:vmap| + |:xmap| + |:smap| + |map-modes| + |40.1| + + *faq-20.8* +20.8. How do I create a mapping that works only in normal and operator + pending mode (but not in visual mode)? + +Using ":map" creates a mapping that works in normal, visual+select mode and +operator pending mode. You can use ":nmap" to have the mapping only work in +normal mode and ":vmap" to have the mapping only be defined for visual and +select mode or use ":omap" to have the mapping only defined in operator +pending mode. + +But if you want to have a mapping defined, that works in both operator +pending mode and normal mode, but not in visual and select mode, you need +to first define the mapping using ":map" and afterwards delete the mapping +for visual and select mode: + + :map + :vunmap + + *faq-20.9* +20.9. In a Vim script, how do I know which keys to use for my mappings, so that the mapped key will not collide with an already used key? Vim uses most of the keys in the keyboard. You can use the prefix @@ -4509,22 +5395,22 @@ When writing a plugin or other script, more often than not, it is advisable to use :noremap instead of :map to avoid side effects from user defined mappings. -For more information, read > +For more information, read: - :help - :help - :help write-plugin -< - *faq-20.8* -20.8. How do I map the escape key? + || + || + |write-plugin| + + *faq-20.10* +20.10. How do I map the escape key? You can map the Escape key to some other key using the ":map" command. For example, the following command maps the escape key to CTRL-O. > :map < - *faq-20.9* -20.9. How do I map a key to perform nothing? + *faq-20.11* +20.11. How do I map a key to perform nothing? You can map a key to to perform nothing when the key is pressed. For example, with the following mappings, the key will do nothing when @@ -4533,42 +5419,42 @@ pressed. > :map :map! < -For more information, read > +For more information, read: - :help - :help :map - :help :map! - :help map-modes -< - *faq-20.10* -20.10. I want to use the Tab key to indent a block of text and Shift-Tab + || + |:map| + |:map!| + |map-modes| + + *faq-20.12* +20.12. I want to use the Tab key to indent a block of text and Shift-Tab key to unindent a block of text. How do I map the keys to do this? This behavior is similar to textpad, visual studio, etc. Use the following mapping: > - :inoremap + :inoremap :nnoremap >> - :nnoremap + :nnoremap :vnoremap > - :vnoremap + :vnoremap < -Note that, the mapping will work only if Vim receives the correct +Note, that the mapping will work only if Vim receives the correct key sequence. This is mostly the case with GUI Vim. -For more information, read > +For more information, read: - :help :inoremap - :help :nnoremap - :help :vnoremap - :help - :help i_CTRL-O - :help >> - :help << - :help -< - *faq-20.11* -20.11. In my mappings the special characters like are not recognized. + |:inoremap| + |:nnoremap| + |:vnoremap| + || + |i_CTRL-O| + |>>| + |<<| + || + + *faq-20.13* +20.13. In my mappings the special characters like are not recognized. How can I configure Vim to recognize special characters? Check the value of the 'cpoptions' option: > @@ -4582,19 +5468,19 @@ recognized in mappings. Remove the '<' flag from 'cpoptions' option: > < Also, check the value of the 'compatible' option: > - :se compatible? + :set compatible? < The 'compatible' option must be reset: > - :se nocompatible + :set nocompatible < -For more information, read > +For more information, read: - :help 'cpoptions' - :help 'compatible' -< - *faq-20.12* -20.12. How do I use the '|' to separate multiple commands in a map? + |'cpoptions'| + |'compatible'| + + *faq-20.14* +20.14. How do I use the '|' to separate multiple commands in a map? You can escape the '|' character using backslash (\) to use '|' in a map. > @@ -4606,12 +5492,12 @@ You can also try the following command: > < There are also other ways to do this. -For more information, read > +For more information, read: - :help map_bar -< - *faq-20.13* -20.13. If I have a mapping/abbreviation whose ending is the beginning of + |map_bar| + + *faq-20.15* +20.15. If I have a mapping/abbreviation whose ending is the beginning of another mapping/abbreviation, how do I keep the first from expanding into the second one? @@ -4619,13 +5505,13 @@ Instead of using the ":map lhs rhs" command, use the ":noremap lhs rhs" command. For abbreviations, use "noreabbrev lhs rhs". The "nore" prefix prevents the mapping or abbreviation from being expanded again. -For more information, read > +For more information, read: - :help :noremap - :help :noreabbrev -< - *faq-20.14* -20.14. Why does it take a second or more for Vim to process a key, + |:noremap| + |:noreabbrev| + + *faq-20.16* +20.16. Why does it take a second or more for Vim to process a key, sometimes when I press a key? Make sure you have not defined a mapping for this key using the following @@ -4643,18 +5529,18 @@ the next key. If the 'timeout' option is set (which is the default), then Vim will timeout after waiting for the period specified with the 'timeoutlen' option (default is 1 second). -For more information, read > +For more information, read: - :help map-typing - :help 'timeoutlen' - :help 'ttimeoutlen' - :help 'timeout' - :help 'ttimeout' - :help vt100-cursor-keys - :help slow-fast-terminal -< - *faq-20.15* -20.15. How do I map a key to run an external command using a visually + |map-typing| + |'timeoutlen'| + |'ttimeoutlen'| + |'timeout'| + |'ttimeout'| + |vt100-cursor-keys| + |slow-fast-terminal| + + *faq-20.17* +20.17. How do I map a key to run an external command using a visually selected text? You can the ":vmap" command to map a key in the visual mode. In the mapped @@ -4678,16 +5564,16 @@ the visual mode and displayed on the command line. If the visual range is not removed using , then the output from the external command will replace the visually selected text. -For more information, read > +For more information, read: - :help :vmap - :help quote_quote - :help let-register - :help c_CTRL-U - :help :!cmd -< - *faq-20.16* -20.16. How do I map the Ctrl-I key while still retaining the functionality + |:vmap| + |quote_quote| + |:let-register| + |c_CTRL-U| + |:!cmd| + + *faq-20.18* +20.18. How do I map the Ctrl-I key while still retaining the functionality of the key? The Ctrl-I key and the key produce the same keycode, so Vim cannot @@ -4695,14 +5581,94 @@ distinguish between the Ctrl-I and the key. When you map the Ctrl-I key, the key is also mapped (and vice versa). The same restriction applies for the Ctrl-[ key and the key. -For more information, read > +For more information, read: + + |keycodes| + + *faq-20.19* +20.19. How do I define a map to accept a count? + +Use the @= command to use an expression. For example, > + + nnoremap = @='3l' +< +Now you can specify a count to the '=' command. + + |complex-repeat| + + *faq-20.20* +20.20. How can I make my normal mode mapping work from within Insert + Mode? + +Mappings in normal mode can be executed after from insert mode as +well but if there are more commands included in the mapping {rhs}, only the +first one will be executed in normal mode and the rest of {rhs} will be +printed literally in insert mode. One of ways to workaround this problem is +to make {rhs} be one command, via wrapping it to the function. For example: > + + function GetFontNameOfFirstChar() + normal! 0 + echo getfontname() + endfunction +< + :nmap :call GetFontNameOfFirstChar() + +A more technical and detailed solution to this problem follows and can +be found at https://groups.google.com/group/vim_dev/msg/75f1f2dfc00908bb + +Not every normal mode-mapping is automatically suitable for execution via + from within insert mode; you need to explicitly design your mappings +for that purpose. + +The command allows execution of one normal mode command from +within insert mode, then returns to insert mode. If a normal mode mapping +concatenates multiple normal mode commands, this breaks down in temporary +normal mode and literally inserts the second part of the command into the +buffer instead. To support execution of normal mode mappings from within +insert mode, these strategies can be used: + +1) Instead of concatenating multiple normal mode commands, use one :normal + mapping: > + + :nnoremap zC :normal! zCVzC +< +2) Concatenate multiple Ex commands via on the rhs: > + + :nnoremap zC :call MyMap1()call MyMap2() +< +3) Shadow normal mode mappings by insert mode mappings that + re-enter normal mode, then invoke the normal mode mapping: > + + :nnoremap MyMap2 :call MyMap2() + :inoremap