alvan / vim-closetag Goto Github PK
View Code? Open in Web Editor NEWAuto close (X)HTML tags
Auto close (X)HTML tags
I added *.php to the closetag_filenames in vimrc, so the plug in works in php files. My problem is that when I press the angle bracket key the second time to get the multi line option, the closing tag is placed at the beginning of the line, it doesn't line up with the opening tag. This works as expected in html files though.
Is there a way to temporarily disable this plugin at runtime through an ex command? I am using this in Typescript to edit template strings that contain html but it has the side effect of interpreting generic types like List<MyType>
as tags and auto closes them as well.
This feature is motivated by the increasing use of JSX and Javscript Flow within the React.js world.
In general the auto-closing of tags by this plugin is a godsend for JSX users, but when the pluging interacts with Flow, Facebook's type-checking layer, it becomes too eager.
For example, sometimes I want to declare things like the following:
Promise<any>
React.Element<*>
As it stands, these two bad boys auto-expand (that rhymes lol!)
It seems that, the indents of children elements are preserved for known html elements, but gets erased for custom elements.
<div>
<span
</div>
after inserting the >
for span...
<div>
<span></span>
</div>
However for custom elements...
<custom-div>
<span
</custom-div>
after inserting the `> for span...
<custom-div>
<span></span>
</custom-div>
There's a noticeable delay after pressing <Leader>
in insert mode since 527bb10.
When set imdisable
option , autoclose is not work in jsx file.
$ vim
:set ft=jsx
:CloseTagEnableBuffer
i
<h1>
set rtp+=~/plugin/vim-closetag
" filenames like *.xml, *.html, *.xhtml, ...
" These are the file extensions where this plugin is enabled.
"
let g:closetag_filenames = '*.html,*.xhtml,*.phtml'
" filenames like *.xml, *.xhtml, ...
" This will make the list of non-closing tags self-closing in the specified files.
"
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx'
" filetypes like xml, html, xhtml, ...
" These are the file types where this plugin is enabled.
"
let g:closetag_filetypes = 'html,xhtml,phtml'
" filetypes like xml, xhtml, ...
" This will make the list of non-closing tags self-closing in the specified files.
"
let g:closetag_xhtml_filetypes = 'xhtml,jsx'
" integer value [0|1]
" This will make the list of non-closing tags case-sensitive (e.g. `<Link>` will be closed while `<link>` won't.)
"
let g:closetag_emptyTags_caseSensitive = 1
" dict
" Disables auto-close if not in a "valid" region (based on filetype)
"
let g:closetag_regions = {
\ 'typescript.tsx': 'jsxRegion,tsxRegion',
\ 'javascript.jsx': 'jsxRegion',
\ 'typescriptreact': 'jsxRegion,tsxRegion',
\ 'javascriptreact': 'jsxRegion',
\ }
" Shortcut for closing tags, default is '>'
"
let g:closetag_shortcut = '>'
" Add > at current position without closing the current tag, default is ''
"
let g:closetag_close_shortcut = '<leader>>'
set imdisable
Is there a way to enable this plugin for any file type instead of based on a whitelist? Any reason not to? Then perhaps it can be enabled temporarily by a keyboard shortcut?
For example, in Ruby, I may have a heredoc (or any string literal for that matter) containing html or xml, and I would like closetag to work there.
Thanks!
I'm trying to use this Plugin with .html.erb files (ruby on rails) but it does not work.
it works with anything ending with a ".html"
but it won't work if the file has ".erb" (or haml for example)
Thanks.
I've set up vim-closetag
for use with tsx regions but it still adds closing tags for generics, which is quite annoying. Do I need to create the tsxRegion
manually or where is it supposed to come from?
My config:
let g:closetag_filenames = "*.html,*.jsx,*.tsx,*.vue,*.xhml,*.xml"
let g:closetag_regions = {
\ 'typescript.tsx': 'jsxRegion,tsxRegion',
\ 'javascript.jsx': 'jsxRegion',
\ }
Otherwise, I'm really happy with this plugin, great time saver! π
Empty tags used in JSX and React files.
When search highlighting is enabled and a search has been done, closing a tag changes the highlighted search to > instead of the previous search.
I'm not too savvy with vimscript but I fixed this by putting let old_search = @/
at the beginning of fun! s:CloseIt()
and then putting let @/ = old_search
right before any retu
in that function, if this isn't too naive of a fix I can submit a PR
Example render method in react class. Symbol |
is my cursor.
render() {
return (
<div>|</div>
);
}
Then I press >
and this is what happens:
render() {
return (
<div>
|
</div>
);
}
And this happens with all files
[2021-05-17 15:37:25]
[2021-05-17 15:37:25] Plugin alvanvim-closetag
[2021-05-17 15:37:25] $ git clone --recursive "https://github.com/vim-scripts/alvanvim-closetag.git" "C:\Users\marct.vim\bundle\alvanvim-closetag"
[2021-05-17 15:37:25] > Cloning into 'C:\Users\marct.vim\bundle\alvanvim-closetag'...
[2021-05-17 15:37:25] > Logon failed, use ctrl+c to cancel basic credential prompt.
[2021-05-17 15:37:25] > bash: /dev/tty: No such device or address
[2021-05-17 15:37:25] > error: failed to execute prompt script (exit code 1)
[2021-05-17 15:37:25] > fatal: could not read Username for 'https://github.com': No such file or directory
[2021-05-17 15:37:25] >
[2021-05-17 15:37:27]
[2021-05-17 15:37:27] Helptags:
[2021-05-17 15:37:27] :helptags C:\Users\marct.vim\bundle\Vundle.vim/doc/
[2021-05-17 15:37:27] :helptags C:\Users\marct.vim\bundle\auto-pairs/doc/
[2021-05-17 15:37:27] Helptags: 2 plugins processed
Hi, I love your wonderful work.
Actually, It works like charms with *.html
. I tried many times and many ways with *.jsx
and *.tsx
, but failed.
Below is my configuration. Any clue?
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'rust-lang/rust.vim'
Plugin 'ervandew/supertab'
Plugin 'pangloss/vim-javascript'
Plugin 'mxw/vim-jsx'
Plugin 'maxmellon/vim-jsx-pretty'
Plugin 'leafgarland/typescript-vim'
Plugin 'w0rp/ale'
Plugin 'alvan/vim-closetag'
call vundle#end()
let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.erb,*.jsx,*.tsx"
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.tsx,*.erb'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_shortcut = '>'
let g:closetag_close_shortcut = '<leader>>'
Reproduce
| = cursor
Actual behaviour:
<MyComponent prop1={()=><Testing/>}|
<MyComponent prop1={()=><Testing/>}>|
Expected behavuour:
<MyComponent prop1={()=><Testing/>}|
<MyComponent prop1={()=><Testing/>}>|</MyComponent>
in my .vimrc, I have let g:closetag_filenames = "*.html,*.erb"
and yet it doesn't seem to work in .erb files. Any idea why?
When I set the filetype trough set filetype=html
when on an empty (or one with a different .format) buffer the plugin won't work.
Suggestion on how to fix it while keeping the old functionality:
- call s:Declare('g:closetag_filenames', '*.html,*.xhtml,*.phtml')
- call s:Declare('g:closetag_xhtml_filenames', '*.xhtml')
+ call s:Declare('g:closetag_filenames', 'html,xhtml,phtml')
+ call s:Declare('g:closetag_xhtml_filenames', 'xhtml')
- exec "au BufNewFile,Bufread " . g:closetag_filenames . " inoremap <silent> <buffer> " . g:closetag_shortcut . " ><Esc>:call <SID>CloseTagFun()<Cr>"
+ exec "au FileType " . g:closetag_filenames . " inoremap <silent> <buffer> " . g:closetag_shortcut . " ><Esc>:call <SID>CloseTagFun()<Cr>"
- exec "au BufNewFile,Bufread " . g:closetag_filenames . " inoremap <silent> <buffer> " . g:closetag_close_shortcut . " >"
+ exec "au FileType " . g:closetag_filenames . " inoremap <silent> <buffer> " . g:closetag_close_shortcut . " >"
- exec "au BufNewFile,Bufread " . g:closetag_xhtml_filenames . " call <SID>Declare('b:closetag_use_xhtml', 1)"
+ exec "au FileType " . g:closetag_xhtml_filenames . " call <SID>Declare('b:closetag_use_xhtml', 1)"
When pressing >, how do you make it indent 2 spaces rather than 4?
For example, say you already have this in your code:
<div className="test">
Hello world
</div>
Then you want to change it to:
<div>
Hello world
</div>
One way you might do this is to move the cursor to the end of the first div
, then type C
to go to the end of the line, then type >
to close the first div
tag:
<div|
Hello world
</div>
As soon as you press >
you get:
<div></div>
Hello world
</div>
There are plugins that can detect and highlight the closing tag (e.g. https://github.com/Valloric/MatchTagAlways), so it seems like this should be possible (check if there's a match already once >
is entered, and only add the closing tag if it's not already there).
The workaround of course would be not to delete the >
, by doing dt>
or ct>
instead of C
, but I think this would be a nice feature.
Hi! First of all, thanks for your good plugin. It is really useful.
Under a certain conditions, Vim or Neovim stay frozen after editing a tag. I tried it in HTML and XML. The way to reproduce it:
xml.xml
.<test>
and the plugin will insert </test>
perfectly.>
again to create the indent for the following tag:<test>
|
</test>
<BS>
and 1 time <Del>
. What happens if you press 2 times <Del>
by mistake? You will have this:<test>|/test>
<
... But nothing is happening. Literally nothing. You can't <Esc>
, you can't close Vim. I had to close the tmux pane/window.Can you reproduce it? Thanks in advance!
Update: I upload an animated GIF. As you can see, I can't close the 'Insert mode' pressing <Esc>
. Actually, I had to kill the process with sudo kill -2 {PID}
because Vim was consuming 100% of the CPU (even after closing Vim deleting the tmux pane).
Doesn't work
call dein#add('alvan/vim-closetag', {'lazy':1, 'on_ft': ['html', 'htmldjango', 'xhtml', 'jinja']})
Works
call dein#add('alvan/vim-closetag', {'lazy':0, 'on_ft': ['html', 'htmldjango', 'xhtml', 'jinja']})
As I follow through with what the instructions tell me to do, the autocompleting tag, for example, <div>
will complete with </div>>
Would it be possible to add an option to configure the default closing tag location? Currently, it is unconditionally added immediately after the closing >
, but it can be desirable to have it added on the next line for people that prefer opening and closing tags on their own lines.
The plugin isn't working , my .vimrc file has :
let g:closetag_filenames = '*.html,*.xhtml,*.phtml'
and I downloaded the plugin with pathogen by following commands:
cd ~/.vim/bundle
git clone https://github.com/alvan/vim-closetag.git
Tested with only the plugin in .vim and an empty .vimrc :
$ cd ~
$ mv .vim vimbackup
$ mv .vimrc vimbackuprc
$ touch .vimrc
$ git clone [email protected]:alvan/vim-closetag.git .vim
$ cd .vim
$ git rev-parse HEAD # current commit
8496544ba82a210b66ab2d8283609f65a36d92a6
$ vim --version | head -n2
VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Oct 7 2017 13:50:55)
Included patches: 1-1176
$ vim hello.html
|
as cursor position
<form method="POST"
action="stuff"|
enter >>
<form method="POST|
action="stuff">></form>
(note dissappeared "
, cursor having moved UP, one too many >
, no new lines for cursor and closing tag)
expected outcome:
<form method="POST"
action="stuff">
|
</form>
(or similar, with valid form tag and cursor and closing tag on their own lines)
I have added this to my VIMRC:
let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.php, *.jsx"
but auto closing tags does not work.
When I set noexpandtab virtualedit=all
I get wrong indentation on the empty line inserted between two tags. For example when I start out like
<html>|</html>
and press > I get this (a tab and 7 spaces):
<html>
β β
β
β
β
β
β
β
|
</html>
Setting either set expandtab
or set virtualedit=
fixes the problem. I can't live without either of these options, so it would be really nice if this can be fixed another way.
I have also set
these options, they may be relevant, but don't seem to change the behavior when I change/disable them.
set autoindent
set shiftwidth=8
set smartindent
set smarttab
set softtabstop=8
set tabstop=8
Plugin will not work if "set paste" option is enabled in .vimrc
To reproduce:
:imap >
should show that >
has been mapped)CTRL-V
), and make a selectionI
, c
, or A
).>
in this mode, vim exits visual block mode prematurely.I'm currently building an app with Vue, where the templating will at times have >
comparisons inside of an attribute value. When that character is entered, closetag immediately closes the tag, even though it shouldn't.
Typing <div :complete="1 >
will immediately result in <div :complete="1></div>
. When using the auto-pairs plugin to insert a closing quote as soon as the opening is typed closetag ends up with <div :complete="1 >"
being converted to <div :complete="1 ></div>"
.
Is there any kind of setting/flag I need to set, or is this a bug?
Right now self-closing tags are not expanded, which is good enough, but the proper way of closing them is />
.
Either, when typing >
on such tag expand it to />
, or let /
expand into />
, or both. (If /
would extend to '/>', if the very next input is >
, ignore it and move the cursor to the right. Or forget if the mode has been switched.)
The second option looks a bit more complicated than just letting >
expand "backwards" into />
It's true that the ending slash in HTML5 is optional but in XHTML it's required.
Is it possible to disable the auto-closing of tags when outside of a JSX region in a regular javascript file? I don't really use the jsx extension and would like to be able to do the following:
let g:closetag_regions = {
\ 'typescript.tsx': 'jsxRegion,tsxRegion',
\ 'javascript.jsx': 'jsxRegion',
\ 'javascript': 'jsxRegion',
\ }
I have this configuration:
let g:closetag_filenames = "*.html,*.xhtml,*.phtml,*.erb,*.jsx"
let g:closetag_xhtml_filenames = '*.xhtml,*.jsx,*.erb'
let g:closetag_emptyTags_caseSensitive = 1
let g:closetag_shortcut = '>'
let g:closetag_close_shortcut = '<leader>>'
And still it doesn't work for my jsx configuration. It works for all other extensions though. Any help would be appreciated.
Today, in order to properly handle empty tags in JSX which closes empty elements like XHTML, I have two autocmd
s change the global variable g:closetag_use_xhtml
depending on the file extension.
This option is not documented in the README, so I'm not sure if I should actually use it.
I currently have the following in my .vimrc
let g:closetag_filenames = '*.html,*.js'
let g:closetag_emptyTags_caseSensitive = 1
autocmd BufNewFile,Bufread *.html let g:closetag_use_xhtml = 0
autocmd BufNewFile,Bufread *.js let g:closetag_use_xhtml = 1
But I think it would be nicer to have something like:
let g:closetag_filenames = '*.html'
let g:closetag_xhtml_filenames = '*.js'
let g:closetag_emptyTags_caseSensitive = 1
What do you think?
Love this plugin by the way. I tried to include .tsx
file types in to the variable in my init.vim
file. it looks like:
let g:closetag_filenames = '*.html,*.jsx,*.tsx'
It doesn't auto close for TSX files but JSX works just fine. Any thoughts or something I may be doing wrong?
The docs say
And now if you press > again, the content will be:
<table>
|
</table>
How can I get this same behavior by pressing the <enter> key (i.e. <c-r>) after I type the close > in <table>?
I am having some troubles pasting some HTML into a .jsx file with autopairs turned on
<blockquote>This is a blockquote</blockquote><p><br></p><h1>This is a header</h1>
ends up as
<blockquote>This is a blockquote</blockquote><p><br></p><h1>This is a header</h1></h1></p></blockquote>
Hi!
First of all thanks for the great work.
At this point when I update closetag to the latest version it doesnt work even if its the only plugin loaded. When I go back to commit 00e1155 it does work. So it seems that when you removed 'unnecessary code' you removed a bit too much :)
Hi, your plugin is awesome! I have use it for a long time.
But I met an issue that it not works well in attribute value. If I want to insert a attribute in class. For example:
<div class="a|"></div>
<!-- "|" is the cursor placed -->
If I hit the >, the vim-closetag
will make effect and the line will be like this:
<div class="a></div>"></div>
It is not what it should be. And it makes trouble when using ng-if
or v-if
in angularjs or vuejs.
When https://github.com/Raimondi/delimitMate is also loaded, closing a tag results in
<sometag></sometag>>
CloseTagEnableBuffer and CloseTagDisableBuffer are great, but it would be even better if there were a way to toggle the plugin to make keybinds a little bit cleaner.
Hi, when I type <
, delimitMate automatically add >
for me, so with vim-closetag
, there will be an extra >
.
vim-closetag
helped me a lot, thank you very much!
Hi,
My project use react written in .js file
I try to config to apply config of vim-closetag to js file but it's not working
Thanks for any helps
A declarative, efficient, and flexible JavaScript library for building user interfaces.
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. πππ
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google β€οΈ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.