Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After a :windo, how do I get the cursor back where it was?

Tags:

vim

Seems that :windo leaves my cursor in the bottom window.

How can I get it to return to the window and cursor-position I was at before I ran :windo?

I thought mZ, then `Z would work. But it just brings that file into the bottom window, instead of moving me back to where I was.

Running 7.3.462 on Win XP.

Thanks

like image 369
shaggyaxe Avatar asked Sep 01 '25 01:09

shaggyaxe


1 Answers

You could save buffer and view:

let saved_bufnr = bufnr("%")
let saved_view  = winsaveview()

and use it to restore the exact position (after argdo, bufo, windo, tabdo, global or any combination of those)

exec 'buffer ' . saved_bufnr
call winrestview(saved_view)

Note This effectively uses the plumbing that underlies the standard :mkview, :mksession functionality too. If you really wanted to restore all windows/tabs, by all means just use

:mksession! /tmp/tmpsession.vim
:# do the work
:source /tmp/tmpsession.vim
like image 190
sehe Avatar answered Sep 04 '25 08:09

sehe