sponsor Vim development Vim logo Vim Book Ad

basic Tip #629: After quitting VIM, comeback to the same file position where you were while quitting.

 tip karma   Rating -10/15, Viewed by 1784 

Read and edit this tip on the Vim tip wiki. The wiki may have a more recent version of this tip.

created:   January 2, 2004 3:21      complexity:   basic
author:   Smart opening and closing      as of Vim:   5.7

many a times while editing a big file we may temporarily want to go to command prompt and
open the same file again. Then again you will be in the first character of the file. This is a smarter tip for
taking the cursor to the same position where you were while quitting.

Just when you want to quit VIM instead of pressing ESC :q   just press ctrl+z. You can see this
[1]+  Stopped                 vim <filename>

you are in command prompt now. Do your work and when u want to return to VIm press fg.

Thats it.

 rate this tip  Life Changing Helpful Unfulfilling 

<< Execut "things" in Win98 from within VIM | usefull for  programming >>

Additional Notes

drNchip@OcampSbellPfamilyA.bizM, January 2, 2004 7:19
In order to exit vim and return later to the file at the same file position, see vimtip#80.
Anonymous, January 5, 2004 2:55
May be using '0 or `0 is easier? :)
sgs_ocp@yahoo.com, January 7, 2004 1:03
Hi
i don't know exactly how but my VIM 6.2 on win 2k saves position when i re open the file !
i use :wq to save and exit
Romland, January 8, 2004 3:42
...and if you found this interesting you might also find that you can open more VIMs at the command prompt and suspend those too (with ctrl-z). Then to see a list of all suspended VIMs (processes) you type 'jobs'.

Might look something like this:
fnurt@iblam[www]$ jobs
[1]-  Stopped                 vim foo
[2]+  Stopped                 vim bar

To return to either of the processes just type %1 for the first one and %2 for the second one and so forth.

cheers.
da_infamous_one@hotmail.com, February 5, 2004 8:06
....unfortunately you cannot suspend processes like that in windows.

Another solution to edit multiple files in vim is to use vim's multiple buffers.

Just place the following in your .vimrc file

map <M-Left> :bN!<CR>
map <M-Right> :bn!<CR>
map <M-Up> :buffers<CR>

Just load up all your files in vim, by recursive :e command or at prompt vim *
Now you can cycle through your multiple buffers by pressing the alt-left or alt-right.
Oh and alt-up will show your buffer list...

enjoy.
da_infamous_one@hotmail.com, February 5, 2004 8:06
....unfortunately you cannot suspend processes like that in windows.

Another solution to edit multiple files in vim is to use vim's multiple buffers.

Just place the following in your .vimrc file

map <M-Left> :bN!<CR>
map <M-Right> :bn!<CR>
map <M-Up> :buffers<CR>

Just load up all your files in vim, by recursive :e command or at prompt vim *
Now you can cycle through your multiple buffers by pressing the alt-left or alt-right.
Oh and alt-up will show your buffer list...
mmr@b1n.org, February 5, 2004 10:58
Well, that is not a VIM issue. That is shell's behavior (ie. its environment dependent).

Honestly, this tip is pretty useless for non-unix users.

Read this tip: http://vim.sourceforge.net/tips/tip.php?tip_id=80 if you want something really clever.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to vim@vim.org after searching the archive. Help Bram help Uganda.
   
Sponsored by Web Concept Group Inc. SourceForge.net Logo