Finding your way in vim: tags, cscope, grep and more
stolowski.blogspot.com
stolowski.blogspot.com
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...
I'd also like some more build system integration hooks (e.g. provide project-specific include dirs and CXXFLAGS on a per-file basis).
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...
A useful alias if you need root permissions to save:
cmap w!! w !sudo tee % >/dev/null
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 in such a way that vim looks relative to root's home directory rather than your user's home directory. You may need to copy your ~/.vim directory to ~root/.vim, if ~/.vim is where you've put scriptname and the other things it loads. Or you can move these into a system-wide path that vim searches.
nnoremap <Leader>q :mks!<CR>:qall!<CR>
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.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?
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.
Although I would slightly change it to search upwards until finding a .git directory, and from there the recursive grep :)
The short answer: if you're happy with your productivity in Emacs, then there's likely no compelling reason for you to switch, unless you enjoy the challenge of learning a new text editor.
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.
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.
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.
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.
EDIT: Please, keep going if you really feel that vindictive.