Wikia

Vim Tips Wiki

Changes: Have . restore the cursor position a la emacs in viper mode

Edit

Back to page

(Fix typos)
(Remove html character entities)
 
Line 25: Line 25:
   
 
<pre>
 
<pre>
cwbar&lt;cr&gt;j.j.
+
cwbar<CR>j.j.
 
</pre>
 
</pre>
   
Line 54: Line 54:
   
 
----
 
----
&gt;You can also use the following mapping, that doesn't modify the z mark
+
>You can also use the following mapping, that doesn't modify the z mark
   
&gt;noremap . .'^
+
>noremap . .'^
   
 
Wouldn't this be:
 
Wouldn't this be:

Latest revision as of 08:46, September 29, 2008

Tip 474 Printable Monobook Previous Next

created May 14, 2003 · complexity basic · author Brett Williams · version 6.0


Before making the switch to Vim, I spent time in limbo using EMACS in viper mode (which is EMACS with vi emulation). Despite the vast improvements in most areas, there were a few things I missed from EMACS. One thing I really missed was the behavior of the . command, which always restored the cursor position.

For example, let's say I had the following:

foo.some_method.each do { |x| puts x }
foo.some_other_method(Time.now)
foo.close()

and I wanted to change foo to bar. I would always use a cw and then the . command:

cwbar<CR>j.j.

rather than making a substitute command which would make me worry about the range over which it should take place etc.

When making the switch to Vim, I was disconcerted because after the first . my cursor was at the end of the second 'bar'.

In fact I pretty much always wanted this behavior from '.', so this mapping helped me out:

"make . not move the cursor
noremap . mz.`z

I've since noticed this is just a special case of the tip *restore-position* in the help manual, but it took me a while to find out how to do this. One other former emacs/viper user also was searching for this. Hopefully this tip makes it easier for the next person to find who finally finds their way out of EMACS.

CommentsEdit

You can also use the following mapping, that doesn't modify the z mark

noremap . .'^

When changing the text you always have several ways of how to specify the text to change.

You can change a word by typing cw at the beginning of the word. However I would prefer ciw - using text objects.

It was the "dot" command that made me to start using text objects aw, iw, ap, ip, etc. :help objects


>You can also use the following mapping, that doesn't modify the z mark

>noremap . .'^

Wouldn't this be:

noremap . .`[

The backtick jumps the cursor to the correct column.


Around Wikia's network

Random Wiki