Archive

Posts Tagged ‘editor’

vi Cheat Sheet

July 4th, 2011 subogero Comments off

I’ve just reached a very severe stage of the disease called Unix. I’m learning vi.

I still vividly remember the shock when a command-line Linux expected me to edit something and kindly opened up vi for me. I did not know how to exit, so I had to shut down the computer.

After using pagers (more or less) and manual pages for some time, I slowly learned a few important hotkeys like “/pattern” to search forward for something, “n” to find the next match and “q” to quit. Playing the command-line version of robots, one quickly memorizes “h”, “j”, “k” and “l” for navigation. It turns out they all come from vi. Or vice versa.

But before going on, I’d like to enlighten my readers about quitting vi:

:q<Enter>   Quit
:q!<Enter>  Quit and discard changes
:wq<Enter>  Save and quit
ZZ          Save and quit

Now that quitting is out of the way, let me tell you about a few highlights of my steepish vi learning curve. It seems the usefulness of Unix tools is proportional with their scariness.  Same as with git.

Those 1-2-letter commands are quite logical, actually, usually consisting of a command and a move, eg “dw” stands for delete word.

Let’s take moving around in the window. After scrolling down a few pages, you find the interesting line, but it’s in the bottom of the screen along with the cursor. Command “z.” will put it in the middle.

When you try to select something with a Windows-style editor, you press Shift at the beginning, keep it pressed and move around with the arrows. Then you realize the beginning is at the wrong position. You can start over.

In vi, on the other hand, you press “v” for visual selection, move around to find the end of the highlighted block. Then you notice the beginning is wrong. Press “o” for opposite, your block’s end will get fixed and the cursor jumps to the beginning, which you can now move around. Astonishing!

And now to something completely different: the vi Cheat Sheet!

vi Chet Sheet

vi Cheat Sheet

Bonus: I was always wondering what text editor I should install onto my Android phone. I’ve just realized that busybox-vi has been there all the time. It works perfectly with the crude virtual keyboard.

Bonus 2: my ~/.vimrc file with syntax highlight, line numbers, autoindent, highlight search results and, most importantly, brighter foreground colours.

syntax on
set number
set autoindent
set hlsearch
set background=dark
Categories: Uncategorized Tags: , , , ,