Vim FuzzyFinder - how to add tags support for other languages - vim

Specifically I want to use FufBufferTag in coffeescript files. I've added the following to my ~/.ctags
--langdef=coffee
--langmap=coffee:.coffee
--regex-coffee=/^[ \t]*([A-Za-z_]+): (\([^)]*\))? *->(.*)/\1 \2/f,function/
(very basic coffeescript method regex so far)
If I run ctags from the command line, it works, but FufBufferTag still doesn't

I was having this same issue with CSS; added the regexes to my .ctags and they wouldn't show up with FufBufferTag. After searching through FuzzyFinder's buffertag.vim, I discovered it was restricting the tagged languages. I was able to add this line to my .vimrc to enable CSS with FufBufferTag:
let g:fuf_buffertag__css='--language-force=css'
I assume something similar will work for your coffeescript definitions:
let g:fuf_buffertag__coffee='--language-force=coffee'

Related

Vim: How to go to the declaration of a C++ method using ctags

How do I jump to the declaration of a C++ method instead of the definition using :tag or C-]? I tried
ctags * --C++-kinds=+p
to generate the tags file but :tselect still does not list any declarations, only definitions. The header files are hpp files and source files are cpp files, all in the same directory.
I have seen this answer but it does not answer my question, except for a comment from where I got the above idea (--<LANG>-kinds).
I'm using the following options: --c++-kinds=+pf --fields=+imaSft --extras=+q. Among many other things, I see function definitions and function declarations.
I handle everything automatically in a plugin I've been maintaining for quite some time.
On the same subject, see also:
Jump to function definition in vim
Vim Plugin to Resolve a Member Function More Efficiently Using Ctags
BTW, I highly recommend using universal-ctags (the maintained fork) instead of exhuberant ctags (the venerable and unmaintained project) when trying to generate tags for C++.

Generally, how do I "go to definition" in VIM? Then how do I with golang?

Two part question:
First, when using VIM what process do I take and what keys do I type to "go to definition" or "go to declaration" etc.? This document might be the answer to my question, but I can't get it to work, so I'm unsure. It looks like its merely text matching the string rather than finding the true definition. If I can get this to work, then will I be able to jump outside of the current document to a definition/declaration? Or does this only work within a single document?
Second, how do I make this work specifically with the Go programming language? It sure would be nice to "click" the Client in
clnt := &http.Client{Transport: tr}
And be taken to the actual code that defines an http.Client.
Possible? How?
As you guess, gd (and other commands) is merely text matching, vim doesn't understand the syntax as it is just a text editor, :h gd will explain how gd works.
Usually, 'go to definition' is brought by using CTRL-] and tag files. A user manual about this topic can be read by :h 29.1.
First you need to generate a tags file for your project, as latest Exuberant Ctags has supported golang (from here), command
cd /path/to/your/project
ctags -f tags -R --fields=+K+a
will do the job.
Second, open vim, by default vim will find tag files under working directory (according to 'tags' option), if the tag file is found successfully, then CTRL-]` should works well.
Also check two useful plugins Tagbar and Easytags.
For golang, you can use the application godef to do it. The pluging vim-go helps you on setting everything, so, you just type 'gd' in a definition and it goes to the exact definition.
https://github.com/fatih/vim-go/blob/master/doc/vim-go.txt

Vim tagslist plugin not detecting custom language (racket)

I've recently started using racket, and one of the first things I've done has been to try and get the vim TagList plugin to work with it. However, it doesn't work in the slightest. I can open racket files and the TagList window will be as blank as if I had opened a text file.
According to the extending page* I have added the following to my ~/.vimrc file:
let Tlist_Ctags_Cmd = 'ctags --langdef=racket --langmap=racket:.rkt --regex-racket=/^\(def[a-zA-Z0-9\-_\?\/\\]+[ \t]+([a-zA-Z0-9\-_\/\\\?]+)/\1/d,definition/'
let Tlist_racket_settings = 'racket;d:Definition'
The extra ctags stuff is also in my ~/.ctags file, but TList was spitting out errors about my setting line not being any good. I did original try to use ctags existing scheme functionality, but I had the same nothing results. To use the existing scheme functionality, i tried the following in my ~/.vimrc
let Tlist_Ctags_Cmd = 'ctags --langmap=scheme:.rkt'
let Tlist_racket_settings = 'racket;f:Functions'
If anyone else has any ideas on how to get it working, then I would be extremely grateful.
Thanks,
I'd post a link to the ctags one page as well, but it wont let me (new user). A link to it can be found on the extending taglist page.
EDIT
ctags from the command line
I can use ctags from the command line. Testing with the ctags line on the TagList FAQ page I get the following:
$ cat ~/.ctags
--langdef=racket
--langmap=racket:.rkt
--regex-racket=/^\(def[a-zA-Z0-9\-_\?\/\\]+[ \t]+([a-zA-Z0-9\-_\/\\\?]+)/\1/d,definition/
--regex-racket=/^\(define\-syntax(\-rule)?[ \t]+([a-zA-Z0-9\-_\/\\\?]+)/\2/m,macro/
--regex-racket=/^\(define?[ \t]+(([a-zA-Z0-9\-_\/\\\?]+)[ \t]+\(lambda|\(([a-zA-Z0-9\-_\/\\\?]+))/\2\3/f,function/
$ ctags -f - --format=2 --excmd=pattern --fields=nks XMMSClient.rkt
defenum XMMSClient.rkt /^(define-syntax defenum$/;" m line:11
defxmmsc XMMSClient.rkt /^(define-syntax defxmmsc$/;" m line:20
libxmmsclient XMMSClient.rkt /^(define libxmmsclient (ffi-lib "libxmmsclient"))$/;" d line:5
Output is the same if I force the language definition with switches, or if I change the language to scheme.
About TagBar
I had not seen TagBar before people had suggested it. Interestingly enough, it just worked with the changes to my .ctags file. Unfortunately, I've not found a setting for showing the tags from all loaded buffers the way TagList does, so I would prefer to use TagList.
I'd post comparison images, but I don't think its going to let me, as a new member. As per romainl's suggestion, I can set the vim filetype to scheme, and it does work. This however only seems like an 80% solution, when the documentation according to the extending pages seems to suggest that what I have should work. Perhaps I should be looking at filing a bug report.
Thanks again,
Here is a small racket snippet I lifted from the official documentation and saved as tt.rkt:
(define (checker p1 p2)
(let ([p12 (hc-append p1 p2)]
[p21 (hc-append p2 p1)])
(vc-append p12 p21)))
Without racket-specific syntax/indent files nothing is shown whether ft is set to racket (of course) or nothing (the default). If I :set ft=scheme, both TagList and TagBar list checker as "function".
From left to right: the file, TagBar, TagList.
From what I understand, "Racket" is a rebranding of some Scheme derivative. If it doesn't deviate too much from the norm, adding this line in your ~/.vimrc may help:
autocmd BufRead,BufNewFile *.rkt set filetype=scheme
I've been struggling with the same issue, though for xslt files... My solution was found by poking around in taglist.vim, whereby I added a line for
let s:tlist_def_xslt_settings = 'xslt;f:function:v:variable'
try doing a search for the s:tlist_def_ parts of the Vim code and put in something which looks sensible. There's a similar mechanism within Tagbar. I've not read the code through in detail, so I don't know why it would need this and not use the output from cta

How to add new snippets to snipMate in VIM

Ive just started using the sniptMate plugin for VIM and love it, however, since my collection of snippets isn't huge, I'd like to be able to add new snippets dynamically rather than opening the snippets file and creating a new snippet as I am in the middle of development.
As I am coding something I realize that some specific piece of code can be saved as a snippet to save me trouble of typing the bloat code again, at this time I want to be able to add a snippet without opening the snippet file for the language I am using at the time.
If you are using pathogen, you can write your own snippets without polluting the original ones. To do this, add your snippets to ~/.vim/bundle/mysnippets/snippets/*.snippets. FYI, mysnippets can be any name.
Moreover, it's a convention to add a _.snippets file in that directory where you add snippets which should be available everywhere irrespective of the filetype.
I'm not sure it's meant to be done like this but you can try calling the MakeSnip function from within file you're currently working on. For example:
:call MakeSnip(&ft, "foo", "<foo>${1}</foo>")
&ft will pass the filetype of the file you're currently editing, "foo" is the trigger and "<foo>${1}</foo>" is the replacement text.
Of course, snippets created like this won't persist. So why not have the snippets file open in another buffer, define new snippets there as necessary, then do:
:call ReloadSnippets(&ft)
and your new snippet will be available. You could even define an autocmd to call the ReloadSnippets function when you write the snippets file.
You can put your own snippets in ~/.vim/after/snippets/ or whatever the equivalent on Windows is... read :h snipMate for the filename syntax.
Just place your own snippets (given you want to use them in all files you edit) here:
~/.vim/after/snippets/_.snippets
For example:
snippet test
{"foo": "${1}", "bar": "${2}"}
Snippets for Snipmate are usually stored in the ".vim" directory in the snippets folder.
You can pretty easily edit the snippet file for the language you are working on.
If you use vundle to manage your plugins on Windows and you have installed
vim-snipMate & vim-snippets
If you want to add your customization, say to 'html' filetype, you just go to this folder:
$HOME/vimfiles/bundle/vim-snippets/snippets/
create a new file and name it in this format:
html_bsmith.snippets
(it must be underscore after html, see :help snipmate)
Then vim will load your file automatically.
If you customization can be used anywhere, just put it in the existing file:
_.snippets

How do I get Vim to automatically put ending braces?

While editing .scm files it would be great if Vim would automatically put the ending brace ) as soon as I start (. How do I do this?
You can map the opening brace to your liking:
:imap ( ()<left>
Try to use AutoClose plugin.
The simplest answer is to include a map. Eg.:
:inoremap ( ()<left>
The problem is that you would need to add one entry for each symbol you want automatically closed ('{','[','"',etc). Besides, plugins are normally more smart, providing things like detecting the "closing" character and not repeating it.
The problem with the solution above and most plugins, is that they tend break the undo sequence (gundo anyone?), as explained in:help ins-special-special.
Here is list of plugins that do what you ask (from vimtips):
delimitMate by Israel Chauca Fuentes (configurable, and doesn't break undo/redo/repeat, but - break iabbr) also on GitHub
AutoClose by Karl Guertin (auto-closes specific hard-coded characters, but doesn't break undo/redo/repeat)
AutoClose by Thiago Alves (configurable, but breaks undo/redo/repeat)
auto-pairs Auto Pairs by Miao Jiang (configurable, but breaks undo/redo/repeat)
ClosePairs by Edoardo Vacchi (configurable, but breaks undo/redo/repeat)
smartinput by Kana Natsuno (configurable, but breaks undo/redo/repeat)
Besides vimtips, there is another nice explanation of the issue on the web.
I needed one too, and I already tried a few of the plug-ins:
AutoClose, http://www.vim.org/scripts/script.php?script_id=1849, is a bit aggressive.
simple pairs, http://www.vim.org/scripts/script.php?script_id=2339, depends on Python. If you are on Linux it is not a problem, but on Windows it can be a trouble to match the Vim version to the Python interpreter you have.
My advice would be ClosePairs, that you can find at http://www.vim.org/scripts/script.php?script_id=2373 which has been working perfectly for me. It is simple and useful.
There are many tips and plugins on the subject. Have a look at the relevant entry in the vimtips site.
I'm presently using auto-pairs and it works quite very well.
The issues of the the plugin breaking undo/redo/repeat seem to persist among some of the plugins listed above but i don't think its much of an issue (well, at least not to me at the moment).
Just one caveat though, i wasn't able to use :helptags to generate the help file with this plugin as at the time of writing this.
Check out this new plugin: vim-autoclose by Townk. The previously mentioned AutoClose was to aggressive, sometimes behaving in an undesirable way.
There is a problem with using this (via the imap or one of the scripts). You won't be able to repeat the complete edit by using the . command.
e.g. (foo) with . only gets you foo, without the brackets.
It works fine if you insert the brackets normally, as two characters.
You can try downloading the following plugin
AutoClose : Inserts matching bracket, paren, brace or quote
https://github.com/vim-scripts/Auto-Pairs
Tested this plugin for undu redo. 2013 It just works. Also with python-mode plugin.
There is a new plugin by cohama:
lexima.vim (github)
(not yet on vim.org)
This plugin supports the .command!
Afaik, this is the only plugin supporting this.
Also the undo/redo sequence works.

Resources