Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Vim editor very smart?

Tags:

java

c++

vim

editor

I am programming in C++ or Java. So I want to use Vim editor, because it is very flexible. I have heard that I can configure the Vim editor to be able to go

  1. from object to the definition
  2. from function to the definition
  3. from class name to the definition

Do we have any professional Vim-er that could tell me exactly how to configure Vim for that? Thanks in advance.

P.S. In case readers will consider this question is not connected with programming, I would say that this is improving speed of programming. So it is a help to the programmer. So please don't close this question.

EDIT: Also I would like to know how vim works with code completion and can vim hint the list of methods that are available for the certain object? If yes, then I would like to know how to configure these options too?

like image 997
Narek Avatar asked Sep 19 '09 18:09

Narek


People also ask

Is Vim difficult to learn?

There is a computer program called Vim, based on software created in the 1970s. It is famously difficult. Computer programmers have endless jokes about how much of a challenge it is just to exit the program. It is also ubiquitous.

Is Vim the most powerful editor?

Vim is extremely flexible and powerful. You can start simple and use it to edit configuration files quickly.

Is Vim really powerful?

Vim is a text editor for Unix that comes with Linux, BSD, and macOS. It is known to be fast and powerful, partly because it is a small program that can run in a terminal (although it has a graphical interface). It is mainly because it can be managed entirely without menus or a mouse with a keyboard.

How much time does it take to learn Vim?

You can learn to use vim in 30 minutes The tutorial that's presented is excellent and you'll be through it in no time. Once you're done, you'll have the rudiments needed to get your work done. You won't be fast yet, no; but you'll be competent.


3 Answers

What you're looking for is ctags and tags/TAGS files. Ctags (I recommend Exuberant Ctags) is a program which scans source files for identifiers and creates a file indexing them. You can then use ^] to jump to the definition for the tag under the cursor.

There may be some additional details needed to tell vim how to find the tags file; I'm not sure off-hand what they are. But that's the general idea - run ctags over your source code and then use ^].

Alternatively, you may wish to look at GNU Global. It's a bit more sophisticated. But ctags will accomplish what you've described.

like image 97
Michael Ekstrand Avatar answered Oct 16 '22 08:10

Michael Ekstrand


Vim is without a shadow of a doubt, the best editor in the world (Come get me emacs guys). Flame wars aside, what I have found incredibly useful for both C++ and Java programming is eclipse (best IDE in the world, yes now I am poking Netbeans) with the vrapper plugin. You get all the benefits of a fully integrated development environment and the power of vim keyboard shortcuts.

Vrapper doesn't give you full vim emulation but you can bounce around your code using vim shortcuts and you don't loose any of the goodness of eclipse.

like image 41
John Oxley Avatar answered Oct 16 '22 08:10

John Oxley


Using ctags is definitely the place to start, but don't forget cscope. In both cases, you first have cscope and ctags scan your source files and create their databases before you start vim. You also need to occasionally refresh the databases as your code grows and changes.

With ctags, simply use the command "ctags" in your code directory. If you have a heirarchy of directories, start at the top and use "ctags -R" to recurse through all the directories below. Start vim in the same directory as the resulting tags file and vim should find and load it automatically. When in the editor with the cursor on a function or variable name, you can type '^]' and vim should jump to the definition.

Similarly, with cscope, use "cscope -b" or "cscope -b -R" to get more detailed tag information. Vim and cscope work together to give you much more information such as where an identifier is used and from where a function is called. There is a set of macros that can be used to access the information. You can find the macros and their meanings in the vim cscope help information.

like image 36
Shannon Nelson Avatar answered Oct 16 '22 08:10

Shannon Nelson