Git Product home page Git Product logo

html-attrs.vim's Introduction

html-attrs.vim

A simple plugin to add or modify HTML tags attributes

WARNING!

This is a work in progress. Right now it is a lame and stupid plugin.

How it works

The idea is quite simple: when editing some HTML code I usually need to add an id or tweak a CSS class.

While inside an HTML tag I want to be able to:

  • Add an id attribute or change it if it exists
  • Add a class attribute or change it if it exists

Examples

In the following examples the "|" character represents the current cursor position.

Given:

<span>some text|</span>

Run the HtmlAttrsAddId command and you get:

<span id="|">some text</span>

Given:

<span id="my-id">some text|</span>

Run the HtmlAttrsAddId command and you get:

<span id="|my-id">some text</span>

Given:

<span class="my-class other-class">some text|</span>

Run the HtmlAttrsAddClass command and you get:

<span class="|my-class other-class">some text</span>

Given:

<span>some text|</span>

Run the HtmlAttrsAddClass command and you get:

<span class="|">some text</span>

### Options

The only available option right now is html_attrs_remove_existing_id. When set to 1 (it defaults to 0) the HtmlAttrsAddId command will replace the existing id (if any).

So, given:

<span id="my-id">some text|</span>

Running the HtmlAttrsAddId command will give you:

<span id="|">some text</span>

Handling nested tags

The plugin uses tag text objects for finding the tag start, so given:

<p>
  <span>
  </span>
  |
</p>

After running the HtmlAttrsAddId command you get:

<p id="|">
  <span>
  </span>
</p>

Specs

The plugin has a set of specs written in Ruby using Rspec + vimrunner.

In order to test the plugin (assuming you have got Ruby and Bundler installed):

  1. Run bundle install
  2. Run rspec

You can also run guard and get the specs automatically executed every time you change a file.

TODO

See the issues.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.