0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Linux][command] エディタ_vi

Last updated at Posted at 2025-02-02

入力モード

コマンド 由来 説明
i insert カーソル前で入力モードに移行
I Insert at beginning 行頭で入力モードに移行
a append カーソル後で入力モードに移行
A Append at end 行末で入力モードに移行
o open below 現在行の下に新しい行を開いて入力モードに移行
O Open above 現在行の上に新しい行を開いて入力モードに移行

コマンドモード: 入力→コマンド = Esc

カーソル操作

コマンド 由来 説明
h ← left 左へ1文字移動
l → right 右へ1文字移動
k ↑ up 上へ1行移動
j ↓ down 下へ1行移動
0 beginning of line 行頭へ移動
$ end of line 行末へ移動
H Head of screen 画面の先頭へ移動
L Low of screen 画面の最下部へ移動
gg go to the beginning of file ファイルの先頭へ移動
G go to the end of file ファイルの末尾へ移動
nG
:n
go to line n n 行目へ移動
Ctrl+b backward 1ページ分前へ移動
Ctrl+f forward 1ページ分先へ移動

終了・保存

コマンド 由来 説明
:q quit 保存せずに vi を終了(未保存の変更があるとエラー)
:q! quit (force) 変更を破棄して強制終了
:w write ファイルを保存
:wq
:x
ZZ
write & quit ファイルを保存して vi を終了
:wq! write & quit (force) ファイルを保存して vi を強制終了

編集

コマンド 由来 説明
yy
Y
yank line カレント位置のをコピー
yw yank word カーソル位置の単語をコピー
dd delete line カレント位置のを削除
dw delete word カーソル位置の単語を削除
x delete カーソル位置の文字を削除
X delete backward カーソル位置の前の文字を削除
p put after カーソル位置の後にバッファの内容を貼り付け
P put before カーソル位置の前にバッファの内容を貼り付け
. repeat (dot) 直前の変更操作を繰り返す
u undo 直前の操作を取り消す

検索・置換

コマンド 由来 説明
?検索文字列 backward search カーソル位置から前方に向かって検索文字列を検索します。
/検索文字列 forward search カーソル位置から後方に向かって検索文字列を検索します。
n next 検索後、次の一致箇所に移動します。
N previous 検索後、前の一致箇所に移動します。
:%s/A/B/ substitute 最初に一致したAをBに置換(各行ごとに1か所だけ)
:%s/A/B/g substitute globally 各行のすべてのAをBに置換

シェルコマンドの実行

コマンド 由来 説明
:r ファイル read ファイルの内容を現在のカーソル位置に挿入する
:! コマンド shell command シェルコマンドを一時的に実行(vi を抜けずに使える)
:r! コマンド read + shell シェルコマンドの出力結果をカーソル位置に読み込む

設定

コマンド 由来 説明
:set nu
:set number
number 行番号の表示
:set nonu
:set nonumber
no numbrt 行番号の非表示
:set ts=タブ幅
:set tabstop=タブ幅
tab stop タブ幅を数値で指定

読み取り専用

$ vi -R ファイル名

Ping-t

全般

入力モード

カーソル操作

終了・保存

編集

検索

シェルコマンドの実行

設定

読み取り専用

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?