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: >&...
romainl's user avatar
  • 39.3k
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 ...
Rich's user avatar
  • 31.3k
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 ...
Tommy A's user avatar
  • 6,710
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 ...
Matt's user avatar
  • 20.4k
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 ...
B Layer's user avatar
  • 19.6k
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 ...
Antony's user avatar
  • 2,550
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 ($...
romainl's user avatar
  • 39.3k
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> ...
Sheharyar's user avatar
  • 751
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 ...
Atav32's user avatar
  • 171
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 ...
Jake Grossman's user avatar
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 ...
Maxim Kim's user avatar
  • 12.4k
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 ...
Boris Brodski's user avatar
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 ...
Tumbler41's user avatar
  • 7,706
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 ...
Jair López's user avatar
  • 1,834
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 ...
Biggybi's user avatar
  • 2,700
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,...
Mass's user avatar
  • 14k
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 ...
Igor's user avatar
  • 56
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. ...
Christian Brabandt's user avatar
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,...
Martin Tournoij's user avatar
3 votes

How to override a ftplugin

On Windows, $HOME/vimfiles/after/ftplugin/foobar.vim runs after loading the standard foobar ftplugin.
TankorSmash's user avatar
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 ...
akku's user avatar
  • 31
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 ...
ZeroKnight's user avatar
  • 1,071
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 ...
Azamat Ali 's user avatar
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>`< ...
Mass's user avatar
  • 14k
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/...
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 ...
Matt's user avatar
  • 20.4k
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 ...
MDeBusk's user avatar
  • 363
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 ...
the_velour_fog's user avatar
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 ...
Sharma SRK Chaitanya Yamijala's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible