Vim Tips Wiki
(Remove html character entities)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 4: Line 4:
 
|previous=1028
 
|previous=1028
 
|next=1030
 
|next=1030
|created=October 27, 2005
+
|created=2005
 
|complexity=basic
 
|complexity=basic
 
|author=bwana147
 
|author=bwana147
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
I sometimes want to insert text at the beginning of a line, but if I happen to already be at the beginning of that line, I use the <tt>i</tt> command instead of <tt>I</tt>. Then, I realize that the same text has to be inserted at the beginning of other lines as well: I go there and hit ".", and the text gets inserted wherever I am in the line (which of course is seldom the beginning). So I have to "u"ndo, hit "I", retype my text and go one moving around and hit "." whenever I want the same text at the beginning of that line.
+
I sometimes want to insert text at the beginning of a line, but if I happen to already be at the beginning of that line, I use the <code>i</code> command instead of <code>I</code>. Then, I realize that the same text has to be inserted at the beginning of other lines as well: I go there and hit ".", and the text gets inserted wherever I am in the line (which of course is seldom the beginning). So I have to "u"ndo, hit "I", retype my text and go one moving around and hit "." whenever I want the same text at the beginning of that line.
   
 
What bothers me is the retyping. I would like to change the "repeat last command", so that it becomes "insert at the beginning" instead of "insert wherever you happen to be".
 
What bothers me is the retyping. I would like to change the "repeat last command", so that it becomes "insert at the beginning" instead of "insert wherever you happen to be".
   
Here comes the <tt>".</tt> register. All I do now, is "u"ndo to remove the text that was wrongly inserted in the middle of the line, hit "I" to start inserting at the beginning of the line, then <C-R>. (that's Ctrl-R followed by a dot), which inserts whatever I had just inserted with the "i" command, and <Esc>, of course.
+
Here comes the <code>".</code> register. All I do now, is "u"ndo to remove the text that was wrongly inserted in the middle of the line, hit "I" to start inserting at the beginning of the line, then <C-R>. (that's Ctrl-R followed by a dot), which inserts whatever I had just inserted with the "i" command, and <Esc>, of course.
   
 
Now the "repeat command" (.) will rightfully insert at the beginning of the lines where I invoke it, and I didn't have to retype my inserted text in full.
 
Now the "repeat command" (.) will rightfully insert at the beginning of the lines where I invoke it, and I didn't have to retype my inserted text in full.
Line 23: Line 23:
 
Is this the same as
 
Is this the same as
 
*do edit in wrong place
 
*do edit in wrong place
*undo, go to beginning of line, repeat with <tt>u0.</tt>
+
*undo, go to beginning of line, repeat with <code>u0.</code>
   
 
----
 
----
Line 44: Line 44:
   
 
----
 
----
<tt><C-R>.</tt> is better done as <tt><C-A></tt> see {{help|i_CTRL-A}}.
+
<code><C-R>.</code> is better done as <code><C-A></code> see {{help|i_CTRL-A}}.
   
 
----
 
----

Latest revision as of 06:04, 13 July 2012

Tip 1029 Printable Monobook Previous Next

created 2005 · complexity basic · author bwana147 · version 5.7


I sometimes want to insert text at the beginning of a line, but if I happen to already be at the beginning of that line, I use the i command instead of I. Then, I realize that the same text has to be inserted at the beginning of other lines as well: I go there and hit ".", and the text gets inserted wherever I am in the line (which of course is seldom the beginning). So I have to "u"ndo, hit "I", retype my text and go one moving around and hit "." whenever I want the same text at the beginning of that line.

What bothers me is the retyping. I would like to change the "repeat last command", so that it becomes "insert at the beginning" instead of "insert wherever you happen to be".

Here comes the ". register. All I do now, is "u"ndo to remove the text that was wrongly inserted in the middle of the line, hit "I" to start inserting at the beginning of the line, then <C-R>. (that's Ctrl-R followed by a dot), which inserts whatever I had just inserted with the "i" command, and <Esc>, of course.

Now the "repeat command" (.) will rightfully insert at the beginning of the lines where I invoke it, and I didn't have to retype my inserted text in full.

Comments[]

Is this the same as

  • do edit in wrong place
  • undo, go to beginning of line, repeat with u0.

This tip lets you use '.' after the first fix. Your suggested solution requires you to do '0.' every time you want to insert the line again.


See also :help gI.


I finally sussed this useful tip.

  • do edit in wrong place
  • u to undo
  • I to insert at beginning of line
  • <C-R>. to insert undone text

Now dot works fine.

uI<C-R>.<Esc>j.

<C-R>. is better done as <C-A> see :help i_CTRL-A.