Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm starting to learn Vim, and following some of the advices given here in stackexchange. I'm beginning to use it in some toy projects and I'm cool with that.
But I started to wonder how you can be productive without opening other files all the time just to know how's that class' Name, what's that macro included in other file, etc. etc.

What are the common advices you can give?

share|improve this question
1  
You will definitely need to add some Vim scripts to help out. I use Vim to program alot, and I always use ctags to help me navigate around the source code. What language are using? –  tehnyit Nov 10 '11 at 22:17
add comment

5 Answers

I do all my programming in vim. I actually find it easier than any IDE I've used. You can have multiple files open at the same time, even on the same screen (look up tabs and windows). I'm usually working in X, so I have several (6) xterm screens open: one for c files in vim (several in tabs), another for headers in vim (also tabs), and non-vim windows: build, debug, configuration, etc. Even when I'm on a pure console, I can use tabs, windows, and code folding to see what I need, and I can build, and even view manpages without exiting vim, you just need to know the right commands. And there are so many, I'm sure I haven't even mastered half of them. And it's hard to beat vim's search and replace.

share|improve this answer
add comment

Many large-scale applications have been (of mine, at least, two ;) , and my guess is, many more will be written completely in Vim. IDEs as such are still a rather modern innovation, so to speak.

However, plain vanilla vi (ouch) or Vim are a bit lacking. Knowing Vim and thinking in some of its ways help a bit, and plugins help a lot, for which www.vim.org is an endless source of. Some specific to the language you're using, and some general ones (for commenting, for file browsing, for ...) turn it quickly into a very rapid development environment. After all (and some will surely argue) an IDE is just an editor with plugins packed in a nicer interface. There isn't much graphical stuff in an IDE either.

share|improve this answer
add comment

One aspect of experienced programmers who move from an IDE to a console / xterm environment, is finding a replacement for the indexing of source code objects (function names, variables). I believe the general term used for Microsoft's Visual Studio is Intellisense or something like that.

In the Unix/Linux world, such as vim, one tool used if ctags or the popular multiple language Open Source implementation, exuberant ctags. It is not vim specific, and is supported by a number of Unix, Linux, MS Windows, Mac OS text editors, including Emacs, CRiSP, vile & a number of other vi clones, nedit, gedit, JED, UltraEdit, BBEdit, and DreamWeaver (some of these are via third-party plugins).

Beyond that, good design and thoughtful decomposition, organization of larger projects makes the project manageable in that there are only 1-2 obvious potential places to look for any given bit of information (typedef or class definitions, etc.).

Also I use multiple instances of vim (often via view for read-only viewing of source files), as well as a limited use of multiple edit buffers per vim instance (primarily for moving or refactoring code between files). I find using only a few source files open at a time can help in its own small way, to keep me focused on the task on hand.

share|improve this answer
1  
+1 for suggesting exuberant ctags! –  Attila O. Nov 11 '11 at 0:43
1  
I find that just being organized helps a lot. If you can look at an artifact in source and say "Oh that must be defined in this place" then things get a lot simpler. On the plus side starting up vim sessions is so fast that having a half dozen open at once becomes a pretty normal thing –  Zachary K Nov 11 '11 at 4:31
    
@ZacharyK Half dozen? I usually have a full dozen by the end of the day –  Izkata Nov 11 '11 at 17:52
    
depends on the day –  Zachary K Nov 12 '11 at 16:09
add comment

In my opinion, Vim gives you a very strong editor with basic features, but it's up to you to spice it up with scripts/addons you'll most likely use in your projects. These will probably be different depending on whether you mostly edit scripts, documentation, or files that need to be compiled.

As an example, I use zencoding for the occasional html/css editing, snipmate for Textmate-like snippets, and a couple of python-related add-ons (pyflakes, pep8, vimpdb, etc.) for Python coding, which is what I do most often.

Then there are other addons that I don't use often, but I still find them helpful every once in a while, like Dpaste and ConqueTerm.

Still, to me, the most useful features of Vim are built-in (time-based undo, quick navigation, range filters, etc.) - things that I couldn't find (or at least are not that easy-to-access) in IDEs. So once you set up your Vim to have the bits and pieces of an IDE that you really need (snipmate, ctags...) you can get the benefit from both IDE and console environments.

My use of Vim is console-only, so I can't say how helpful these tools are with Gvim.

Despite all the addon goodness, however, I still find myself running !grep ... or ^Z + find ... every now and then.

share|improve this answer
add comment

I don't intent to be part of VIM vs. IDE debate. I guess that is personal pref. But i use a lot of VIM and here is why i find it very powerful to use vim

Two parts of the answer:

A. Most things VIM allows most thing you can do with IDEs,(i am not trying to put every feature but just a few non-obvious that make vi look limiting)

  1. you can go traverse the prototypes if you have ctags enabled and do ctrl+{

  2. You can open multiple windows simultaneously sing :sp 'filename' command. Of course, sometime i just open multiple terminals to make life more easy.

  3. Powerful syntax highlighting. Default as well as other stuff. Also, unlike some IDEs, if there is a mismatch of open braces, string or don't match with closed ones, gives you a very clear indication. It is for most languages rather than specific.

  4. You can execute command line using command ":!make" without going out of window.

  5. Traverse much faster based on word, based on search (vi support regexp if you are available), and you can traverse { to } using ESC %

  6. It is possible to do work in GDB while doing step debugging and keeping vi (in other window to work on the code). When you decide to change the file, you can make again and reload it in GDB.

B. Many things you find it better in VIM

  1. Search and replacement is definitely much more powerful.

  2. You can create your custom look and feel and (black+green as oppsed to white+blue) and more importantly your own powerful command.

  3. Vertical Block select. Try ctrl+v and move cursor vertically. This is truly an unimaginable feature!

  4. Sounds wiered -but try to cut/copy a block and having to past it 30 times! It takes no more effort than doing it 1 time. Also, try to redo (not undo) an activity one or multiple times.

  5. Auto indenting, tab control and automated way to convert your comments in block comments or comments of particular styling.

  6. Effective merge conflict with vimdiff.

  7. The most important thing with console based work environment is that you never touch the MOUSE! so if you are fast on key board- IDE's are no good.

  8. Work on multiple machines, servers simultaneously! Doesn't look obvious but sometimes when you work on server, you directly login in multiple machines and do things.

Will answer about how to do in vi if those features are in serious demands. See this site Vimcast. of course, there are many.

But yes, most console based stuff is old fashioned, and in no way i am saying anything against IDEs.

share|improve this answer
    
Small note: vim has a :make command built in, you don't even need the ! (which, for those who don't use vim, executes a command on the terminal). And I just found ctrl-v a couple weeks ago and now I use it constantly, it's incredibly useful. –  Kevin Nov 11 '11 at 15:29
    
@Kevin - ok i didn't knew about <code>:make</code>! This was exciting to know. This is a kind of romance you get with VIM - one cannot ever make a full list of features that VIM can ever let you do!! It always keeps surprising you. Thanks. –  Dipan Mehta Nov 11 '11 at 15:58
    
Yeah, it's great like that. The advantage of :make is that it automatically moves you to the first error, and you can navigate them with cn and cp, see :help make. I actually didn't realize that until I looked it up; I usually make in a different window and pwd, it seems you have to be in the same one as the Makefile, though you could put one in the src directory just to move to the root and make there. –  Kevin Nov 11 '11 at 16:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.