sponsor Vim development Vim logo Vim Book Ad

tagasort.vim : Sort and format the attributes of html and jsx tags.

 script karma  Rating 44/11, Downloaded by 199  Comments, bugs, improvements  Vim wiki

created by
Josť Villar
script type

The idea of Tagasort is to improve the readability of attributes of html and jsx tags. To do so, the attributes are sorted alphabetically and formatted to enforce a consistent style. Note that this plugin was designed with Vim's autoload functionality in mind to keep your Vim startup time low.


The following case shows a tag before and after using the plugin.


    <Box z={ 1   } color="red" onPress={()=>onClick(id )} a={5 } >


    <Box a={ 5 } color="red" onPress={ () => onClick( id ) } z={ 1 }>


Tagasort works in normal mode. To use it, place your cursor anywhere inside a tag and then hit the space bar twice. If you use it outside a tag, it will search for the next tag in the current line and use that as the target.


You can easily change the key combination that triggers the plugin. For example, if you wanted to change the default mapping to <Leader>0 , you would have to add the following line to your vimrc:

    nmap <unique><Leader>0 <Plug>Tagasort_FormatTag


- This plugin doesn't work with tags whose attributes are spread across multiple lines.
- Nvim has magic enabled by default. Make sure to keep it this way, or else the plugin will have serious performance issues.


install details
Use your favorite plugin manager.


1. Add the following line to your vimrc:
    Plug 'jose-villar/vim-tagasort'

2. From within Vim, run:


rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
vim-tagasort-main.zip 1.2.4 2021-04-16 7.0 Josť Villar Fix bug regarding colon characters.
vim-tagasort-main.zip 1.2.3 2021-04-11 7.0 Josť Villar Fix bug regarding non single-byte characters

The bug prevented it from working with tags that had attributes
containing certain characters such as š or Š.
vim-tagasort-main.zip 1.2.2 2021-04-06 7.0 Josť Villar Fix bug regarding whitespace characters after commas.
vim-tagasort-main.zip 1.2.1 2021-02-18 7.0 Josť Villar Add compatibility with Tim Pope's vim-repeat plugin
vim-tagasort-main.zip 1.1 2021-02-10 7.0 Josť Villar Add support for single quote string attributes
tagasort.zip 1.0.1 2021-02-04 7.0 Josť Villar Fix typo in the documentation
tagasort.zip 1.0 2021-02-04 7.0 Josť Villar Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.