よく参考にするサイト
今日から少しずつ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
ESCCTRL + V- ↓と↑でライン選択 or ←と→(w/ SHIFT)を使ってより広範囲に。
-
dorx 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の勉強内容まとめ
