How do you find and replace within selection in sublime text 3?

  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,

Select the word by pressing CMD+D it selects 1 from whole file and show transparent selection of all related word you can press more times CMD+D for selecting all word then edit it all words take places


You can (using ctrl-h, then toggling the 'in selection' option from the dialog), but it's a bad design IMO. Firstly, if you have an area of text highlighted when you request 'replace', it should assume "replace in selection" automatically. Secondly, as soon as you choose 'replace' it thoughtfully cancels the text selection for you. The whole process ends up involving cumbersome repetition, or an illogical sequence of steps. Visual Studio gets the UI design right; Sublime does not.