Apr 19 2009

Learning ViEmu, part 3

Category: zvolkov @ 12:17

Repeatable command sequences

Generally speaking, commands can be repeated by pressing . (dot).This is useful when you want to apply the same change to multiple lines (assuming it can't be done with basic find and replace and you don't feel like writing a RegEx).

Note that standalone moves, like w or t. are repeated using a different command: ; and incremental search is repeated by pressing n. This makes sense as whole point of the repetition is to move to the new place, repeat the command, move again, repeat again -- if standalone moves used same repetition buffer as edit commands they would overwrite the last edit command and therefore make this sequence impossible. Enough of this pseudo-deep analysis though. Let's see some examples:

de -- this is same de that we've learned last time. Now you can go nuts and delete everything till the end of the word by pressing . at your heart's desire.

i[Hello][Esc] -- types something, for example Hello. Not very exciting but still, repeatable!

A;[Esc] -- adds ; at the end of the line. Hope you recognize A command.

I[Tab][Esc] -- adds tabulation in front of the line. Repeat this for each line in the block you want to indent. I know I know in normal editors you can select and press Tab to indent the whole block.

ce[Boo][Esc] -- this will delete the rest of the word, go to the insert mode, type Boo, and switch back to the Command mode. Pressing . repeats the sequence which is now "replace rest of the word with Boo".

c%q[Esc] -- when standing on an opening bracket of any kind ({[ replaces everything up until and including the closing one with "q" (or any other text). Since c is actually the Cut command, it also places the whole () block in the clipboard.

ci(xyz[Esc] -- This is a weird one. Here, i does not mean Insert mode. Instead it means Inside the parenthesis. So this sequence Cuts the text Inside parenthesis you're standing in and replaces it with "xyz". It also works inside square and figure brackets -- jus do ci[ or ci{ correspondingly. Naturally, you can do di( if you just want to delete all text without typing anything. You can also do a instead of i if you want to delete the parentheses as well and not just text inside them.

ciw - cuts the current word. This works just like the previous one except that ( is replaced with w.

ci" - cuts the text in current quotes

Indentation

Finally, solved this one! Here's how you do it:

To indent/unindent the current line just press >> or << (with Shift!) -- no need to select nor move cursor no nothing!

5>> -- indent next 5 lines

To indent entire block, stand anywhere inside the block you'd like to indent, feet at shoulders width. Then press >i{ to indent all text inside the block (exluding the figure brackets) or >a{ to indent everything including the brackets. It's kind of powerful. My only problem with this is having to press Shift with > and { but not with i. You can do B instead of { (B stands for Block) but that still requires two Shifts.

 

Other cool commands

C - cut the rest of the line and switch to Insert mode.

ZZ -- save and close current file (WAY faster than Ctrl-F4 to close the current tab!)

ddp - move current line one row down

xp -- move current character one position to the right

U - upercase, so viwU upercases the word

~ - switches case, so viw~ will reverse casing of entire word

The End

Let's live with these crazy commands for a week and see if they fly.

P.S. Check out the last post in the series.

Tags:

Comments

1.
trackback Yesterday's news says:

Learning ViEmu, part 2

Learning ViEmu, part 2

Comments are closed