Vim Tips Wiki
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
FANDOM
Explore
Current Wiki
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Vim Tips Wiki
1,649
pages
Explore
Main Page
All Pages
Community
Interactive Maps
Community portal
To do
Editing
Repeat last command and put cursor at start of change
Back to page
Edit
Edit source
View history
Talk (0)
Edit Page
Repeat last command and put cursor at start of change
We recommend that you
log in
before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your
Watchlist
.
Creating an account
is quick and free.
The edit appears to have already been undone.
Anti-spam check. Do
not
fill this in!
{{review}} {{TipImported |id=1142 |previous=1141 |next=1146 |created=2006 |complexity=basic |author=Adam Wolff |version=5.7 |rating=38/19 |category1=Usage |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: <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: <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== I like that tip. I made something similar to the . <pre> :map <a-.> <Down>. </pre> knowing this tip I will change it to <pre> :map <a-.> `[<Down>. </pre> 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: <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.) 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: <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... 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: <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 "." Here's the true solution: <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)
Summary:
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Templates used on this page:
Template:Help
(
view source
)
Template:Navigation
(
view source
)
Template:Review
(
view source
)
Template:TipImported
(
view source
)
Follow on IG
TikTok
Join Fan Lab