This link has been bookmarked by 467 people and liked by 1 people. It was first bookmarked on 17 May 2007, by Fadzlan.
-
01 Jun 20
-
02 Dec 18
-
15 Jun 17
-
Commands in vi/vim are meant to be combined - 'd' means delete, 'e' means 'move to end of word', then 'de' is a complete command that deletes to the end of the current word (something like Ctrl-Shift-Right, Left, Del in most regular editors).
-
One good benefit of this is that the '.' command repeats the last complete, combined editing command (not movement commands). After doing 'dw', '.' will act as a command to delete to the beginning of the next word. You can move around at will with all the powerful navigation commands, and press '.' at will to delete to the next word quickly. This turns out to be incredibly powerful.
-
What this means is that if you type 'iHello<Esc>', which enters the text 'Hello' at the cursor's position, what now '.' does is "Type 'Hello' at the cursor's position".
-
But it's better than this. 'A' goes to the end of the current line and enters insert mode there. So, after completing the insert by pressing <Esc>, you can press '.' anywhere to go to the end of the line and do the same thing.
-
S' to delete to the end of line, etc... all of them entering insert mode afterwards) so
-
And now you have to repeat this with the other two. How do you do it? Easy: first, press 'j' to move the cursor down. And then, press '.' to repeat the last full editing command (the 'A' command with the backspace and the inserted text). If you do 'j.j.', that is, twice, you get the following:
-
editing operations being pretty repetitive. But think about it, how much of your daily editing is repetitive? Yeah, I thought so.
-
right. Not with vi or vim. The '%' motion moves from a parenthesis (or similar grouping character) to its matching one - but if you're not positioned at one of these special characters, it will scan chara
-
-
29 May 17
-
21 Nov 16
-
19 Jul 16
-
03 Jul 16
-
01 May 16
-
27 Apr 16
-
14 Apr 16
-
24 Mar 16
-
15 Jul 15
-
12 Jul 15
-
- One- or two-key motions to move directly anywhere on the line, or on the screen
- Operators such as 'd' or 'c' that can be combined with any motion to directly modify some text and maybe enter insert mode, and being able to repeat it all as many times as you wish with '.'
- Anything can be done without moving your hands away from home row! No more suffering when editing on a laptop with a braindead keyboard layout (most of them)
the main power of vi, and the power that you can't live without after you've got used to it, is the power of the basic editing model:
-
-
26 Mar 15
-
laptop with a braindead keyboard layout (most of them)
-
-
04 Jan 15
-
24 Sep 14
-
normal mode, and only
-
-
04 Aug 14
-
29 Jul 14
-
22 Jun 14
-
27 May 14
-
21 May 14
-
06 May 14
-
07 Apr 14
-
You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press <Esc> to go to normal mode.
-
But you never think about insert mode as a mode where you stay.
-
'.' command repeats the last complete, combined editing command
-
Example #1: the wonderful dot command
-
press '.' to repeat the last full editing command
-
Misconception #2: it's not all about regular expressions
-
move directly anywhere on the line, or on the screen
-
Operators such as 'd' or 'c' that can be combined with any motion
-
Example #2: smart ranges
-
The '%' motion moves from a parenthesis
-
it will scan character by character to the right, until the first one is found, and then moving to the character matching that one.
-
since we have it in the clipboard, we can use Ctrl-R, " to paste it in insert mode
-
Misconception #3: you gotta be nuts and/or a genius to use it
-
Example #3: manipulating delimited blocks
-
How do you select the text inside
-
'i' or 'a' (they can only be used after an operator like 'd' or 'c')
-
'i>' refers to "the current 'i'nner angle bracket block", so you can do 'di>'
-
(or even 'b' from 'b'lock)
-
or 'a' to include the delimiting characters too.
-
Misconception #4: hjkl to move around?
-
'f' followed by any other character to find its next occurrence
-
']]' and the likes to navigate by functions, etc.
-
Example #4: nice commands
-
'zt', 'zz' and 'zb' keep the cursor a
-
'H'ighest, 'M'iddle, or 'L'ower line on the screen
-
'*' searches forward for the next occurrence of the word under the cursor ('#' does the same backward
-
Misconception #5: since you are thinking 90% of the time, and editing 10%, the productivity gain might be there, but it's useless anyway
-
I'll wager that this is wrong.
-
Example #5: indenting a block
-
'>aB' ("indent a Block")
-
Misconception #6: it's just sticking to a disappearing past
-
Example #6: visual nature
-
Correct-conception #1: steep learning curve
-
Closing words
-
-
25 Mar 14
-
07 Mar 14
-
04 Mar 14
-
15 Dec 13
-
06 Oct 13
-
22 Sep 13
-
05 Jun 13
-
29 Mar 13
-
27 Mar 13
-
05 Mar 13
-
30 Jan 13
-
03 Jan 13
-
16 Dec 12
-
11 Nov 12
-
14 Sep 12
-
17 Jul 12
-
You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press <Esc> to go to normal mode.
-
And now we come to insert commands. These commands enter insert mode and let you type text until you press <Esc>. Ok, in the case of these commands, the full command includes all the text you typed between 'i' (or whatever command you used to enter insert mode, as there are several) and <Esc>
-
let's take the 'ce' command
-
It's the same as 'd', but with the distinction that it enters insert mode, instead of staying in normal mode
-
Knowing about the 'c' command, which deletes the extents of the next motion (also copying it to the clipboard) and enters insert mode, we can type just 'c%' ("change match") from the above case and we get the following
-
After typing di> ("delete inner angle-block")
-
n other editors, you move around, you select, you type TAB or the shortcut to auto-indent. Not so with vim, just three keystrokes: '>aB' ("indent a Block") and you get this:
-
-
08 Jul 12
-
14 Apr 12
-
04 Apr 12
-
07 Feb 12
-
'.' command repeats the last complete, combined editing command
-
-
06 Feb 12
-
04 Feb 12
-
03 Feb 12
-
02 Feb 12
-
rishabh Sharmaince you're already probably used to other editors, and if the arrow keys work in insert mode (they do i
-
-
You are always in normal mode, and only enter insert mode for short bursts of typing text, after which you press <Esc> to go to normal mode
-
Commands in vi/vim are meant to be combined
-
the '.' command repeats the last complete, combined editing command
-
-
24 Jan 12
-
29 Dec 11
-
06 Nov 11
-
25 Oct 11
-
23 Oct 11
-
you never think about insert mode as a mode where you stay.
-
The boon is that the text you type in the next (short) input session is also part of the command.
-
And this during this period of editing, you are feeling a tremendous sensation of power.
-
-
27 Sep 11
-
31 Aug 11
-
28 Aug 11
-
28 Jul 11
-
07 Jun 11
-
09 May 11
-
08 Apr 11
-
17 Mar 11
-
05 Mar 11
-
06 Feb 11
Kenneth A. DrakeYes, there are definite reasons why the vi/vim editing model
is just superior to any other out there. And you don't need to be a
Unix whiz to use it, either: vim is available for free for almost any
platform out there, and there are plug-ins to get the fu -
03 Feb 11
-
17 Jan 11
-
19 Dec 10
-
18 Dec 10
-
15 Dec 10
-
25 Nov 10
-
22 Nov 10
-
21 Sep 10
-
17 Sep 10
-
13 Sep 10
-
11 Sep 10
-
27 Aug 10
-
12 Aug 10
-
30 Jul 10
-
29 Jul 10
-
08 Jun 10
-
21 May 10
-
29 Apr 10
-
28 Apr 10
-
27 Apr 10
-
10 Apr 10
-
02 Apr 10
Would you like to comment?
Join Diigo for a free account, or sign in if you are already a member.