|Perl: the Markov chain saw|
Learn vi/vim in 50 lines and 15 minutesby tachyon (Chancellor)
|on Mar 04, 2004 at 00:05 UTC||Need Help??|
So you need a perl editor. vi/vim (vi-improved) has its advantages. You will find it on virtually any *nix and you can get it for Win32. I syntax higlights perl, C and everything else pretty well. And it is simple to get the basics. So let's begin. We only have 15 minutes, and time is a wastin ;-)
To edit a file with vi/vim do:
vim is better and on many systems if you type vi you actually get vim. Use vim if you possibly can rather than plain old vi. If you did that let's go on..... Vi is a tie died hippy modal editor possibly developed by guys who did too much LSD. But once you get you head around the wierdness it works well. It has 4 MODES.
You are only in one MODE at a time. When you are in a MODE what you type causes different stuff to happen. Escape (ESC at top left of keyboard) will get you out of whatever mode you are in. You will learn to love ESC. Press it lots if needed. It does respond to lots of stabs!!! You will end up back in nav mode which is where you begin. So without further ado let's begin....
Default is nav mode. This is where you start and where you end up with lots of ESC ESC ESC if you get lost. Arrow keys work as expected. In short h j k l move the cursor as well. Direction not entirely intuitive but you get used to it. Try it. You need to be able to feel it rather than have me say this key moves you this way.
Almost all vi commands will take a prefix integer argument. For example typing 12j is the same as typing jjjjjjjjjjjj. In this case you will execute 12 j commands, each one of which moves the cursor down one line, so you will jump down 12 lines. Useful when you mean it, potentially painful if you don't. Examples 5h - left 5 chars, 10j - down 10 lines, 3k - up 3 lines, 7l - right 7 chars. We will use NN to represent an integer argument to a command.
Type a / or a ? and you enter match mode. You will see either a / or a ? at the bottom left of your editor window. Then type almost any perl RE and hit enter. Note there is no trailing / or ? required. The cursor will move to the first match. Hit n to go to the next or NNn to go the the NNth match moving forward.
Type a ? and then almost any perl RE and hit enter - works the same as / but heads towards top of file, so n gets you the match before....
As always ESC gets you back to nav mode.
Type SHIFT+: to enter colon mode. That is shift and the colon key together. Hit ESC key to exit colon mode and get back to nav. Colon appears at bottom left of window. You have 3 main chars you can type (w q !)
You have 2 chars a and i and the shift key adds A and I. From nav mode typing the following enters insert mode at the following position relative to the cursor:
In insert mode when you type 'stuff' it appears at the cursor. Arrows work as normal for navigation if needed. hjkl of course don't navigate you they just type letters. To use the undo key 'u' you need to hit ESC to escape into nav mode, then type undo which will undo all your insert mode edits. If you need to delete just a bit use arrows, backspace and delete as normal.
There is a lot more power than what I have shown you but if you take the time to learn those 20 odd keystrokes you will be able to use vi and perhaps learn more.....happy beeping.