Is there a fast way to paste consecutive numbers i

2019-05-09 13:17发布

问题:

When working with HTML ids it is often necessary to create elements with same id names, but different numeric index, for example:

<ul>
   <li id="item-|"></li>
   <li id="item-|"></li>
   <li id="item-|"></li>
   <li id="item-|"></li>
   <li id="item-|"></li>
</ul>

"|" - represents one of the multiple cursors. Is there a way to paste numbers from 1-5 there?

回答1:

For PhpStorm:

You can use the String Manipulation plugin.

To generate numbers in sequence at the multiple carets:

  1. Type in the number to start the sequence with, say 1, and then select the number.

  2. Open the String Manipulation menu. This is done by

    • Alt+M, or
    • Alt+Shift+M, or
    • Pull Down MenuEditString Manipulation.
  3. In the menu, choose Increment/DecrementCreate sequence.

Here's an animated screenshot: Screenshot is based on PhpStorm 2016.2 and String Manipulation 5.0.135.445.0.



回答2:

you can install the emmet plugin for sublime text from the package control. here is the emmet cheat sheet Every web developer used it and saves heck a load of time


type ul>li#item-$*5 and press tab and the whole code will be generated :

<ul>
  <li id="item-1"></li>
  <li id="item-2"></li>
  <li id="item-3"></li>
  <li id="item-4"></li>
  <li id="item-5"></li>
</ul>


回答3:

There is a plugin called insertNums that does exactly what you are looking for. You can use it to insert a sequence of numbers into the cursors positions.

It also allows you to define some options like the start number and the step between numbers and others.