Mike on the MATLAB Desktop

May 3rd, 2010

Selecting a whole line

I’m thinking of turning posts about our underutilized features into a reoccurring series. What do you think of “Hidden Gems” or “Desktop Tricks & Tips” or “11 Things You Can Do MATLAB, but Were Afraid to Ask”? While I think about these, I’m going to present another Editor feature, along the lines of Two Editor Shortcuts I Bet You Didn’t Know About and Open As Text. This is selecting the whole line in the Editor.

There are two ways to select an entire line with the mouse:

  1. triple click anywhere on the line
  2. click on the space between the break-point gutter and the start of the line

The advantage of the second approach is that you can hold down the mouse button and drag it down to select multiple lines at a time. (You can also drag the selection on the third-click with #1, but I find #2 easier).

The keyboard equivalent is a little messier because they depend on the current location of the caret. For instance if you’re at the beginning or end of a line, you can press Shift + Home or Shift + End to move the caret and select the whole line. If you’re in the middle of the line, you’d have to move to the beginning (Home) or end (End) first.

Were you aware of these mouse actions? What other hidden gems do you find useful?

Also don’t forget currently going on is the MATLAB Programming Contest! It’s not too late to enter, it’s going on through Wednesday. I got to try it out internally, and this is a fun one.

EDIT Jun-22-10: fixed link in paragraph 1

16 Responses to “Selecting a whole line”

  1. Chris replied on :

    I do know about 2 because it’s one of my pet peeves with the Matlab editor. I would dearly love to turn it off. Is there a way to do so?

    I hate it because it makes it hard (at least for me) to put the insertion point at the beginning of a line. About 50% of the time I accidentally select the whole line rather than putting the insertion point at the beginning of the line. Unfortunately, there’s no visual indication of where the “select the whole line” region starts or ends. For me, trying to put the insertion point at the beginning of a line is much more common than selecting an entire line.

    Besides, if I want to select the whole line, I can just triple-click, which I think is standard across Mac OS X. :-)

  2. Yair Altman replied on :

    I guess my personal favorite is Ctrl-D to open the m-function beneath the caret. So much easier than using the Open action in the toolbar or menubar, or to use the edit() function in the Command Prompt.

    BTW, I would love to have Ctrl-D do the same in the Command Prompt – at the moment I need to manually type the edit(etc.). This is not a big nuisance, but it could be a very nice time saver.

    -Yair

  3. Jared replied on :

    @Chris,

    At least on Windows, I believe the mouse pointer turns from a text bar to an arrow as an indication of what it’s going to do (text bar: place caret there; arrow: select line).

    Jared

  4. Chris replied on :

    @Jared,

    Oh, that’s true, I never noticed it. That will help eliminate mis-clicks, thanks. I’d still rather have the feature turned off, though, and have a much larger target for clicking.

  5. Scott Hirsch replied on :

    @Yair –

    At the command windows, Ctrl-D will open the selected function. The behavior is slightly different from the editor, in that the function has to be selected – it won’t work just based on the current caret location. I’ll put it an enhancement request to match the editor behavior (if it makes sense to do so).

  6. Mike replied on :

    @Chris,
    The feature cannot be turned off, but I’ll look into it.

  7. Yair Altman replied on :

    Ah!
    I live and learn… :-)

    Yes – please do enter the enhancement request. I never thought of pre-selecting the token. Command Window F1 works without requiring pre-selection so I expected Ctrl-D to work the same way.

    Many thanks,
    -Yair

  8. OysterEngineer replied on :

    Yes, please continue the series. I’m not too creative, so call it what ever seems best to you.

    And thanks for pointing out these ways to select a line.

    Regarding the triple click, I’ve been doing technical computing since before mice were a common way to control the computer. And, I’ve concluded that a mouse is an inferior & imperfect interface between humans & computers. A mouse is adequate for vague commands. But, technical computing frequently requires precision & a mouse doesn’t score well at that.

    Thus, I’ll play a bit with the triple click. But, I’m unlikely to adopt it. My experience is that about 1/3 of the time, I can’t get the cadence correct for a double click so I’m sure I’ll rarely get the cadence right for a triple click.

  9. OysterEngineer replied on :

    @Scott,

    Thanks for your attention to the consistency. I’m happy to see you are gleaning these blogs for gems like this.

    Now, if you could start on that documentation project . . .

    After all, isn’t that a consistency issue?

  10. Øyvind replied on :

    What I really miss, and haven’t been able to find in Matlab, is block select of text.

    This is a very handy feature you can find in e.g. TextPad, and is priceless when you want to select a column of whatever. Shouldn’t this be a relatively easy feature to add, or is it there, and I just missed it?

  11. Mike replied on :

    @Øyvind,

    This is one of our oft-requested features, but it is not yet implemented in the Editor. And no, it is not at all easy to add.

  12. Øyvind replied on :

    OK. Seems relatively simple, conceptually. At least you are aware of it, then:)

  13. KE replied on :

    Please define “break-point gutter”

  14. Mike replied on :

    KE

    The breakpoint gutter is the the gray strip between the line numbers and the text. For each executable line there is a dash (“-”) that when you click it, turns into a breakpoint.

  15. Mohammed El-Said replied on :

    Dear Mike,

    The link “Two Editor Shortcuts I Bet You Didn’t Know About” in the article refers to the same link as “Open As Text”
    it refers to:
    http://blogs.mathworks.com/desktop/2010/01/25/open-as-text/
    and the right is to make it refers to:
    http://blogs.mathworks.com/desktop/2010/01/18/two-editor-shortcuts-i-bet-you-didnt-know-about/

    Thanks

  16. Mike replied on :

    @Mohammed,

    Thanks! I fixed the link.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks
Mike works on the MATLAB Desktop team.

These postings are the author's and don't necessarily represent the opinions of The MathWorks.