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 377  Comments, bugs, improvements  Vim wiki

created by
José Villar
 
script type
utility
 
description
INTRODUCTION

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.

EXAMPLE

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

Before:

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

After:

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

USAGE

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.

MAPPINGS

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

LIMITATIONS

- 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.

GITHUB REPOSITORY

    https://github.com/jose-villar/vim-tagasort
 
install details
Use your favorite plugin manager.

USING PLUG

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

2. From within Vim, run:

    :PlugInstall
 

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: 3.236.219.157

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.
   
Vim at Github