Search code examples
sublimetext3text-editor

Find and replace within selection in sublime text 3?


I've read this thread indicating how to find and replace within selection in ST2. Despite reading this thread but still cannot figure out if it's possible to do a simple find and replace within selection in ST3?


Solution

    1. Ensure the find and replace panel is closed.
    2. Select the text in which you want to perform the find/replace - i.e. define your selection.
    3. Open the Find/Replace panel - if desired, you can use a keybinding to run the show_panel command by going to preferences -> keybindings, then adding this line to the user keybindings: { "keys": ["ctrl+shift+s"], "command": "show_panel", "args": { "panel": "replace", "in_selection": true } } to ensure that the "in selection" mode is active and skip the next step. (see the forums for more available args.)
    4. Turn on "in selection" mode if it is not already active by clicking on the button in the panel.
    5. Enter your find/replace terms and perform your find/replace

    If you want to change the selection you are searching within, you will need to close and re-open the panel.

    If the region/selection you are searching within always contains multiple lines, you may want to consider setting the following preference for convenience:

    // When auto_find_in_selection is enabled, the "Find in Selection" flag
    // will be enabled automatically when multiple lines of text are selected
    "auto_find_in_selection": true,