About the go forward/back in VIM

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

About the go forward/back in VIM

Joseph WU
Hey all,

I am wondering if there is any key-binding or script to let me go
back/forward between the new position to the original one?

Saying, I am editing the text in the middle of the buffer and wanna go
back to the first line to see what the title is. After I press "gg" to
the first line, I wanna know how to jump back to the original position
to keep going my editing.

I know the "mark"-m works if I make a mark before I jump to somewhere in
the same buffer. But if I have several files to edit, how to go
back/forward between those files? It seems "mark" only works in single
buffer. I have googled for many days, but unfortunately, no answer for
this so far. Does anybody here have good solution?

Thank you in advance.

Joseph
Reply | Threaded
Open this post in threaded view
|

Re: About the go forward/back in VIM

Aaron Griffin
On 8/10/05, Joseph WU <[hidden email]> wrote:
> Hey all,
>
> I am wondering if there is any key-binding or script to let me go
> back/forward between the new position to the original one?

No need for a script... check out ":help jumps"
Reply | Threaded
Open this post in threaded view
|

Re: About the go forward/back in VIM

Pete Johns
In reply to this post by Joseph WU
On Wed, 2005-08-10 at 23:07:07 +0800, Joseph WU sent:

>Hey all,
>
>I am wondering if there is any key-binding or script to let me go
>back/forward between the new position to the original one?
>
>Saying, I am editing the text in the middle of the buffer and wanna go
>back to the first line to see what the title is. After I press "gg" to
>the first line, I wanna know how to jump back to the original position
>to keep going my editing.
>
>I know the "mark"-m works if I make a mark before I jump to somewhere in
>the same buffer. But if I have several files to edit, how to go
>back/forward between those files? It seems "mark" only works in single
>buffer. I have googled for many days, but unfortunately, no answer for
>this so far. Does anybody here have good solution?
>
CTRL-O works a treat, even across old files!

See:

:help jump-motions

Hope this helps;


--paj

--
Pete Johns                                          ICQ: 61363909
http://www.johnsy.com/          MSN: johnsyweb[at]hotmail[dot]com
Tel/Fax: +447092119833       AIM / Jabber / Skype / Y!: johnsyweb
Reply | Threaded
Open this post in threaded view
|

Re: About the go forward/back in VIM

Joseph WU
Hey Aaron and Pete,

Thank you very much! That's absolutely what I want.

Thanks again. :)

Joseph

Pete Johns wrote:

> On Wed, 2005-08-10 at 23:07:07 +0800, Joseph WU sent:
>
>>Hey all,
>>
>>I am wondering if there is any key-binding or script to let me go
>>back/forward between the new position to the original one?
>>
>>Saying, I am editing the text in the middle of the buffer and wanna go
>>back to the first line to see what the title is. After I press "gg" to
>>the first line, I wanna know how to jump back to the original position
>>to keep going my editing.
>>
>>I know the "mark"-m works if I make a mark before I jump to somewhere in
>>the same buffer. But if I have several files to edit, how to go
>>back/forward between those files? It seems "mark" only works in single
>>buffer. I have googled for many days, but unfortunately, no answer for
>>this so far. Does anybody here have good solution?
>>
>
> CTRL-O works a treat, even across old files!
>
> See:
>
> :help jump-motions
>
> Hope this helps;
>
>
> --paj
>
Reply | Threaded
Open this post in threaded view
|

Re: About the go forward/back in VIM

Tim Chase-2
In reply to this post by Joseph WU
> Saying, I am editing the text in the middle of the buffer and
> wanna go back to the first line to see what the title is.
> After I press "gg" to the first line, I wanna know how to jump
> back to the original position to keep going my editing.

There are, as usual with vim, multiple ways to attack the problem.

For simple "go back to where I was before I jumped somewhere
else", you can use ``  (that's "back-tick back-tick").

In addition, you can use ^I and ^O to go forward and backward in
your jump-list.  Vim maintains a list of "large jumps" ("fixed at
100" according to ":help jumplist" where you'll find further info).

If you are inserting some text, hit <esc> and then "gg" to go and
check something at the top of your file, you can then use

        gi

to resume in insert mode where you last left off.  More info on
that can be found at ":help gi"

For yet more options, vim drops marks automatically where you
last inserted (the "^" mark) and where you last made a change was
made (the "." mark) so you can use

        `.

to go the last place you made a change or

        `^

to go the the last place you were in insert mode.

        :help `.
        :help `^

should give you some leads on that one.

Hope this gives you some options for how to do what you want.

-tim