Live data from Hacker News

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

stolowski.blogspot.com

11–20 of 34 posts

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

#11

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

[deleted]

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

#12

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

For C and C++, clang_complete gives pretty good completion.

https://github.com/Rip-Rip/clang_complete

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

#13

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

That's because the whole problem is trivial in Python. What he's talking about is jumping to the correct version of an overloaded function and similar.

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

#14
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?

You should learn VIM for the same reasons a Haskell programmer should learn Common Lisp. Not because you don't already have an extremely powerful tool. Just because there are other extremely powerful tools and the perspective is worth it.

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

#15
post #8

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

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?). Based on what you've said, I'm not sure if this is an sudo issue or a vim issue. Where is scriptname, and where are the files that scriptname references? Your sudoers may be set up to replace the environment…

It might be worth running :cd in the sudo vim instance and in the regular one. Your sudo current directory could well be different to your own which would explain vim not being able to find the script.

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

#16
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?

My experience is this: Emacs has better integration to tools (like debuggers, etc).

However, I like the Vim input model, where you combine commands (like delete or yank) to a motion (like a word, 3 words or everything inside these parentheses).

Emacs has the Viper mode, which gives basic Vi-style input model but it doesn't do advanced stuff like text objects.

IMO any serious coder should try both, Vim and Emacs and see which one works better.

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

#17
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 next to no experience with Emacs so from the perspective of a 'normal' text-editor-using-guy Vim is (Warning, some slight exaggeration ahead) one of the greatest things I have discovered, learnt and now use daily.

Why? I can do simple things faster (Delete a single char, delete a line, search/replace, etc.), it seems like a more logical way to write, and so on.

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

#18
Using cscope, ctags and grep with Vim's location list and quickfix list has been a huge productivity booster for me. I highly recommend experimenting with different key bindings to ease navigating with tags other search results (:cnext :cprev :lnext :lprev, etc).

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

#19
post #10
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?

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.

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

#20

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

For C and C++, clang_complete gives pretty good completion. https://github.com/Rip-Rip/clang_complete

I like where this is going, but it was a bit unstable for my taste last I tried it. I think it still relies on the file being syntactically correct, which may break your parsing sometimes and is still quite slow with template-heavy code (Boost mostly). Is it still the case?

I'd also like some more build system integration hooks (e.g. provide project-specific include dirs and CXXFLAGS on a per-file basis).

Post reply on HN