Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 553
wheresrhys Avatar asked Dec 26 '22 10:12

wheresrhys


2 Answers

  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"

like image 64
enrey Avatar answered Jan 31 '23 00:01

enrey


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"

like image 30
Tim Krins Avatar answered Jan 30 '23 23:01

Tim Krins