Vim Tips Wiki
Register
No edit summary
 
(Change <tt> to <code>, perhaps also minor tweak.)
 
(12 intermediate revisions by 7 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=1142
 
|id=1142
  +
|previous=1141
|title=map . to .__OPENBRACKET__'
 
  +
|next=1146
|created=February 20, 2006 9:23
+
|created=2006
 
|complexity=basic
 
|complexity=basic
 
|author=Adam Wolff
 
|author=Adam Wolff
 
|version=5.7
 
|version=5.7
 
|rating=38/19
 
|rating=38/19
  +
|category1=Usage
|text=
 
  +
|category2=
I rely on this behavior so much, I'm always surprised when I use VIM on a system that doesn't have this map installed:
 
 
}}
 
I rely on this behavior so much, I'm always surprised when I use Vim on a system that doesn't have this map installed:
  +
<pre>
 
nmap . .`[
  +
</pre>
   
 
This changes the behavior of the very useful . command to leave the cursor at the point where it was before editing started. This means that if I have, say, a list of files from a change summary that look like this:
nmap . .`[
 
  +
<pre>
 
.../foo/bar/pick.c
 
.../cram/bar/yup.c
 
.../drop/bar/slop.c
  +
</pre>
   
 
And I want to change the leading path, I can go to the first one, and type (say) c3t/anotherdir<Esc> This gives me:
  +
<pre>
 
anotherdir/pick.c
 
.../cram/bar/yup.c
 
.../drop/bar/slop.c
  +
</pre>
   
 
Now I can just go the beginning of the second line and hit <code>.j.</code> to change the second and third lines. Of course you could also use a regexp for stuff like this, but often . is a little faster and saves precious brain cells. See {{help|.}}.
   
 
==Comments==
This changes the behavior of the very useful . command to leave the cursor at the point where it was before editing started. This means that if I have, say, a list of files from a change summary that look like this:
 
 
I like that tip. I made something similar to the .
  +
<pre>
  +
:map <a-.> <Down>.
  +
</pre>
   
 
knowing this tip I will change it to
.../foo/bar/pick.c
 
  +
<pre>
  +
:map <a-.> `[<Down>.
  +
</pre>
   
 
So you can do changes in more than one line with repeating only one key.
.../cram/bar/yup.c
 
   
 
Sometimes it is useful to make changes like this with a Visual Block, but in this example, shown in the tip, it doesn't work. See {{help|v_b_I}} {{help|v_b_A}}.
.../drop/bar/slop.c
 
   
 
----
 
I use this to make changes to a visual block:
  +
<pre>
 
vnoremap <silent> . :normal .<CR>
  +
</pre>
   
 
If you do something like this on a line:
  +
<pre>
 
Aline ending<Esc>
  +
</pre>
   
 
(Basically, adding 'line ending' to the end of the line.)
And I want to change the leading path, I can go to the first one, and type (say) c3t/anotherdir&lt;ESC&gt; This gives me:
 
   
 
You can then visually select a bunch of lines and hit . to have the same happen to each of them.
anotherdir/pick.c
 
   
.../cram/bar/yup.c
 
 
.../drop/bar/slop.c
 
 
 
 
Now I can just go the beginning of the second line and hit .j. to change the second and third lines. Of course I could you can also use an RE for stuff like this, but often . is a little faster and saves precious brain cells.
 
 
 
 
[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:}} :help ].
 
 
 
}}
 
 
== Comments ==
 
I like that tip. I made something similar to the .
 
:map &lt;a-.&gt; &lt;down&gt;.
 
knowing this tip I will change it to
 
:map &lt;a-.&gt; `[&lt;down&gt;.
 
So you can do changes in more than one line with repeating only one key
 
 
Sometimes it is usefull to made changes like this with a visual Block, but in this example, shown in the tip, it doesn't work
 
:h v_b_I
 
:h v_b_A
 
 
info at jochen minus behrens de
 
, February 21, 2006 11:26
 
 
----
 
----
 
There is a very useful feature of Vim built it for doing these kinds of edits. Take the original example for instance:
I use this to make changes to a visual block:
 
  +
<pre>
 
.../foo/bar/pick.c
 
.../cram/bar/yup.c
 
.../drop/bar/slop.c
  +
</pre>
   
 
Instead of changing the first one and repeating the change for the other lines...
vnoremap &lt;silent&gt; . :normal .&lt;CR&gt;
 
   
  +
Visually select the desired text using ctrl-v. Then with them visually selected (in this case the leading .'s would be selected) press c and then type the new text. It will appear to only be changing the first line however once you hit escape it will apply the change to all the lines.
If you do something like this on a line:
 
   
 
No extra commands and no remapping needed. Works everywhere.
Aline ending&lt;esc&gt;
 
   
 
For a better description of all the things you can do with the visual block stuff, see {{help|blockwise-operators}}.
(Basically, adding 'line ending' to the end of the line.)
 
   
You can then visually select a bunch of lines and hit . to have the same happen to each of them.
 
 
salmanhalim--AT--hotmail.com
 
, February 21, 2006 20:53
 
 
----
 
----
There is a very useful feature of vim built it for doing these kinds of edits.
 
   
  +
This throws E19 if you do
Take the original example for instance:
 
  +
:exe "normal d\<Up>G."
.../foo/bar/pick.c
 
  +
and it changes the jumplist.
.../cram/bar/yup.c
 
.../drop/bar/slop.c
 
Instead of changing the first one and repeating the change for the other lines...
 
Visually select the desired text to be chanaged "Visual block" mode ( usually ctrl-v )
 
Then with them visually selected ( in this case the leading .'s would be selected )
 
Press c
 
Then type the new text. It will appear to only be changing the first line however
 
once you hit escape it will apply the change to all the lines.
 
   
  +
Here are some changes that fix both:
No extra commands and no remapping needed. Works everywhere.
 
  +
<s>nnoremap <expr> . line(".") == line("$") ? "." : ".g`["</s>
  +
[[User:Andres.p|Andres.p]] 04:27, December 8, 2010 (UTC)
   
  +
'''EDIT''': Actually, I was anticipating the position after "."
montumba--AT--gmail.com
 
, February 22, 2006 14:48
 
----
 
For a better description of all the things you can do with the visual block stuff
 
just do
 
   
  +
Here's the true solution:
[http://vimplugin.sf.net/cgi-bin/help?tag={{urlencode:blockwise-operators}} :help blockwise-operators]
 
  +
<pre>
  +
function! ResDot(count)
  +
execute "normal!" count . "."
  +
if line("'[") <= line("$")
  +
normal! g`[
  +
endif
  +
endfunction
   
  +
nnoremap <silent> . :<C-U>call ResDot(v:count1)<CR>
 
  +
</pre>
 
  +
[[User:Andres.p|Andres.p]] 05:14, December 8, 2010 (UTC)
montumba--AT--gmail.com
 
, February 22, 2006 14:54
 
----
 
<!-- parsed by vimtips.py in 0.547239 seconds-->
 

Latest revision as of 06:09, 13 July 2012

Tip 1142 Printable Monobook Previous Next

created 2006 · complexity basic · author Adam Wolff · version 5.7


I rely on this behavior so much, I'm always surprised when I use Vim on a system that doesn't have this map installed:

nmap . .`[

This changes the behavior of the very useful . command to leave the cursor at the point where it was before editing started. This means that if I have, say, a list of files from a change summary that look like this:

.../foo/bar/pick.c
.../cram/bar/yup.c
.../drop/bar/slop.c

And I want to change the leading path, I can go to the first one, and type (say) c3t/anotherdir<Esc> This gives me:

anotherdir/pick.c
.../cram/bar/yup.c
.../drop/bar/slop.c

Now I can just go the beginning of the second line and hit .j. to change the second and third lines. Of course you could also use a regexp for stuff like this, but often . is a little faster and saves precious brain cells. See :help ..

Comments[]

I like that tip. I made something similar to the .

:map <a-.> <Down>.

knowing this tip I will change it to

:map <a-.> `[<Down>.

So you can do changes in more than one line with repeating only one key.

Sometimes it is useful to make changes like this with a Visual Block, but in this example, shown in the tip, it doesn't work. See :help v_b_I :help v_b_A.


I use this to make changes to a visual block:

vnoremap <silent> . :normal .<CR>

If you do something like this on a line:

Aline ending<Esc>

(Basically, adding 'line ending' to the end of the line.)

You can then visually select a bunch of lines and hit . to have the same happen to each of them.


There is a very useful feature of Vim built it for doing these kinds of edits. Take the original example for instance:

.../foo/bar/pick.c
.../cram/bar/yup.c
.../drop/bar/slop.c

Instead of changing the first one and repeating the change for the other lines...

Visually select the desired text using ctrl-v. Then with them visually selected (in this case the leading .'s would be selected) press c and then type the new text. It will appear to only be changing the first line however once you hit escape it will apply the change to all the lines.

No extra commands and no remapping needed. Works everywhere.

For a better description of all the things you can do with the visual block stuff, see :help blockwise-operators.


This throws E19 if you do

:exe "normal d\<Up>G."

and it changes the jumplist.

Here are some changes that fix both:

nnoremap <expr> . line(".") == line("$") ? "." : ".g`["

Andres.p 04:27, December 8, 2010 (UTC)

EDIT: Actually, I was anticipating the position after "."

Here's the true solution:

function! ResDot(count)
    execute "normal!" count . "."
    if line("'[") <= line("$")
        normal! g`[
    endif
endfunction

nnoremap <silent> . :<C-U>call ResDot(v:count1)<CR>

Andres.p 05:14, December 8, 2010 (UTC)