wheresrhys
wheresrhys

Reputation: 23500

First letter capitalisation with multiple cursors in sublime

In sublime if I use cmd+D to select every occurrence of 'old' the selection is case insensitive so will match old and camelOld. But when I start typing the capitalisation is not respected so i will get new and camelnew. Are there any shortcuts or plugins to get sublime to preserve first letter capitalisation when typing using multiple cursors?

Upvotes: 4

Views: 1347

Answers (2)

jcen
jcen

Reputation: 1631

  1. Select your word
  2. Select all occurences you want to change (ctrl+d)
  3. Open Find > Replace (ctrl+h)
  4. Check "in selection" and "preserve case" (alt+a), uncheck regex (alt+r) and other stuff you don't want
  5. Go to lower field, write your replacement
  6. Replace all

There are key shortcuts for all the steps except for "toggle_in_selection". You can put this in your keys to fix it:

{ "keys": ["alt+s"], "command": "toggle_in_selection", "context":
    [
        { "key": "setting.is_widget", "operator": "equal", "operand": true }
    ]
},

NOTE: change the shortcut to whatever suits you best.

Alternatively, you can put this in your keys:

{ "keys": ["ctrl+h"], "command": "show_panel", "args": {"panel": "replace", "in_selection": true, "preserve_case": true, "regex": false, "highlight": true} },

with custom shortcut. You can use the original shortcut to overwrite it's default behavior.

It will prepare all those toggling and checking for you, so you can just

  1. Select
  2. ctrl+d all occurrences
  3. use this shortcut
  4. tab to go to lower field, write your replacement
  5. ctrl+alt+enter to replace all

...be careful, with "replace all"

Upvotes: 7

Tim Krins
Tim Krins

Reputation: 3819

There is a Sublime plugin that will help you do this a bit easier:

https://github.com/philippotto/Sublime-MultiEditUtils

The case preservation code was just merged today.

See the heading "Preserve case while editing selection contents"

Upvotes: 3

Related Questions