vi commands for the Windows user

This is a cheat sheet for Windows keyboard junkies who feel as out of place in vi as I do. I got most of the vi commands from the rather useful IBM vi tutorial. dd was the only one I ever learnt (and I didn’t know that I could paste after deleting it). There’s loads more vi commands, I’ve just listed the ones that are most similar to Windows ones.

Alot of the vi commands are two letters together e.g. dd. To do these just tap the two letters quickly. N.B. capitalisation matters. So moving to line 100 in vi is 100, Shift+G quickly. But capital G & P are the only two capitals we use.

Update: I’ve just come across this excellent article on learning to speak vim, to get a more in depth understanding.

Quick start

Ctrl+Home = gg
Ctrl+End  = G
Ctrl+x    = dw / dd / dG
Ctrl+c    = yw / yy / yG
Ctrl+v    = p


Command Windows (Notepad) Vi (command mode) Notes
First line Ctrl+Home gg
Last line Ctrl+End G
Line N Ctrl+g, N, Enter Ngg e.g. 100, g, g quickly
End of the line End
  • End
  • $
Start of the line Home
  • Home
  • 0
Next word Ctrl+Right w
Previous word Ctrl+Left b
Page up Pg Up
  • Pg Up
  • Ctrl+u
Ctrl+u acts more similarly to Pg Up in Windows as Pg Up won’t take the cursor all the way to the top in vi.
Page down Pg Dn
  • Pg Dn
  • Ctrl+d
Find text Ctrl+f, [text], Enter (forward)
  • /[regex] (forward)
  • ?[regex] (back)
regex (regular expression): so you need to escape dots and backslashes e.g. \. \/
Replace text Ctrl+h, [search], [replace], Enter (forward)
  • :%s/[search]/[replace]/, Enter (line)
  • :%s/[search]/[replace]/g, Enter (global)
The vi search and replace are regex

Cut, Copy, Paste

Command Windows (Notepad) Vi (command mode) Notes
Delete Delete
  • Delete
  • x
Select Word
  • Double-click word
  • Ctrl+Left, Ctrl+Shift+Right (or vice-versa)
Double-click word
Select Line
  • Left-click in margin
  • Home, Shift+End
  • Home, Shift+Down
Drag mouse over line
Select All
  • Ctrl+a
  • Ctrl+Home, Ctrl+Shift+End
Delete Word Select Word, Delete dw
Delete Line Select Line, Delete dd
Delete rest of line Shift+End, Delete d$
Delete New line
  • End, Delete (next)
  • Home, Backspace (prev)
J (next)
Delete All Select All, Delete gg, dG
Copy Word Select Word, Ctrl+c Select Word, right-click,
yw, p/P
Copy Line Select Line, Ctrl+c y aka ‘Yank’
Copy All Select All, Ctrl+c gg, yG
Cut Word Select Word, Ctrl+x Delete Word
Cut Line Select Line, Ctrl+x Delete Line
Cut All Select All, Ctrl+x Delete All
Paste Ctrl+v
  • p (after cursor)
  • P (before cursor)

Undo, Redo

Command Windows (Notepad) Vi (command mode) Notes
Undo Ctrl+z u
Redo Ctrl+y Ctrl+r

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.