13
votes
How to generate closing tags for HTML?
Here is a simple ad-hoc solution to put in ~/.vim/after/ftplugin/html.vim:
inoremap <buffer> > ></<C-x><C-o><C-y><C-o>%<CR><C-o>O
Breakdown:
>&...
9
votes
How to override a ftplugin
Overriding a plugin manually
Unless you intend to change all of the settings set by Vim's existing html ftplugin, you want your plugin to be loaded before it. The setting of the b:did_ftplugin ...
9
votes
Accepted
How do I paste the same line of code X times but change one word in the line each time?
For what you want to do, emmet-vim, as nobe4 suggested, is your best bet.
In insert mode, li{item $}*10<c-y>, will expand 10 <li>s with item N prefilled as the text. You'll start editing ...
9
votes
Accepted
HTML - Wrap current tag inside another tag
In vim-surround ys{motion} puts "a surround text" on the same line. To place it on a line of its own with indent you should use yS{motion} instead.
Next, a motion you want for this case is :h at (a ...
7
votes
Accepted
Expand <TAB> into 2 spaces when and only when editing HTML
Put this in your .vimrc file:
autocmd BufRead,BufNewFile *.htm,*.html setlocal tabstop=2 shiftwidth=2 softtabstop=2
Briefly, autocmds get processed when the specified events occur for the specified ...
6
votes
Accepted
How do I open several FORTRAN files in Vim and save them as HTML files?
After you've added your files to the arguments list with :n ./**/*.f90 (:args + filenames would do the same thing and is perhaps more obvious) you can use:
:argdo exe 'TOhtml' | wq
:argdo will ...
6
votes
Accepted
Why does Vim load unrelated ftplugins?
Vim already comes with Markdown support so what happens is that you have two Markdown ftplugins doing the same thing. Since you "fixed" one (~/.vim/ftplugin/markdown.vim) without "fixing" the other ($...
5
votes
How to generate closing tags for HTML?
See vim-closetag
It's exactly what you're looking for. From it's README:
If this is the current content:
<table|
Now you press >, the content will be:
<table>|</table>
...
5
votes
Disabling partial HTML indentation in Vim
I recommend the tidy-html5 plugin.
As a web developer myself, I also recommend aligning the HTML tags a little differently,
AirBnb React Styleguide (most legible & recommended for React)
<a ...
5
votes
Accepted
Syntax coloring is inaccurate for HTML files with CSS code in it
Sometimes, Vim can lose track of where it is highlighting from, especially in complex scenarios (nested languages, in this example).
You can tell Vim where it should sync the syntax highlighting from ...
5
votes
Accepted
How do I delete a self closing html tag?
Are you looking for da< or da>?
d deletes text (see :help d), and is followed by a motion movement (see :help motion.txt)
a< or a> selections the text that starts with < and that ends ...
4
votes
How to jump between matching HTML/XML tags?
The xmledit (http://vimawesome.com/plugin/xmledit) plugin allows to jump between open and close tags using
<localleader>%
Often <localleader> will be \, so you can jump with
\%
NOTE: Unlike ...
4
votes
Nested highlighting
Ok, this is probably not the best solution because it is pretty invasive. But, it's all I could come up with so I will give it to you.
One thing we can do is basically manually do the highlighting ...
4
votes
Accepted
How can I shift only inner contents of HTML element?
That's a great opportunity to leverage text objects (see :help text-objects). The following code extends the normal behavior of the it text object (see :help it and :help tag-blocks) to make it ...
4
votes
Add matching html tag
You could use the plugin called vim-closetag which does exactly this.
The big advantage over the default omni-completion is you don't need to type as much.
The matching closing tag will be ...
4
votes
Accepted
Add matching html tag
In vim, you can complete open html tags and close tags using omni-completion, invoked via ctrl-xctrl-o. To do this though, you must first type < or </ depending on which tag you want. For close,...
4
votes
Accepted
Text Object for HTML/XML attributes, e.g. data-foo="bar baz caz"
The vim-textobj-xmlattr plugin does exactly that.
This vim plugin provides two text objects: ax and ix.
They represent XML/HTML attributes.
ix works with the inner attribute, with no surrounding ...
3
votes
Accepted
How can I override a syntax keyword match?
Well you can of course dive into the complex syntax rules, see @Carpetsmoker's answer. However that might not always work correctly, depending on the order of the syntax rules and their priorities. ...
3
votes
How can I override a syntax keyword match?
You'll need to modify the contains of syn region htmlTag to include your new htmlArgId. The full line would be:
syn region htmlTag start=+<[^/]+ end=+>+ fold contains=htmlTagN,htmlString,...
3
votes
How to override a ftplugin
On Windows, $HOME/vimfiles/after/ftplugin/foobar.vim runs after loading the standard foobar ftplugin.
3
votes
Why does Vim load unrelated ftplugins?
According to the Markdown specification, you are allowed to use inline HTML for any markup that is not covered by Markdown's syntax. For this reason, the Markdown configuration of Vim's ftplugin also ...
3
votes
NeoVim indents each property:value in CSS
This particular issue seems to have come up more than once:
A 2009 Stack Overflow question*
A post in the Vim subreddit from just a few months ago
Unfortunately the replies and answers mostly ...
3
votes
HTML - Wrap current tag inside another tag
As you are surrounding single line you VS<div>
Let's break it down:
V enter visual by line select mode
S surround with...
<div>
Your y s s < d i v >
command ...
3
votes
Accepted
Easiest way to go to start/end of html element
Although vim provides text objects for tags, it doesn't have motions for tags.
One options is to reuse it to create a pair of maps [t and ]t somewhat analogous to [b:
nnoremap [t vit<esc>`<
...
3
votes
Accepted
Vim HTML syntax highlight doesn't correctly identify comment endings consisting of minuses
This was a bug in Vim's HTML syntax, which @Matt has fixed with lightning-speed.
Upgrade to an upcoming version of Vim to fix this, or simply copy runtime/syntax/html.vim from Matt's fork into ~/.vim/...
Community wiki
3
votes
Vim HTML syntax highlight doesn't correctly identify comment endings consisting of minuses
To shed some light on what's going on. As you probably know, HTML originates from SGML. In SGML they could write something like that:
<!ELEMENT some serious stuff
--
Some stupid comments
...
3
votes
Are there color variables for various programming languages?
A "color scheme" is not language-specific. Every file will use the same color scheme. Here's an old question with some good answers on creating your own color scheme, though, if that's ...
2
votes
How can I indent JavaScript that's within <script> tags in an HTML file?
Based on @SatoKatsura's comments, here is a shell script (for UNIX like systems) which will install js-beautify and setup the python executable as a command.
Just to clarify, this will install the ...
2
votes
How do I open several FORTRAN files in Vim and save them as HTML files?
As pointed by "Karl Yngve Lervåg" in his comments, combining the answers of both "Karl Yngve Lervåg" and "Antony" gave me the desired result.
So, after opening the first .f90 file, you should use the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filetype-html × 62indentation × 18
syntax-highlighting × 9
vimrc × 6
filetype-javascript × 4
filetype-scss × 4
vimscript × 3
search × 3
autocompletion × 3
folding × 3
formatting × 3
filetype-xml × 3
filetype-php × 3
neovim × 2
colorscheme × 2
cursor-motions × 2
filetype × 2
custom-text-object × 2
key-bindings × 1
cut-copy-paste × 1
substitute × 1
cursor-movement × 1
insert-mode × 1
visual-mode × 1
replace × 1