Sublime text - how to select HTML table columns?

3.8k views Asked by At

In Sublime Text, is it possible to select the cells of a specific column in an HTML table? Assume there's no common attribute to hook onto (such as class or position at the end of a row) so multi-select isn't helpful in this context.

<table>
  <tr>
    <td>col 1.1</td>
    <td>col 2.1 - I'd like to select this</td>
    <td>col 3.1</td>
  </tr>
  <tr>
    <td>col 1.2</td>
    <td>col 2.2 - ...and this</td>
    <td>col 3.3</td>
  </tr>  

2

There are 2 answers

0
Thomas Roch On

Do the following

  • Select <tr>
  • Press ALT + F3
  • Press down arrow as many times as required (so that each cursor is on the right column)
  • Move cursor right so it is at the end of <td>
  • Press SHIFT + End. Maintain SHIFT pressed and press left arrow 5 times
0
Aditya On

To perform SEARCH AND/OR REPLACE, open replace box using Ctrl+H or menu (Find>Replace). In the bottom bar, select the first button that enables regular expressions. It looks like [.*]. There will be two boxes - first one for search, second one to write the replacement.

Search for :

(<tr>\s+<td>.+</td>\s+<td>)(.+)(</td>)\n

This will find and select upto second TD in each row.

Now you wish to replace only content of second TD. That's done using regex groups marked by brackets. So you can write

$1 REPLACEMENT $3

in the second textbox marked "Replace With". I love Sublime Text mainly because of its regex capabilities like VIM but far more simple and intuitive interface.