Linux/Unix チュートリアルのコマンドを使用した VI エディタ
⚡ スマートサマリー
The vi editor is the classic, universally available text editor of Linux and Unix, working entirely through the keyboard in two modes: a command mode for actions and an insert mode for typing テキスト。

The vi editor is the text editor you will meet on almost any Linux or Unix machine, so learning its keyboard-driven workflow is a skill that transfers everywhere. This guide explains its two modes, its editing commands, and how to save and quit a file.
What is the vi editor?
The vi editor is the most popular and classic text editor in the Linux family. Below are some of the reasons that make it a widely used editor:
- It is available in almost all Linux distributions.
- It works the same across different platforms and distributions.
- It is user-friendly, so millions of Linux users rely on it for their editing needs.
Nowadays there are advanced versions of the vi editor available, and the most popular one is VIM, which stands for Vi Improved. Some of the others are Elvis, Nvi, Nano, and Vile. It is wise to learn vi because it is feature-rich and offers endless possibilities to edit a file.
vi Editor Operation Modes
To work on the vi editor, you need to understand its operation modes. They can be divided into two main parts: command mode and insert mode. The screenshot below shows the vi editor open in a Linux terminal.
vi Command Mode
- The vi editor opens in this mode, and it only understands commands.
- In this mode you can move the cursor and cut, copy, and paste text.
- This mode also saves the changes you have made to the file.
- Commands are case-sensitive, so you should use the right letter case.
vi Insert Mode
- This mode is for inserting text into the file.
- You can switch to insert mode from command mode by pressing ‘i’ on the keyboard.
- Once you are in insert mode, any key is taken as input for the file you are currently working on.
- To return to command mode and save the changes you have made, press the Esc key.
viエディタの使い方
To launch the vi editor, open the terminal (CLI) and type:
vi <filename_NEW> or <filename_EXISTING>
If you specify an existing file, the editor opens it for you to edit. Otherwise, it creates a new file. The screenshot below shows a new file being created and edited in vi.
VI編集コマンド
The vi editing commands below let you insert, delete, and change text. Use them from command mode.
| Command | 詳細説明 |
|---|---|
| i | カーソル位置に挿入 (挿入モードになります) |
| a | カーソルの後に書き込み (挿入モードになります) |
| A | 行末に書き込みます (挿入モードになります) |
| ESC | 挿入モードを終了する |
| u | 最後の変更を元に戻す |
| U | 行全体に対するすべての変更を元に戻す |
| o | 新しい行を開きます (挿入モードになります)。 |
| dd | 行を削除 |
| 3dd | 3行削除 |
| D | カーソル以降の行の内容を削除します |
| C | カーソル以降の行の内容を削除し、新しいテキストを挿入します。 ESC キーを押して挿入を終了します。 |
| dw | 単語を削除 |
| 4dw | 4 単語を削除 |
| cw | 言葉を変える |
| x | カーソル位置の文字を削除 |
| r | 文字を置き換える |
| R | カーソル以降の文字を上書きする |
| s | Substitute one character under the cursor and continue inserting |
| S | Substitute entire line and begin inserting at the beginning of the line |
| ~ | 個々の文字の大文字と小文字を変更する |
注意: You should be in command mode to execute these commands. The vi editor is case-sensitive, so make sure you type the commands in the right letter case. Pressing the wrong command can make undesirable changes to the file. You can also enter insert mode by pressing a, A, or o as required.
ファイル内での移動
You need to be in command mode to move within a file. The default navigation keys are listed below, but you can also use the arrow keys on the keyboard.
| Command | 詳細説明 |
|---|---|
| k | Move cursor up |
| j | Move cursor down |
| h | Move cursor left |
| l | Move cursor right |
ファイルを保存して閉じる
You should be in command mode to exit the editor and save changes to the file. The commands below cover the common ways to save and quit.
| Command | 詳細説明 |
|---|---|
| Shift+zz | Save the file and quit |
| :w | Save the file but keep it open |
| Q! | Quit vi and do not save changes |
| :WQ | Save the file and quit |
The screenshot below shows a file open in the vi editor, ready to be saved and closed.

.jpg)

