Select Multiple Lines, Words, & Columns

On this page…

    What is it?

    For example, say you have the following:

    Lorem ipsum  
    Dolor sit amet  
    Consectetur adipisicing elit  
    Sed do eiusmod tempor  
    Incididunt ut labore
    

    You want to quickly turn these into an unordered list in Markdown, which means placing a * followed by a space at the beginning of each line. You could do this manually, but Sublime Text makes it very easy to automate the task.

    Adding lines to a multiple selection

    Given this:

    Lorem ipsum  
    Dolor sit amet  
    Consectetur adipisicing elit  
    Sed do eiusmod tempor  
    Incididunt ut labore
    

    Follow these steps:

    1. Place your cursor in front of Lorem.
    2. Press Ctrl+Alt-Down if you're using Windows & Ctrl+Shift-Down if you're using a Mac. You'll see that the cursor stays in front of Lorem ipsum, but that it moves down & also appears in front of Dolor sit amet.
    3. Press the key combination again 3 more times, so there is a cursor in front of each line.
    4. Type * followed by a space. You'll see that what you type appears in front of each selected line.
    5. When you're finsihed typing, press Esc to cancel the multiple selection.

    You should now see this:

    * Lorem ipsum  
    * Dolor sit amet  
    * Consectetur adipisicing elit  
    * Sed do eiusmod tempor  
    * Incididunt ut labore
    

    "I went too far!"

    If you go down (or up too far) in your selection, press Esc to cancel & start over, or press Ctrl+U (Windows) or Command+U (Mac OS X) to undo the selection.

    Select multiple instances of a word

    What if you have several instances of a word that you want to change? Not every instance—for that, you'd use Find & Replace or the technique in the next section, "Select all instances of a word"—but instead several instances. In those cases, follows these steps:

    1. Place your cursor somewhere in or next to the word you wish to select.
    2. Press Ctrl+D (Windows or Linux) or Command+D (Mac OS X) to highlight the entire word.
    3. Press Ctrl+D (Windows or Linux) or Command+D (Mac OS X) to select the next instance of the word.
    4. Repeat until you've selected the words you want to change.
    5. If you go too far & select an instance of the word you don't want, press Ctrl+U (Windows or Linux) or Command+U (Mac OS X) to deselect that instance.
    6. Type to replace the selected words with your changes.

    Select all instances of a word

    Now you want to change every instance of a particular word. You could use Find & Replace, or you can follow these steps:

    1. Place your cursor somewhere in or next to the word you wish to select.
    2. Press Alt-F3 (Windows or Linux) or Command+Ctrl+G (Mac OS X) to highlight every instance of the word in the document.
    3. Type to replace the selected words with your changes.

    Select multiple words with the mouse

    What if you want to change muliple words on a page, but they're not all the same words? So you want to select foo & bar & foobar & barfoo? For that, follow these steps:

    1. Place your cursor somewhere in or next to the first word you wish to select.
    2. While holding down Ctrl (Windows & Linux) or Command (Mac OS X), click in the next word you wish to select.
    3. Repeat until you've selected the words you want to change.
    4. Type to replace the selected words with your changes.

    Supposedly you can press Alt to de-select a word.

    Select columns

    Why select columns of text? An example will help. Recently I had this text:

    drwx------+ 22 rsgranne  staff   748B Jul  6 15:55 Desktop/
    drwx------+ 25 rsgranne  staff   850B Jul  5 11:45 Documents/
    drwx------+ 43 rsgranne  staff   1.4K Jul  6 13:45 Downloads/
    drwx------@ 22 rsgranne  admin   748B Jul  5 11:45 Dropbox/
    drwx------@ 74 rsgranne  staff   2.5K Jun 24 10:49 Library/
    drwx------+  9 rsgranne  staff   306B Jul  5 11:45 Movies/
    drwx------+ 11 rsgranne  staff   374B Jul  5 11:45 Music/
    drwx------@ 51 rsgranne  staff   1.7K Jul  5 11:45 Pictures/
    

    I wanted to get rid of all the groups in each line except the 1st (drwx------+ in the first line) & the last (Desktop/ in the first line), leaving this:

    drwx------+ Desktop/
    drwx------+ Documents/
    drwx------+ Downloads/
    drwx------@ Dropbox/
    drwx------@ Library/
    drwx------+ Movies/
    drwx------+ Music/
    drwx------@ Pictures/
    

    Notice how everything lines up in neat columns. Because it does, it was easy to use column select to choose everything from 22 in the first line down to 11:45 in the bottom line & then nuke it.

    To select text in columns, follow the steps appropriate to your pointing device below.

    With a mouse that has a wheel:

    1. While holding down the wheel, click & drag to select the columns of text.
    2. Type to replace or remove the selected text.
    3. Press Escape when you are finished.

    With a mouse lacking a wheel, or a trackpad:

    1. While holding down Command & Alt (Mac OS X) or Ctrl & Alt (Windows & Linux), click & drag to select the columns of text.
    2. Type to replace or remove the selected text.
    3. Press Escape when you are finished.
    WebSanity Top Secret