Vim tagslist plugin not detecting custom language (racket) - vim

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

Related

How to get add folder to Projects (like Sublime Text) in VIM?

I just switched from Sublime Text to GVIM (on Windows). I am still debating whether I should continue ST or move completely to VIM. One feature that I desperately need (or miss) are
Ctrl+P to go to any file that I want in my list of folders.
Ctrl+Shift+f to find (and replace) any text in those list of folders.
I had added number of folders using Add Folders to Project feature in Sublime Text 3. It was really helpful. Now, I know that CtrlP plugin for VIM can do similar thing, but I can't figure out how to make it search the folders that I want, and not the root directory of current file.
I played around a bit with setting path in my vimrc file without much success.
Can you please help. If it is a repeated question, please excuse me.
Thanks.
AFAIK, ctrlp plugin only searches within one directory (and its descendants). Use the Unix features: make a directory with links to out-of-project directories you are interested in. This way, the association with out-of-project directories is not just something the editor knows about, but something recorded in the actual project.
Search and replace is a bit stickier thing. You want to work with all the files you are interested in, then repeat the replace command through all of them. For example, if you want to do the search for foo and replace with bar on all C files here and under,
:args **/*.c
:argdo %s/foo/bar/g
Ctrl+P to go to any file that I want in my list of folders.
The :find command can be used to "find" a file in the directories specified in the 'path' option:
set path+=/some/arbitrary/path
set path+=/another/one
:find *foo
I find these two mappings very handy:
nnoremap <key> :find * " search in every directory
" in 'path'
nnoremap <key> :find <C-R>=expand('%:p:h').'/**/*'<CR> " start from the directory
" of the current file
Ctrl+Shift+f to find (and replace) any text in those list of folders.
What amadan said above.
Good switch! So you’ve discovered CtrlP. It has extensive documentation built in. Use :h ctrlp to see the full vimdocs explaining the various options. It’ll explain some important settings for working dirs, which are pretty important for a good experience with it. Take for example some of the settings I use:
" The one you really care about...
" Set root to CWD. Another good option is 'r' for VCS mode.
" You should start vim in the root of your project tree
let g:ctrlp_working_path_mode = 0
" You _can_ switch dirs
let g:ctrlp_extensions = ['dir']
" Avoid big/unimportant project areas
set wildignore+=*/node_modules/*,*/build/*,*/components/*,*/_public/*,*/tmp/*,*/vendor/*
" Cache -- get used to pressing F5 on tree changes/additions
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 0
" Somewhat self-explanatory
let g:ctrlp_show_hidden = 1
let g:ctrlp_switch_buffer = 2
let g:ctrlp_max_depth = 6
let g:ctrlp_max_height = 50
" Open *h*orizontally and *j*ump to first win.
let g:ctrlp_open_multiple_files = 'hj'
" Use <C-d> to toggle
"let g:ctrlp_by_filename = 1
For further control of where to look for files outside your working tree, consult g:ctrlp_user_command. There is a Windows example using dir. You’d use that, but with your desired extra paths.
You might also want to add NerdTree, a nice complement to CtrlP. It is reminiscent of ST’s sidebar. Use its ? to get help. It has a menu that lets you quickly add files and dirs, maybe like you’re wanting out of “Add folders to project”.
For search-and-replace, look at ag.vim. I map it to <leader>g (meaning “grep”).
Those mentioned are some of my favorites, but you should explore the world of Vim plugins to decide which others are worth adopting. I recommend trying one at a time while you’re new, rather than a sometimes-opaque “distribution”. Tools to make plugin management easier are Vundle / Pathogen (choose one).
Eureka...!!!!!
After searching tirelessly for days (and sleepless nights), I found my answer (please read on).
First some foolosophy though
I was so keen not to give up on Vim. But this issue was just eating me from inside, and was disruptive in my work flow. I have many project folders in windows that I want vim to search through. Ctrl+p for some reason never really worked. I had some not-so-nice thoughts of giving up on Vim. and then I found this!
My Answer
This is a little different from what I expected. But the answer is Everything (by VoidTools). It allows to search from anywhere and gives results in a fraction of sec. It is by far the best filename search tool in Windows. It supports Regex. (though it is not text search tool). It has a command line interface called
es.exe
using Vim's FindEverything.vim plugin (FindEverything), I was able to search not only through my project folders, but pretty much anywhere. It returns the results in the vim buffer.
Thanks Y'all for your help. I know that not everyone may agree with this solution. But on Windows, this is by far the best solution, I found! Hopefully, it is useful for others why are in same boat!!!

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

Making AutoComplPop search entire project (or open buffers)?

I started using AutoComplPop for automatic code completions. It works great on the single file I am editing, but if file1 is making a reference to a method defined in file2, it doesn't find it.
The docs don't specify if there is a way to make it search a whole project directory, or even just all open buffers, so I can't tell if this is simply not something the plugin does, or if I need to enable something.
I was testing it out on two Ruby files, if that's relevant. Thanks!
Looks like that the cause of the problem is that ACP set the complete option for its purposes to .,w,b,k (see line #125 in autocomplpop/plugin/acp.vim),
call l9#defineVariableDefault('g:acp_completeOption', '.,w,b,k')
while the default value that is used when pressing \<C-n> is .,w,b,u,t,i. And it appears that the very last letter i actually makes the difference: for some reason vim would not use word from an include file opened in a buffer to complete words in another buffer. So, b option is not enough, i must also be included. Adding the following line into my .vimrc helped
let g:acp_completeOption = '.,w,b,u,t,i'
At least it worked for C++ files, but I'm not sure it fixes the problem for the case of Ruby scripts.
Depending on what is on the left of the cursor, ACP (like all the alternatives) decides what completion mechanism to use.
But ACP only uses Vim's default completion mechanisms: if <C-x><C-o> and <C-n>/<C-p> don't provide what you are looking for, ACP won't help. Try them out first.
Oh cool, this plugin looks a lot like neocomplcache but maybe cleaner...looks a little old. Little concerning that there are so many open tickets on that project and no updates in two years.
Anyway, according to the documentation it doesn't...really...say. Very likely its one of the following things:
Your pwd. If the root directory for your source is some/path then that should also be your current working directory. Try typing :cd some/path to see if that makes a difference.
The runtime path rtp. See if adding the directory with your source files to &rtp does the trick.
The path. Same deal as the &rtp setting.
Very likely this plugin is just falling back on the built in ruby omni completion functions bundled with vim. Try help ft-ruby-omni.
I just had the same problem, and I actually found a solution for this.
Apparently you have to set in your .vimrc file the following:
let g:acp_behaviorKeywordCommand = "\<C-x>\<C-i>"
This will make acp look in every file included by your source for completions, as if you were actually typing <C-p>. However, it is slow, after trying it I decided to revert using <C-p> when there are no matches and default behaviour in the other cases.

Search tags only in current file

I am using ":ta " to jump to a method.
For example i got two classes named A.java and B.java. They both have a foo() method and B.java have another method called fooBar(). Then i open A.java and input :ta foo then press TAB then i will got two completion : foo and fooBar. But what i want to jump now is just tag in current file, i don't like tag in other file to display.
And i found tagslist does very good in this job. So if i can use the tag generated by taglist to search from, it will be very nice.
Depending on how many times you call your methods a couple of * may be enough.
Without using tags, gd can be used to go to the local declaration of the method under your cursor. I tend to choose the most low-tech solution usually, so I would go with this one.
But ctags is also able to generate tags for a single file only or for an arbitrary selection of files. It can be done in a few steps but it's definetely not as straightforward as what you are accustomed to do…
Create a file with the name(s) of the file(s) you want to scan. Let's say it's called files.txt and it's located at the root of your working directory.
Generate your tags file using the -L <file> argument: ctags -L files.txt.
At this point you should have a tags file containing only the tags present in the file(s) specified at step 1.
Generating different tags files for the whole project and for single files may be useful, here. A short script generating a tags file named after the current file and making it the sole tags source may make the whole thing easier.
EDIT
Actually, TagList and TagBar don't generate tags files. The output of the ctags <options> command they run is used internally and parsed with all kinds of regexp to filter by scope or filename or whatever.
Unfortunately this cannot be done using ctags. Ctags does not respect context, it is a pure list of all possible "functions". Try to open a tag file with an editor (e.g. vim) and you will see it is just a list of "functions" (in case of Java they are "methods"). Example:
getDesc src/com/redhat/rhn/internal/doclet/Handler.java /^ public String getDesc() {$/;" m class:Handler
getDoc src/com/redhat/rhn/internal/doclet/ApiCall.java /^ public String getDoc() {$/;" m class:ApiCall
Vim just search the file "as is" without giving it any context - it just search for a "function". It is able to search for files, classes, methods, enums etc. Tags format is described in more detail here: http://ctags.sourceforge.net/FORMAT
In Vim you have few possibilities. There are several plugins that gives Vim some context sensitivity, but you cannot use tags for that. Vim itself has a feature called OmniComplete and there are few plugins dedicated for Java. Then you can use Ctrl-X Ctrl-O to start a completition. I recommend you to map this to a different key (maybe Ctrl-Space if you like). More info about Java OmniComplete plugins here:
Vim omnicompletion for Java
Eclim (http://eclim.org/) is very comperhensive, but difficult to setup (you need to run Eclipse in the background). JDE script is easier and also robust (http://www.vim.org/scripts/script.php?script_id=1213). And please note IntelliJ IDEA Community Edition (free) also has a very nice Vim plugin that is free to use. But I understand you - Vim is Vim.
Good luck!
Not exactly an answer to your question, but it seems like there's no way to do exactly what you need, so, i would recommend you the following: for your Java development in Vim, try eclim.
This tool helps you to use your favorite text editor Vim with power of an Eclipse (IDE).
I can't find analogue for tab-completion of :ta, but i know a smart analogue for g] : this is a command :JavaSearchContext. You can map it to something.
For example, if you have two classes A and B, and you have method foo() in each class, then g] will ask you every time you want to jump to foo(), but :JavaSearchContext will always jump to the proper declaration of foo().
Of course, there are many other features.

Vim FuzzyFinder - how to add tags support for other languages

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'

Resources