Vim for code navigation

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

Vim for code navigation

Ven Tadipatri
  I really want to learn to use vi for navigating through code files.
But I'm running into a couple of issues:
    To jump to a tag I think I should use ctrl+], but if I've changed
the file it keeps prompting me that I need to use ! to override. I
know
I can use '!' for one of the colon commands. How do I do it for ctrl
+]?
Also, I don't want it to blindly jump to the code - if there are
multiple
 matches i want to choose where to go.
     I tried using :ts and :ta but it seems like that's not what I
want
either since it jumps to what's already on the stack. Maybe I need to
make a vi shortcut to push the function I want to go to onto the
stack,
close the new buffer so the tag is still on the stack, then jump to
the
tag that's at the top of the stack?  And also when I close one buffer
(with :bd), it doesn't seem to go back to the position on the line I
last left off on, so maybe I need to make a mark before jumping to
the
function, so I can get back to it?  This seems really cumbersome, and
I'm sure navigating through functions is easier than that.
    Again, the difficulty is that I want to step into a function
without
writing the file that I'm on. I could probably open it with ctrl+w,
then
maximize it. Then when I want to get back, I can just close the
window
instead of popping it off the stack. If I open the function in a new
window with ctrl+w, then hitting ctrl+t on the code I jumped to
results
in the same code appearing in 2 windows, top and bottom.

Thanks,
Ven

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Vim for code navigation

Reid Thompson
On Fri, 2010-09-03 at 09:35 -0700, vtadipatri wrote:

> I really want to learn to use vi for navigating through code files.
> But I'm running into a couple of issues:
>     To jump to a tag I think I should use ctrl+], but if I've changed
> the file it keeps prompting me that I need to use ! to override. I
> know
> I can use '!' for one of the colon commands. How do I do it for ctrl
> +]?
> Also, I don't want it to blindly jump to the code - if there are
> multiple
>  matches i want to choose where to go.
>      I tried using :ts and :ta but it seems like that's not what I
> want
> either since it jumps to what's already on the stack. Maybe I need to
> make a vi shortcut to push the function I want to go to onto the
> stack,
> close the new buffer so the tag is still on the stack, then jump to
> the
> tag that's at the top of the stack?  And also when I close one buffer
> (with :bd), it doesn't seem to go back to the position on the line I
> last left off on, so maybe I need to make a mark before jumping to
> the
> function, so I can get back to it?  This seems really cumbersome, and
> I'm sure navigating through functions is easier than that.
>     Again, the difficulty is that I want to step into a function
> without
> writing the file that I'm on. I could probably open it with ctrl+w,
> then
> maximize it. Then when I want to get back, I can just close the
> window
> instead of popping it off the stack. If I open the function in a new
> window with ctrl+w, then hitting ctrl+t on the code I jumped to
> results
> in the same code appearing in 2 windows, top and bottom.
>
> Thanks,
> Ven
>

investigate using cscope with [g]vim.

--
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
Reply | Threaded
Open this post in threaded view
|

Re: Vim for code navigation

Benjamin Fritz
In reply to this post by Ven Tadipatri


On Sep 3, 11:35 am, vtadipatri <[hidden email]> wrote:

>   I really want to learn to use vi for navigating through code files.
> But I'm running into a couple of issues:
>     To jump to a tag I think I should use ctrl+], but if I've changed
> the file it keeps prompting me that I need to use ! to override. I
> know
> I can use '!' for one of the colon commands. How do I do it for ctrl
> +]?
> Also, I don't want it to blindly jump to the code - if there are
> multiple
>  matches i want to choose where to go.
>      I tried using :ts and :ta but it seems like that's not what I
> want
> either since it jumps to what's already on the stack.

If you give either of these commands an argument, it will jump to that
tag instead of the current top of the stack.

You can make a mapping or just press CTRL-R followed by CTRL-W to
automatically get the word under the cursor.

Actually, you probably want the :tjump command. Or even better, just
set the 'cscopetag' option (a little counter-intuitive) and CTRL-]
will act like :tjump instead of like :tag.

--
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
Reply | Threaded
Open this post in threaded view
|

RE: Vim for code navigation

JohnBeckett
In reply to this post by Ven Tadipatri
vtadipatri wrote:
> To jump to a tag I think I should use ctrl+], but if I've
> changed the file it keeps prompting me that I need to use !
> to override.

You do not want '!' because if you managed to use it, your
changes to the file would be lost. You need to do some reading
about buffers and the 'hidden' option. Try:
http://vim.wikia.com/wiki/Easier_buffer_switching

> Also, I don't want it to blindly jump to the code - if there
> are multiple  matches i want to choose where to go.

Instead of Ctrl-] type:
    g Ctrl-]

John

--
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