Is there a vim plugin that allows you to place the cursor over a function and have a plugin run a script that searchs a tag or some other entity for where that function is defined. Or perhaps it provides a list of places where that function is defined? Specifically I am looking for a C/C++ based plugin.
You want ctags, which supports many, many languages beyond C. It will show you the definition of the function or variable under the cursor.
cscope integrates nicely with Vim to do exactly that and more. Where a function is defined, where it is called etc. You may also need a tags with cscope.
The vim website hosts a lot of plugins, you might really want to look there. Also, you didn't really specify what languages you wanted this to apply to, so this is a very broad question (hard to find a real answer to this).
An alternative to your question is, instead of putting the lookup capability into vim, why not put in into something else that already has it? Why not eclipse? There's an eclipse plugin called vrapper that gives vim like functionality within eclipse. You can then use eclipse to do the referencing and lookup that you want to do, because it already has this supported for many languages.
Edit: wouldn't this solve it?
I think you wanted to know what it was that you had to do to be able to solve the problem, as though you knew the feature was there but not how to use it. That link explains it. If that is the solution to your problem, please remember to vote & check XD
Related
I wanted a cross reference navigation similar to Source Insight.
Lets take simple example:
classA::MethodB()
{
...
m_variable = value;
}
In this example if I use Ctags / Cscope, then when I try to find m_variable, it will show me all the available m_variable. I need to go through each and then find which one is required.
Where as in Source Insight, it clearly gives me the Class delectation.
Is there any such Cross ref tools available for Vim?
Vim is not an IDE, it's a text editor.
You can't reasonably expect it to understand your code as well or as deeply as an IDE.
IDEs typically keep a dynamic internal representation of your code which makes them able to track declaration and usage even when you have dozens of methods or variables with the same name. Vim, like most text editors, is not able to do that on its own: it must rely on external tools for indexing/navigating through your code. Now, because of architectural constraints, Vim is incapable of running any background process which is the absolute prerequisite for a real "code intelligence" to be added to Vim.
Given all that, you are left with code indexers like ctags, cscope or GLOBAL. These tools do their best trying to give you accurate results but they are not as smart and as specific as the tools used in IDEs.
To compensate, Vim has a bunch of different commands like :tselect or g] which open a list of possible tags to chose from. Read :h tags, :h ctags and :h cscope for how to deal with those limitations.
I've not tried this myself. But sounds like eclim is what you're looking for. http://eclim.org/
It provides eclipse features to be accessible from Vim, including code searching and auto-completion.
I think standard highlighting is useful -- to some extent. When programming with callbacks and nested structures, this does not help. Keywords and strings, they appear everywhere, and it helps when they are shown in a distinct color, but these colors gives no clue about in which scope I am, where I am in a lexical standpoint.
I have heard of context highlighting, in a talk of Douglas Crockford, which I can't remember a url to. The idea is, to highlight lexical levels of scope. Toplevel definitions are colored in color0, inner level block statements are colored in color1, and this repeats recursively every time a new level of scope is introduced. Below is an example for this, using some imaginary node libraries. (Now added a (ish (or scheme lisp)) example)
This is not necessarily for node or javascript. I wonder if there is an editor/vim plugin implementing this kind of feature. I don't know if context highlighting is the word for this, but I can't just find one. Googling for context highlighting brings up results for generic token based highlighting and ConTeXt (which I don't have a clue about).
Does this exists? Is there an editor implements this? And more importantly, can I have this in vim?
Another question which is identical to mine, with no real answer: Is Crockford style Context Coloring implemented in any code editor?
I also couldn't find anything similar, so I wrote one:
rainbow_levels.vim: A different approach to code highlighting.
Of course it is a very simplistic implementation, only considering indentation levels instead of real context, but it gets the job done ;D
Not exactly what you are requesting, but code folding is a powerful feature to let you focus on specific levels of your code. Vim supports folding http://vim.wikia.com/wiki/Folding
Indention guides are very handy also, for focusing in on specific parts of code. The sublime text editor has this (http://sublimetext.userecho.com/topic/98136-indent-guide-highlighting-changed/)
I saw this plugin for vim (https://github.com/nathanaelkane/vim-indent-guides) that appears to do the same thing.
You could possibly create a syntax highlighter that uses the indentation logic of this plugin to change the color scheme. What you describe is more involved where it needs to work not just off the indention, but like a language parser.
There is now a plugin for this in VIM called vim-js-context-coloring. I've only just played with it a little and am not super impressed yet, but it looks promising!
Note: you need to install npm and then run npm install in the directory where the plugin is installed. I regretfully, forgot to read the instructions when I installed it.
I'm looking to beef up the Markdown capabilities of vim a bit (https://github.com/plasticboy/vim-markdown), namely to add some support for auto-creating the next list item while indenting everything properly.
My question is, what vim mechanism is best to implement this in? Is this a task for the highlighting file? Should I cobble together something in SnipMate? I'm glad to do any homework necessary, but I'd like to know where's the best place to start.
Based on a quick snoop through the help, formatoptions and formatlistpat and the related fo-table look like good places to start. I'd start by reading those and then finding existing plugins that use them and figure out how they work.
Pre:
I've been working in VIM for like a year already. Lots of great things: combinations, scripts. Whenever I'm editing something in a different editor, I feel sluggish/uncomfortable without VIM's navigation.
The problem:
The thing that really bothers me most of all is source code navigation using existing tools (ctags, cscope). Often, ctags can't find the declaration of a variable, cscope as opposed to ctags finds all definitions with the same variable name. Same craziness with call tree navigation, finding forward declarations along with a single class definition etc.
Compared to MS Intellisense, Visual Assist or even source code navigation in Eclipse, Exuberant Tags/cscope seems to be deprecated for at least 10 years.
I know there are tools like ViEMU, but they don't really solve the problem, since you lose lots of VIM's functionality.
The question:
I was wondering if there is a tool that does the source parsing better, or there is some way to integrate source parsing engines like Intellisense into VIM ?
Maybe there are commercial solutions or there are people who are ready to implement one ?
All the benefits of VIM seem to save less time than is being wasted while navigating to class definition, compared to Visual Assist, where it's done by a single Alt-G shortcut.
Search and Call tree
You could try eclim, which is a way to use some Eclipse features in Vim.
For C/C++, it provides :
Context sensitive completion (although it is disabled on Windows because it is buggy)
Context sensitive search in Project files (through :CSearchContext)
Call tree for functions/methods (:CCallHierarchy)
Code Validation (:Validate)
It is not great, but it can help in some cases.
Code Completion
Regarding automatic code completion, I primarily use OmniCppComplete, which is using tags to provide Context aware code completion. It is not that bad.
As advised by Luc Hermitte, you can also use clang_complete which does not need ctags, but needs clang installed.
Unfortunatelly, it is a real problem. ctags or cscope can hardly compete with Visual Studio code browsing - it actually uses a C++ compiler front-end to parse the code for the editor.
I've been using Vim for a while now and love it, but one thing I've noticed when I use other editors is that I've never really got autocomplete working with much efficiency. I have supertab & snipmate working, I have tags for whatever language I'm using set up, but somehow it seems a little too cumbersome to use all that much, and apart from long method names I typically just avoid autocomplete.
Does anyone have fast, comprehensive autocomplete funcitonality set up in vim? Specifically:
At the moment, I hit "tab" to autocomplete class/method/variable names & generate snippets, but Ctrl+X+O for inbuilt langauge commands. I'd rather press tab for everything.
The ordering doesn't seem to be too intelligent. Very common stuff is often hidden in the middle of a bunch of rarely-used commands.
I've set up autocomplpop to show potential autocompletes as I'm typing, but I have to hit tab twice to accept the first entry. One much rather single-tab it.
So, any tips on setting up an efficient, comprehensive autocomplete configuration in vim? I know this question is a little vague - but if anyone has an overview of how they autocomplete well, and/or a link to a guide, it would be much appreciated.
Just thought I'd come back and mention that I finally found something I like: A customised version of NeoComplCache. Nice auto popup, everything integrated pleasantly into 'tab', and with a bit of customisation plays nice with snippets.
http://www.vim.org/scripts/script.php?script_id=2620
This is very dependant on your working domain. Vim is a text editor with the ability to interface with intelligent text-aware mechanisms.
If you are using java there is eclim, which is the eclipse backend together with a vim plugin for the frontend.
For C or C++ there is the plugin OmniCppComplete
It works by scanning the headers in the paths you have set up in vim (see :h path), and works very well imo.
If you have to press Ctrl-X_Ctrl-O for omnicompleteion, then your supertab config seems a bit broken. It should try omni or filename completion first, and then fall back to word completion.
YouCompleteMe plugin by Valloric is a very decent plugins for autocomplete and suggestion.
It contains support for all the major languages and you can extend the feature with setting up different engine .
it also comes with syntax checker so u don't have to use Syntastic separately
For setup details visit this link
https://github.com/Valloric/YouCompleteMe