Tuesday, April 10, 2012

Re: gf - How to get back in one hop

El Domingo, 8 de abril de 2012, Roy Fulbright escribió:
> While editing a file, I issue the 'gf' command while the cursor is on a
> file name and the file is opened in the editor. I move around in the newly
> opened file and issue ctrl-o multiple times to retrace my steps back to
> the original file where I ran the 'gf' command. How can I return to the
> original file in one step? I have tried 999ctrl-o, but ctrl-o wants an
> exact number. I can see the number of steps using :jumps and when I enter
> ctrl-o with the exact number I get back to the original file, but I am
> looking for a way to avoid the manual process of getting the number from
> :jumps and then use that number with ctrl-o.

Although changing to the alternate buffer might seem good, there is an even
better solution, but it requires a plugin:

https://github.com/kana/vim-exjumplist.git

By default doesn't map anything, so you will need to do something like:

" hb for 'hop back' and hf for 'hop forward'
nmap <leader>hb <Plug>(exjumplist-previous-buffer)
nmap <leader>hf <Plug>(exjumplist-next-buffer)

That, or define commands that trigger the functions, your choice.

This seems to do exactly what you wanted: go back (or forward) in the jump
list till you change buffer.

BTW, this author has a very nice list of very clever plugins. I recommend
everyone to check them out.

--
Alex (a.k.a. suy) | GPG ID 0x0B8B0BC2
http://barnacity.net/ | http://disperso.net

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: