Live data from Hacker News

Finding your way in vim: tags, cscope, grep and more

stolowski.blogspot.com

21–30 of 34 posts

Re: Finding your way in vim: tags, cscope, grep and more

#21
tags and cscope look excellent.

However, for the grepping and general file searching stuff, wouldn't that be better done from the shell? I generally have both vim (either MacVim, or shell-vim) running, as well as a the command line sitting in a window right next to it.

What's the advantage of doing the searching inside vs. outside vim?

Re: Finding your way in vim: tags, cscope, grep and more

#22

tags and cscope look excellent. However, for the grepping and general file searching stuff, wouldn't that be better done from the shell? I generally have both vim (either MacVim, or shell-vim) running, as well as a the command line sitting in a window right next to it. What's the advantage of doing the searching inside vs. outside vim?

If you search from inside vim, it will load the results into the quickfix list. This means that it jumps you to the first result, and `:cn` and `:cp` will take you to the next and previous results, respectively.

This is much easier than searching in a terminal, noting the first filename (which may be buried in some directory), opening it in vim, then jumping/scrolling down to the relevant line.

Re: Finding your way in vim: tags, cscope, grep and more

#23
post #6

I find VIM so difficult to get my head around. Emacs seems to make more sense.. is there any point in trying to grok VIM?

I have not used Emacs, but Vim feels incredibly powerful to me. I feel that I can tell it what to do in a very natural way: "change inside parentheses", or "delete from here to the word 'foo'," or "replace 'bar' with 'baz' inside the current set of curly braces."

Most of my time in code is spent moving around, editing and refactoring. Vim fits that: "Normal" mode puts an entire keyboard of commands at my disposal for for moving around and editing - no need to press Control or something to say "watch out, I'm going to issue a command!" Of course I am - that's what I mainly do. If I actually want to type, I go into insert mode.

I have written the beginnings of a book to explain the power of Vim, if you'd like to check it out. I'd love any feedback anyone wants to give.

http://nathanmlong.com/vanquish/

Re: Finding your way in vim: tags, cscope, grep and more

#24

tags and cscope look excellent. However, for the grepping and general file searching stuff, wouldn't that be better done from the shell? I generally have both vim (either MacVim, or shell-vim) running, as well as a the command line sitting in a window right next to it. What's the advantage of doing the searching inside vs. outside vim?

Saves a few steps jumping from hit to hit, and if you set up next-result and previous-result mappings, it's even faster. This is assuming your workflow is "find, then open one or more of the results in vim."

Re: Finding your way in vim: tags, cscope, grep and more

#25

tags and cscope look excellent. However, for the grepping and general file searching stuff, wouldn't that be better done from the shell? I generally have both vim (either MacVim, or shell-vim) running, as well as a the command line sitting in a window right next to it. What's the advantage of doing the searching inside vs. outside vim?

Its faster, because with one key you're searching for the word under the cursor, and you're already on the editor, where the probable next action (editing) on the results is going to be run.

Although I would slightly change it to search upwards until finding a .git directory, and from there the recursive grep :)

Re: Finding your way in vim: tags, cscope, grep and more

#26

Maybe somebody could help me to figure out how to save files properly with vim. I made a script that opens all the files I need. I call the script with: :source scriptname. Only problem is that the script works only if I open vim with 'vim' and not with 'sudo vim' (by the way, why is that?). But if I open with 'vim', then it give me problem when I try to save...

You might try using sessions instead. In my vimrc, I have this line:

    nnoremap q :mks!:qall!
And in my .bashrc I have this line:

    alias vv=vim -S
Once you have all the files you want open and arranged the way you like, save it all and then hit \q to save the session and quit. Then, instead of vim, use vv to go right back to your session. That's how I do it, anyway.

Re: Finding your way in vim: tags, cscope, grep and more

#28
post #19
post #10

Earlier quoted context omitted.

Speaking as a longtime vim user, not if you already grok Emacs. The one really good reason I can think of is that vi is pretty much ubiquitous on *nix and might be better suited if you need a powerful editor which you can almost always expect to be there for you even over ssh.

I know this point has been beaten to death, but in that case you only need to know/grok vi, a significantly smaller subset of vim.

Granted.

Under vi(1), the ctags example in the article is a constructive activity.

In the case of cscope, one needs to drive a development session from cscope then drop into vi to make edits.

Re: Finding your way in vim: tags, cscope, grep and more

#29

> A word of caution first: there is no perfect symbol-based navigation for programming languages such as C++ or Java in vim, as vim doesn't perform any syntax analysis of the code. At least for Python, Vim's OmniCompletion does a reasonable job of figuring out function names: http://vimdoc.sourceforge.net/htmldoc/version7.html#new-omni...

Same thing for php. I really don't want to use Eclipse, but its a pain navigating source code using cscope. For instance, if you are looking for a method definition, it may list hundreds of matches. It has no notion of semantic analysis. It doesn't know what class is calling the particular method and if you're looking for something like $instance->execute, you're screwed.

Re: Finding your way in vim: tags, cscope, grep and more

#30

tags and cscope look excellent. However, for the grepping and general file searching stuff, wouldn't that be better done from the shell? I generally have both vim (either MacVim, or shell-vim) running, as well as a the command line sitting in a window right next to it. What's the advantage of doing the searching inside vs. outside vim?

Vim shells out for that, but it understands the format of results returned by the programs, which makes it easy to jump around in them.
Post reply on HN