Vim Tips Wiki
(Move categories to tip template)
(Remove html character entities)
Line 16: Line 16:
 
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 &lt;C-R&gt;. (that's Ctrl-R followed by a dot), which inserts whatever I had just inserted with the "i" command, and &lt;esc&gt;, of course.
+
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.
   
 
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 36: Line 36:
 
*u to undo
 
*u to undo
 
*I to insert at beginning of line
 
*I to insert at beginning of line
*&lt;C-R&gt;. to insert undone text
+
*<C-R>. to insert undone text
   
 
Now dot works fine.
 
Now dot works fine.
 
<pre>
 
<pre>
uI&lt;C-R&gt;.&lt;ESC&gt;j.
+
uI<C-R>.<Esc>j.
 
</pre>
 
</pre>
   
 
----
 
----
<tt>&lt;C-R&gt;.</tt> is better done as <tt>&lt;C-A&gt;</tt> see {{help|i_CTRL-A}}.
+
<tt><C-R>.</tt> is better done as <tt><C-A></tt> see {{help|i_CTRL-A}}.
   
 
----
 
----

Revision as of 23:47, 29 September 2008

Tip 1029 Printable Monobook Previous Next

created October 27, 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.