How can I get vim's closetag plugin to work for all html tags? - vim

I am using the closetag.vim plugin, but it doesn't seem to work for all tags. In the plugin code there is the ignored tags var that contains some one that I noticed were not closing ex dd dl, but there are many others that aren't in the list that are not working (p, ul, li).
Nothing seemed to happen after updating the list of ignored tags.
To get this plugin to work you just enter the tag text and click tab, right? ie div
Am I missing something?

How did you install the plugin?
I had troubles with closetag.vim when I installed it in ~/.vim/plugins. Then I moved it into ~/.vim/scripts instead, and added the following to my .vimrc:
:let g:closetag_html_style=1
:source ~/.vim/scripts/closetag.vim
and now it works fine for me. I find that it closes all tags (including those included in the 'ignore' list), but not those that are self-closing (e.g. <img/>).
In the version of the script that I am using (0.9.1), it defines <C-_> as the trigger for completing tags. If you have mapped the command to <tab>, then that should work too.

I also cannot get this plugin to work, however in my case what it does it throw out a number of error messages before finally working. For instance if I try to close an H1 tag I will get the error Error Detected while processing function GetCloseTag and the error is an undefined variable b:UnaryTagsStack.
Seems like it would be a useful plugin but it just won't cooperate.

I had the same issue and nelstrom's answer above didn't solve it for me. What worked for me was adding the following lines to my .vimrc:
if !exists("b:unaryTagsStack") || exists("b:closetag_html_style")
if &filetype == "html" || exists("b:closetag_html_style")
let b:unaryTagsStacktack="area base br dd dt hr img input link meta param"
else " for xml and xsl
let b:unaryTagsStack=""
endif
endif
if !exists("b:unaryTagsStack")
let b:unaryTagsStack=""
endif
I don't know why adding just let b:unaryTagsStack="" didn't do the trick, but the combination above seems to fix it in all file types for me.

Related

Vim cannot be commented correctly with multiple quotation marks

I found a bug in the vim language syntax of <vim.vim> file. If there are multiple quotation marks in a comment, it will not be treated as normal comment. For example:
the line 1 and line 3 will not be commented as I expected.
How can I fix the bug ? I try to understand the syntax setting in the of vimComment setting and do some modification, but failed.
Add more details about my question:
I wrote a vim script as below:
let a = b " b range:0~255
Note: there are some spaces at the beginning of the statement.
I want to comment this statement, so add quotation at the beginning of the statement.
" let a = b " b range:0~255
I find the statement will NOT be recognized as vimComment as I expected, it will be treated as vimString (when cursor under let) and vimIsCommand (when cursor under range).
Here, I used the following method to check syntax name and definition under cursor.
nnoremap <f8> :echo synIDattr(synID(line('.'), col('.'), 0), 'name')<cr>
I think this is a bug in the vim.vim file which version is '8.0-28'.
For received feedbacks that there were no the same issue found in the others' VIM enviroment, I had to check my settings and did some trials. In the end I found this issue was caused by the Plugin 'thaerkh/vim-indentguides'. If I did not use this plugin, the comment state was correct as I expected. I guess the plugin has some errors in using of VIM conceal feature. So I changed to use the Plugin 'Yggdroot/indentLine' instead and solved the issue. Thank #all.

How do I stop vim reading in the default syntax?

I have defined my own javascript syntax file, which is in ~/.vim/syntax/after/
The problem is that the default syntax file that exists in /usr/share/vim/vim82/syntax is loaded along side my custom syntax file (it seems to be loaded before my custom syntax).
The result is that it conflicts with my custom syntax.
How do I ONLY load my custom syntax file? Not the default one.
Of course I could just delete the default one (which works), but that seems like a not very robust fix to the problem considering it will just be put back there when vim is updated.
I have "syntax clear" at the top of my custom file but it doesn't help.
I also note that the default syntax file has the following at the top:
if !exists("main_syntax")
" quit when a syntax file was already loaded
if exists("b:current_syntax")
finish
endif
let main_syntax = 'javascript'
elseif exists("b:current_syntax") && b:current_syntax == "javascript"
finish
endif
But that doesn't do anything either.
I have also tried putting the syntax folder in .vim/syntax, as suggested on the official vim page, but that doesn't seem to do anything at all (as in, it's not read at all).
Thankyou.
In principle, the order in which syntax scripts are sourced is the following:
~/.vim/syntax/foo.vim
$VIMRUNTIME/syntax/foo.vim
~/.vim/after/syntax/foo.vim
~/.vim/after/syntax/ comes last. It is not a good place if you are writing a complete replacement of a built-in syntax script because you have at least one syntax script sourced before yours. On the other hand, it is a good place if what you want to do is either add your own stuff or selectively override stuff that has been set earlier.
$VIMRUNTIME/syntax/ is not a good place either, because it is a systemwide location. Your customisation is supposed to happen in your $HOME, right?.
~/.vim/syntax/ comes first so it is the ideal place for custom syntax scripts, if you add the following line:
let b:current_syntax = "javascript"
This is because $VIMRUNTIME/syntax/javascript.vim begins with the following boilerplate:
if !exists("main_syntax")
" quit when a syntax file was already loaded
if exists("b:current_syntax")
finish
endif
let main_syntax = 'javascript'
elseif exists("b:current_syntax") && b:current_syntax == "javascript"
finish
endif
which, essentially, throws the towel if b:current_syntax is set, and ends with:
let b:current_syntax = "javascript"
to "mark its territory", if you will.
You don't have to check for anything because you come first, but you still have to tell other syntax scripts to mind their own business.
Note that bad mannered syntax scripts may not check for that buffer-local variable so it is entirely possible to still have conflicts even if you are doing the right thing. But that's the nature of Vim.

What is causing this SnipMate message?

I have just started using the Vim plugin SnipMate. When I create an HTML file (with filetype .html), go into insert mode, and type "html" and a tab, I see this message at the bottom of my screen:
1* 1. Users/me/.vim/bundle/vim-snippets javascript-jquery default
2: 2. Users/me/.vim/bundle/vim-snippets html default
__InputList__
select snippet by name (filter: ; press <F1> for help) [glob]
I'm not sure why this is happening. How can I configure SnipMate so that it knows that when I type "html" I always want the second option?
Thanks.
This message was caused by an "html" snippet in the file vim-snippets/snippets/javascript/javascript-jquery.snippets. Once I commented that snippet out, the message stopped occurring.
Yep.
I had a similar error on the bottom of my vim screen:
1 1* 1. html bundle/vim-snippets html.snippets
2 2: 2. javascript bundle/vim-snippets javascript-jquery.snippets
There is already a snippet called html in the
~/.vim/bundle/vim-snippets/snippets/javascript-jquery.snippets file.
You should comment out these two lines with the # sign, like this:
'# snippet html
̈́'# ${1:obj}.html('${2:Some text and bold!}')
Someone should fix this problem.
Installing Vim plugins should be easy, not complicated! :-(

Vim ctags behaves strangely

I'm starting out Lua development, so I ran ctags on a simple starter project and tried jumping around the source code with Ctrl + ]. Upon trying this, I got E426: tag not found: cache_objects where cache_objects was a function in another file. I checked the tags file and the correct entry was there for cached_objects. I also checked my tags path and it was correct.
I then tried explicitly executing the tags command: :ta cache_objects. This returned the same error. Now things are about to get weird. I executed: :ta /cache_objects, and it worked! It brought me to the function defined as:
function cache_objects (basedir)
...
I triple checked the spelling to make sure it was right. How could this be happening?
This is a bug in ctags. http://sourceforge.net/p/ctags/bugs/347/
If you noticed in your tags file that fields are tab delimited. However when ctags generated the cache_objects tag it included the space after it. vim only looks for complete words when using <C-]> which is why it didn't find the tag but did find it when you used a regex search. If you change the line to
function cache_objects(basedir)
it works.

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

Resources