Capt.Redbeard
Capt.Redbeard

Reputation: 790

Browsing through file in vim, return to where I was when done

I am attempting to use VIM as my main code/text editor. I think I am doing fairly well, but there is one thing that is bugging me that, if I cannot find a solution to, will force me back to Sublime.

In Sublime, it is common for me to scan through a file looking at previous function definitions or similar. And then I just move the arrow key left or right and I return to where I was. Is there something I could do in VIM that would imitate this? Maybe even better than this?

I know I could use marks, but that seems rather clunky just to scan and then come back immediately (within 20 seconds or so). Maybe marks would be the way to go.

Any suggestions?

Upvotes: 1

Views: 69

Answers (3)

romainl
romainl

Reputation: 196496

I think you want <C-^> (<C-6> on some keyboard layouts).

But you can try better ways to explore your code base…

Assuming you have an up-to-date tags file and Vim knows where to find it, pressing <C-w>} with the cursor on a function name is a very convenient way to take a look at function signatures without changing context.

The preview window can also be used with an arbitrary tag: :ptag foo or better, with a partial tag name: :ptag /foo.

Upvotes: 0

FDinoff
FDinoff

Reputation: 31419

If you got to the function definition with <c-]> use <C-T> to go back up the tag stack.

More generally <C-O> and <C-I> to navigate the jump list.

Another options would be <C-^> which would bring you to the alternate file.

Take a look at :h tags, :h CTRL-O, :h alternate-file


If you use buffer efficiently you can do :b <buffer number> or :b <filename> to bring you back to the buffer the previous file was in. The numbers can be found with :ls

Look at :h :b

Upvotes: 2

Greg Hewgill
Greg Hewgill

Reputation: 992857

Use one of:

  • CtrlO, which goes back to the last cursor position
  • '., which goes back to the last line where you edited something

Upvotes: 2

Related Questions