This document is a scratchpad for helping me learn commonly used actions in Xcode's VIM mode.
Commands are case-sensitive. A command of N
means pressing shift + n
on the keyboard.
[Formatting is a WIP]
Vim Input | Xcode Standard | Action |
---|---|---|
h | ← | move left |
l | → | move right |
k | ↑ | move up |
j | ↓ | move down |
0 | ↖ | move to first character in line |
$ | ↘ | move to last character in line |
^ | ⌘← | move to first non-whitespace character in line |
g0 | ⌘←← | goto before first non-whitespace character in line |
g_ | ⌘→ | goto to last printed character in line |
gg | ⌘↑ | goto to first line in file |
G | ⌘↓ | goto to last line in file |
% | - | move to matching character in pair, e.g. {} , () |
{ | - | jump to next paragraph above |
} | - | jump to next paragraph below |
Vim Input | Xcode Standard | Action |
---|---|---|
w | ⇧→ | jump forward to start of word |
W | ⌃→ | jump forward to start of Word, ignoring punctuation |
e | - | jump forward to end of word |
E | - | jump forward to End of word, ignoring punctuation |
b | ⇧← | jump backward to start of word |
B | - | jump Backward to start of word, ignoring punctuation |
Actions that scroll the code viewport without moving the cursor.
Vim Input | Action |
---|---|
zz | scroll viewport to center on current line |
zt | scroll line to top of viewport |
zb | scroll line to bottom of viewport |
H | move cursor to top of viewport |
M | move cursor to middle of viewport |
L | move cursor to bottom of viewport |
Actions that scroll the code viewport by moving the cursor.
Vim Input | Action |
---|---|
^e | scroll one line down |
^y | scroll one line up |
^d | scroll one half page down |
^u | scroll one half page up |
^f | scroll one page forward |
^b | scroll one page back |
Vim uses yank
as a naming convention analgous to the copy
clipboard command. The delete command is analogous to the cut
command as it places the deleted content into a buffer that can be pasted.
Vim Input | Xcode Standard | Action |
---|---|---|
yy | – | Copies the current line and places it into a buffer that can be used with p to paste. |
y | – | Copies characters from the current cursor position. |
Y | – | Copies the entire line at the cursor position. |
p | – | Pastes characters copied from y or d commands at the current cursor position. |
P | – | Pastes characters copied from y or d commands before the current cursor position. |
Vim Input | Xcode Standard | Action |
---|---|---|
dP |
N/A | Pressing d begins a delete that matches a selection based on the next position command of P . For example, dw deletes all characters jumping forward to the start of the next word. Usable for most all cursor position commands such as w , e , b , B . |
dd | ⌘D | Deletes the current line. |
dN |
N/A | Deletes N number of lines where N from the cursor position. e.g.: d5 deletes the next 5 lines. |
D | – | Deletes characters to the end of the line from the current cursor position. |
x | – | Deletes the character at the current cursor position. |
X | Backspace | Deletes the previous character from the character position. |
Vim Input | Xcode Standard | Action |
---|---|---|
f{char} | - | move to next character ahead of cursor in line |
F{char} | - | move previous character behind cursor in line |
t{char} | - | move behind next character ahead of cursor in line |
T{char} | - | move ahead of next character behind cursor in line |
; | - | repeat previous f, t, F or T movement |
, | - | repeat previous f, t, F or T movement, backwards |
Vim Input | Action |
---|---|
vP |
Selects text up to the next position, P . e.g. ve selects from the cursor to the end of the word. |
V | Selects the current line. Subsequent position commands will extend the selection. Very handy for beginning multi-line selections and edits. |
NOTE:
Xcode will drop the current selection after the action is performed, which makes these commands not as good as a standard Xcode indentation command with ⌘+([
or ]
) which retains the selection. Its really only useful for making the indent once, unlike the built-in action which can indent multiple times.
Vim Input | Action |
---|---|
<< | Indent line(s) left |
>> | Indent line(s) right |
Vim Input | Action |
---|---|
~ | Changes the case of the character at the cursor position and moves the cursor to the next character. |
Vim Input | Xcode Standard | Action |
---|---|---|
u | ⌘z | Undo last action. |
N u |
– | Undo last N number of actions. e.g. 3u undo 3 times. |
^r | ⌘Z | Redo last action |
Vim Input | Xcode Standard | Action |
---|---|---|
/ | ⌘f | Begin a forward text search. |
? | ⌘G | Begin a backward text search. |
n | ⌘g | Move to next search result. |
N | ⌘G | Move to previous search result. |
Vim Input | Action |
---|---|
i | "Insert here". Enter visual mode at the start of the current cursor position. |
a | "Append here". Enter visual mode at the end at the current cursor position. |
I | "Insert at start". Enter visual mode at the beginning of the line. |
A | "Append at end". Enter visual mode at the end of the line. |
Vim Mode | Action |
---|---|
esc | exit to normal mode |
Below are tips for using and combining the commands in VIM to perform common actions.
O
- add a new line above the cursor and enter insert mode
o
- add a new lnie below the cursor and enter insert mode
ce
- Edit from cursor to end of word and replace
v$
- Select from cursor to end of line
Basic finding
/
Start the find, enter the text to fnid and pressEnter
n
andN
to move between the occurences found in the file
Replace
vey
- Selects a word and yanks (copies) itviwp
- Selects a word and puts (pastes) the copied text
To copy 2 lines…
2yy
- Copies 2 lines
To cut 2 lines
2cc
- Cuts two lines