10

On Windows, I use Notepad++ which has the great feature of when I select a word, all instances of that word are also highlighted in the same document. I have found it very helpful for finding patterns in giant log files.

I am wondering if there is a similar feature in a text editor on the Mac. I have looked into the documentation for TextWrangler and TextMate to no avail. Hopefully there is a way to do this so I can be more productive when working on a Mac.

--

Note: in Notepad++ you do not have to do a keyboard shortcut to make this work... you just select some text and it does the highlighting for you automatically.

2
  • What happens when you do a "Find" in TextEdit? Does it not highlight all the instances of the text (I apologize; I don't have my Mac in front of me at the moment)?
    – jrc03c
    Jul 19, 2010 at 16:20
  • In TextEdit, "Find" iterates through each match. I am looking for a way to avoid using a keyboard- or menu-shortcut... just select a word and highlight the other instances of that word in the document.
    – jedierikb
    Jul 19, 2010 at 16:24

10 Answers 10

5

Sublime Text is able to do that.

1
  • FYI, a Textmate 2 solution is described below. ST is nice also :-)
    – tim
    Mar 30, 2013 at 21:21
5

Who said BBEdit couldn't do it?

With your document in the front window:

  • Choose Search > Live Search ⌥ ⌘ F
  • Enter your search string
  • Notice that all instances of that string are now highlighted in your document

To make Live Search go away, click the Done button.

Reference: BBEdit 9.5 User Manual, pages 159-160

4
  • This looks promising! (only been using TextWrangler...). However, reading the documentation, it appears I would still need to enter the query I want into the Live Search field instead of anything I select with the mouse becoming a new Live Search query.
    – jedierikb
    Jul 19, 2010 at 21:01
  • 2
    Select the text, ⌘C, ⌥⌘F, ⌘V—and you're done. Yes, it's a couple of extra keystrokes, but I don't think that you'll get any closer. If you want to search based on selected text, there's also Use Selection for Find (⌘E), but I don't see that it works with Live Search.
    – Dori
    Jul 19, 2010 at 22:21
  • 1
    Works in TextWrangler also May 18, 2011 at 20:47
  • @Dori, Is there a particular reason Live Search isn't the default (Ctrl F)?
    – Pacerier
    May 18, 2018 at 3:27
3

In addition to @Tim's answer, but also with input from this message on TextMate's mailing list , one can create the following one-key shortcut:

(
    {   command = 'selectWord:'; },
    {   command = 'copySelectionToFindPboard:'; },
    {   command = 'findAllInSelection:'; },
)

I assigned this to Command-A, and it works quite nicely, highlighting all occurrences of the word under cursor, whether pre-selected or not.

Caveats: this action will scroll the file to the last occurrence of the highlighted word, so one has to manually scroll back. In addition, this will trigger automatic substitution of all occurrences with the typed text ("parallel edit"), which is convenient in many cases but one has to be careful if this is unintended.

3

Earlier versions of BBEdit may not have been able to do this, but as of version 11, this is possible via:

Preferences -> Editing -> Highlight instances of selected text

Do note that the "free version" of BBEdit, called "TextWrangler", doesn't have this feature (it seems to be one of a number of items reserved for TextWrangler's big brother to sweeten the pot for upgraders).

3

TextMate 2 does this really nicely bound to control-W

This macro [1] is built in.

^W will select a word, but once a selection exists, ^W will add the next instance to the (mult-) selection: Really nice feature!

Even better: double tap the shift key to un-select the last-added instance (great if you overshoot the set you wanted to select.

Even better: All of these are now separate selections, so you can type edit select and it works on each separately, but synchronously. Fabulous time saver!

[1] It's just a macro bound to ^W with a dyn.selection Scope selector

(
    {   command = 'copySelectionToFindPboard:'; },
    {   command = 'findNextAndModifySelection:'; },
)
0
2

Well, BBEdit does incremential search. Emacs/Aquamacs and Vim/MacVim do it too of course. This is really an essential feature for me and I am heartbroken that TextMate and SubEthaEdit still have no support for it.

2

Not exactly what you want but TextMate does also have an incremental search.

Hit Ctrl + S and start typing text. What you type will appear in the status bar at the bottom of TextMate window and will also be highlighted in the opened document, if the opened document contains that text..

Hitting Ctrl + S again will select the next match in the document. It is more immediate than Command + S

0

When I have switched from Windows to OS/X, I was missing Notepad++. After some research I came into Textwrangler. A feature that I used a lot with Notepad++ was the highlighting of all occurrences of a selected word. Textwrangler did not have this feature so easily accessible. It have such feature but you have to use live search (F), but since the moment that the highlighted text is not filled into live search text box you have to copy the highlighted text (C), fire live search (C) and then paste the text (V)

So since I have a magic mouse and better touch tool installed, I have bound a magic mouse gesture to execute double click (to select the work where the cursor is) + C + F + V

0

Visual Studio Code multi-cursor/selection

The free Visual Studio Code has this feature (cmd-shift-L instantly selects all other instances of the current selection, cmd-D the next instance...) - answered in full in another post on Stack Overflow.

Or just See the VS Code keybindings (OS sensitive).

0

Lifehacker.com says Fraise is a nice alternative.

I have no personal experience with it. But it looks nice.

4
  • just tried it -- alas, it does not seem to do what I am looking for.
    – jedierikb
    Jul 19, 2010 at 19:41
  • Damn. sorry. Was it at least any good (in general)?
    – alpha1
    Jul 21, 2010 at 2:05
  • Well, it opened a text file and let me write it in it and save it! :-)
    – jedierikb
    Jul 21, 2010 at 3:01
  • For future reference, development has been stopped on this program. It is available as a "Mac App" under the name "Smultron" peterborgapps.com/smultron
    – zourtney
    Mar 11, 2011 at 3:08

Not the answer you're looking for? Browse other questions tagged .