ctags automatic tag writing - vim

Thus far I have installed exuberant-ctags from synaptic, and also attained the older version before exuberant: http://www.vim.org/scripts/script.php?script_id=610
First of all, do I need both? I would rather just use exuberant, if possible.
Furthermore, I am attempting to utilize the following script to auto-generate tags (which isn't working):
http://vim.wikia.com/wiki/Autocmd_to_update_ctags_file
I checked out the post at : Vim auto-generate ctags
and alot of people use easytags (which I made a post about since I could not get it to work).
Any suggestions for auto writing of tags?
Thank you

The first plugin in your question is not the old ctags that was deprecated by exuberant ctags: it's just one of the many vim plugins written to interact with ctags. And it does the generation too.
Technically, you don't need any plugin to make vim work with ctags, :help tags and :help ctags have a lot of useful info, read them.
There are many other tag generation plugins (some are listed in the answers to the question you linked to): try them all and make your decision based on your experience/needs.
In the future, try to make your questions clearer and more focused (what did you try, what worked, what files...).

Related

Vim Cmake integration

I have a cmake project. I want to do the following easily
search the declaration, definition and references of any variable, function, etc. under the cursor, which may be declared in an external header file whose path is added using INCLUDE_DIRECTORIES in CMakeLists.txt
rename a variable, function, etc. that is declared in the project
How can I set this up?
You can try to use vim plugin cmake4vim in order to integrate CMake to Vim.
This plugin helps to work with cmake targets and allows to generate compilation database file (compile_commands.json). A lot of plugins use this file for code completion, jump to definition and etc. (for example YCM)
Also you can use vim lsp plugins (for example vim-lsp) these plugins use language servers for code completion, refactoring and another good features.
But CMake project integration (cmake cache generation, project compilation, etc.) and search the declaration, definition and etc are different tasks. And different plugins and tools solve these tasks.
You can tell Vim where to look for includes by adding entries to the path option. I don't have enough experience with Cmake to know how to pull paths from CMakeLists.txt, though.
See :help 'path'.
Assuming a properly set path, it is possible to use the built-in :dsearch and related commands to search for definitions across includes.
The define option has a prescriptive name but it could be used to find any specific pattern so you could alter it to match declarations, too, or really anything.
See :help include-search and :help 'define'.
Vim has no built-in concept of "reference". :isearch and friends should work for that but they will probably be too noisy.
Renaming is usually done with something like:
:grep foo paths
:cwindow
:cdo s/foo/bar/gc
YouCompleteMe will help you. It uses compilation_database.json, witch can be generated by cmake.
This plugin also provides autocompetion for many languages.
I use functions in vim and assign them to a hotkey.
https://developer.ibm.com/tutorials/l-vim-script-2/
it gives you more an IDE feel. but at the end of the day you get a bit more control.

Command-T for Emacs?

I'm a long time Emacs user, but partially switched to MacVim 2 years ago, and have been using it for all my programming work (still using Emacs for other stuff). I decided to switch back to Emacs now, mainly because of the awesome evil-mode. I'm quite happy, but I still haven't found something as good and simple as the Vim Command-T plugin.
The main problem with the Emacs alternatives is that they are either too complicated and or slow.
The closest thing to Command-T is helm/helm-cmd-t, but it doesn't quite work like it.
Let's say you have two paths:
app/controllers/admin/feedback_controller.rb
app/controllers/fee_controller.rb
In Vim's Command-T, you can write:
app/controllers/fe
And it will match both paths.
With helm-cmd-t, if I write app/controllers/fee, it will only match fee_controller. If I want to match both, I have to use a regexp, as in app/controllers/.*, which is not that bad, but requires more keystrokes.
Any suggestions appreciated!
Any Emacs package that uses ido can do this, provided that ido-flex-match is non-nil. Helm-cmd-t deliberately doesn't support this kind of flexible matching.
You can get the behaviour you describe using find-file-in-repository with ido-flex-match set to 't.
I've recently started using flx with ido-mode and projectile it has exceptionally good, ranked fuzzy matching and has a very similar feel to CtrlP and CmdT for Vim.
It can be installed via MELPA.
M-x package-install
flx
For more info see the flx project.
Here's a screengrab to illustrate...
Here it is, but required helm to be installed first: https://github.com/emacs-helm/helm-cmd-t
EDIT: See my Helm guide. Read why it is powerful. See helm with projectile in action in that section.
With fuzzy searcher like Ido + flx or the like in Vim, you have to type thing in order.
With Helm, you can perform out of order matching.I called it out of order because whether I enter "main.c x86" or "x86 main.c", I get the same set of results for the either query. But it also makes sense to call it multi-steps search. Without having to enter the search strings (called "patterns", which are actually regexp) in an orderly fashion, Helm gives me greater freedom: I can enter the thing I wanted first in my mind without having to remember its complex path; if there are many candidates from the target I wanted, I narrow it down further with more details (patterns).
The above example to illustrate the two cases from the advantage above:
If my desire target is not unique, fine I can narrow further.
If my desire target is unique, I can immediately get it.
As you can see, the Linux kernel source tree contains more than 40kfiles, and I narrowed it down to a few files immediately.
Visual Studio also implements this mechanism in their project search, but it's not generic as Helm. In Helm, you can reuse the same Helm interface for many other things; for example, see helm-semantic-or-imenu. You have something like an outline tree, but you can interactively and incrementally narrow to the candidates you want with a few simple patterns.
Finally, fyi, flx author - Le Wang - is using Helm.
Did you try LustyExplorer? It's based on the Vim plugin with the same name.
Also, it looks like you are not using Command-T to the best of its capabilities: acfe should be enough for it to match those two files. What you do is not particularly better than :e app/con*/**/fe<Tab>.
I've once run across gpicker which advertises speed as one of its advantages over Ido and other "native" elisp packages. Never got to try it out on real-world projects though, but it might work for you.
Long story short - there's nothing quite like command-T for Emacs. Best options are gpicker or Peepcode's peepopen, but they are external applications, and I find them to be distracting after using command-T for so long. I'll stick to MacVim for now, only because of command-T, but might look into implementing something that behaves just like command-T as an exercise.
Thank you all for the answers and comments!
Give textmate.el a try :)
https://github.com/defunkt/textmate.el
You'll just have to use "Command+T" instead of "Ctrl+P" :)
https://github.com/bling/fzf.el
This is the best solution out there in my opinion. Here's why:
Uses projectile to determine project root if you're in a project.
Otherwise it very quickly indexes the file in the current directory.
Fuzzy matching.
Can be customized (top or bottom placement, number of records, etc.)

VIM: hack ctags or tweak tagbar for better PHP support

Recently, i gave up Taglist for Tagbar. Tagbar works as expected for all languages except PHP.
It lists class, methods and variables into their respective categories instead of displaying methods and variables into their respective scope.
I came to know that ctags has poor support for PHP.
Is there any way to improve ctags and Tagbar's support for PHP? I am hopping for some kind of hack or tweak, or any other way around.
I have just using PHP_Parser as syntax parsing backend written a tool called phpctags to generate ctags compatiable index file and an addon plugin for tagbar called tagbar-phpctags to enhance the PHP suport for tagbar.
Methods and properties even local variables assigned in functions could be listed in their own scope now as well as their access information.
Maybe these could help.
Unfortunately there is no easy answer to this. The ctags PHP parser just uses regular expressions, and the result -- as you noticed -- is that support for scopes is missing.
There would be two ways to get proper scope support working: someone has to write either an actual recursive parser module for ctags, or some other program that can output tags in a ctags compatible format. That could theoretically even be written in PHP, which might make it easier -- maybe there already is some functionality available that allows access to the AST, which would then just need to be printed out in the correct format. But until someone does that I'm afraid there's no real way to properly display PHP scopes in Tagbar, since it has to rely on the information that ctags hands to it.

Is there a Vim plug-in similar to fuzzyfinder_textmate and Command-T which does _not_ require Ruby support?

Both of these plugins require Vim to be compiled with Ruby support, need to be compiled themselves using the same version of Ruby, etc. Is there a plugin which does the same job, but doesn't require installation other than dropping it into vimfiles directory?
UPDATE: These plugins allow to open files/buffers by typing characters which appear in their path, not necessarily in a row. I.e. if your directory has files
foo/bar.txt
foo/baz.vim
zee.c
you can type
,t f
and only two matching files are shown; after you add r, only one file is left and it can be opened by pressing <Return>.
Using the latest fuzzyfinder vim plugin you can use
:FufCoverageFile
to mimic the global search features of fuzzyfinder_textmate and Command-T. No ruby needed.
Need also to have vim >= 7.2
I used LustyExplorer which provides similar functionality to the plugins you mention. Unfortunately it also requires ruby.
Later I started using LycosaExplorer which is based on LustyExplorer but uses python instead of ruby. I prefer this one to LustyExplorer because I cannot compile vim against ruby in windows and with python I can do it fine.
Recently I started using ctrlp.vim which also allows you to do something similar to what you request and doesn't require external depedencies (ruby or python). It seems to me that it is slower than LycosaExplorer on folders with a large number of files.
There are a few plugins in this same thematics. fuzzyfinder may be the most ergonomic though.
I've listed some of them on the description page of searchInRuntime (that also helps opening files)
HTH.
ctrlp is a good one. It's used a lot, if for no other reason than it's in janus.vim
If you don't mind python dependency, LeaderF is a good choice. The performance on large project appears very well compared with some similar plugins.

Has anyone got the vim taglist plugin working with Scala?

I'm having trouble getting the taglist plugin working properly with Scala. I've installed the plugin and ctags and verified that it works properly with Java and C++. I then followed the instructions on this page (minus the Lift specific instructuions), but was nothing shows up in the taglist window when I open it while editing a Scala file. Has anyone got this working and what are the proper steps? Thanks.
First check that your tags file has something in it. If you have followed the instructions on the page you mention, it should correctly identify classes, methods, etc. If that has worked then you can go to the next step.
The taglist plugin has a hardcoded list of supported language settings and Scala is not amongst them. So even if CTags generates the correct tags, the plugin will not read them in for this filetype.
It should be possible to add a definition as a global variable g:tlist_def_<lang>_settings, but I haven't been able to get that to work. So you have to modify the taglist.vim file in your ~/.vim/plugin directory to add Scala support. Don't worry, this is easy to do!
Search for the line that defines s:tlist_def_yacc_settings and add the following couple of lines after it:
let s:tlist_def_scala_settings = 'scala;t:trait;c:class;T:type;' .
\ 'm:method;C:constant;l:local;p:package;o:object'
Now when you hit Ctrl-T you should see your generated Scala tags in the Tag List window.
I had the same trouble recently and I have adopted and extended a ctags extractor for scala that works quite well with the tagbar plugin. Here it is the code:
https://github.com/luben/sctags
It is slower than exuberant-ctags because it uses the scalac parser and JVM has noticeable startup time but it gives a quite complete information.

Resources