Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigate between words in two ways using different separators

Thanks to Visual Studio Code—Customizing word separators I was able to set underscore as separator. So now whenever I press Ctrl+Left Arrow, VS code recognizes that the word starts right after the underscore. However sometimes I want go at the very beginning of the variable/function/class name and, using underscore as separator, I have to press Ctrl+Left Arrow several times to get there. Is there any way to get a behavior like:

  • Ctrl+Left Arrow it considers underscore as separator
  • Ctrl+Alt+Left Arrow it doesn't consider underscore as separator
like image 494
Leonardo Boscolo Avatar asked Sep 12 '25 08:09

Leonardo Boscolo


1 Answers

Another possible way for achieving the desired behaviour is through the following steps:

  1. Exclude _ from the word separators in case you still have it included.

  2. Add the two following keybindings to your keybindings.json :

     {      
        "key": "ctrl+shift+left",    
         "command": "cursorWordLeft",
         "when": "textInputFocus"
     },
    
     {
         "key": "ctrl+left",
         "command": "cursorWordPartLeft",
         "when": "textInputFocus"
     }
    

The first keybinding allows you to move to the left of a word by pressing Ctrl + Shift + Left Arrow.

The second keybinding allows you to move to the left of a word by pressing Ctrl + Left Arrow but considering _ this time.

like image 193
inpap Avatar answered Sep 13 '25 20:09

inpap