よく参考にするサイト
今日から少しずつsublimeからvimへと移行していく際にググったことや勉強になったことなどを自分のモチベーションが続くまで書き続けていこうと思います。
aside from the fact that motivation and demotivation are two sides of the same coin.
basics
-
/[word]
or?[word]
で単語検索 -
i
でテキスト編集開始 -
:
でエディットモード閉じる
Insert mode: hit i
to initiate
Normal mode: what you hit the escape key to get to
-
gg
でカーソルを一番上に持っていく *equivalent of command + ↑ -
shift + g
で一番下へ *equivalent of command + ↓ -
w
でカーソルを次の単語に持っていく -
b
で一単語戻る -
control + f
で画面単位で下へ -
control + b
で画面単位で上へ -
^
で行の始まりへ -
$
で行末へ -
f + 1st letter of word to get to
で行きたい単語の始まりへ - ↑の候補が複数ある場合は
;
を押して次に行ける -
%
で対応する括弧まで飛ぶ -
shift + v
で行ごと選択 -
control + v
で自由に選択 -
:undolist
で今まで編集履歴確認 -
ctrl + r
がctrl + z
の反対。= redo -
x
でカーソル上の文字をカット -
dd
でカーソルがある行をまるごとカット -
[arbitrary num]dd
で消したい行数だけカット - (カットしたもしくはコピーしたものを)
p
で貼り付け -
yy
でカーソルがある行をまるごとコピー -
[num]yy
で指定した行数分だけコピー -
/[word to look up for]
で単語検索 - 単語検索後
n
で下へ(下にある候補へ)N
で上へ -
*
でカーソルがある位置の単語を検索(下方向) -
#
でカーソルがある位置の単語を検索(上方向) -
:s/[word]/[word to replace with]
でカーソルがある行の指定した単語/文字を書き換え -
:s/[word]/[w to replace with]/g
でカーソルがある行の指定した物全てを書き換え -
:%s/[w]/[wrw]/g
でファイル上の単語全てを書き換え -
:sv <file name>
でsplit layout (vertically) -
:tabnew
で新しいタブを作成 -
:tabe [file name]
で指定したスクリプトを新たなタブとして開く -
.
でひとつ前に行った処理をもう一度 -
ctrl+n
で入力候補を出す -
:%s/foo/bar/g"スクリプトないすべての
fooを
bar`に変換 -
:%s/foo/bar/gc"スクリプトないすべての
fooを
barに変換(w/ confirmation)変えたい
fooの数 != スクリプト内全ての
foo`のときとかに便利。 -
ciw
で現在選択している単語を消してそのままInsert Modeへ。 -
dd
でカーソルのある行を削除。 -
D
で同じ行でカーソル以降の単語を全て削除。
tricks
- スクリプト内のコード全選択:
gg
+shift v
+shift g
- 全選択してインデントを直す:
gg + shift+v + shift+g + =
- 選択箇所を一気に編集:
ctrl + v
で挿入/編集箇所を選択しshit + i
を押して編集をしてesc
To comment out/uncomment blocks in Vim
to comment out
ESC
-
CTRL + V
(visual block mode) - ↓と↑でライン選択
SHIFT + i
#
ESC
to uncomment
ESC
CTRL + V
- ↓と↑でライン選択 or ←と→(w/ SHIFT)を使ってより広範囲に。
-
d
orx
ESC
split windows/multiple windows
- 横分割:
CTRL + W, S
*upper case s - 縦分割:
CTRL + W, v
*lower case v - 画面移動:
CTRL + W
,CTRL + W
vimrc
-
vi ~/.vimrc
でvimのファイルを開いてここで色々ショートカットキーの調整etcが行える -
set number
を追加すればライン番号が反映される - 例えばpythonを頻繁に使う人は
au FileType python set
でpythonのファイルを専用のキーを設定出来る。 - vimに移行した途端に謎の
TabError: inconsistent use of tabs and spaces in indentation
が出てきた場合はこちら - タブを
ctrl tab
で回れるようにしたい場合はこちら
おすすめplug-ins
ref
- How to avoid indentation error after changing tab stops in Vim?
- How To Show Line Numbers In vi / vim Text Editor
- ドットインストール
- How do I do redo (i.e. “undo undo”) in Vim?
- Vim keyboard shortcut to move around tabs
- What's a quick way to comment/uncomment lines in Vim?
- How to open files in vertically/horizontal split windows in Vim from the command line
- Search and replace
- これまでのVimの勉強内容まとめ