Sublime Forum

Deleting a Word

#1

When my cursor (caret) is on the left side of a word and I hit [Ctrl-Del], virtually all Windows applications since Windows 3.1 (1992), delete the entire word and the space after it, placing the first letter of the next word next to the cursor. I am guessing most editors’ basic editing behaviors are modeled after the cursor navigation (and word deletion) behavior of the Windows TextBox control, which was well documented in the Windows 3.1 User’s Guide. That includes the Markdown editor I am typing this question into.

But when I do that with Sublime Text, it only deletes to the end of the current word, leaving 2 spaces between the two words, which then requires an additional keystroke to get rid of.

[Ctrl-RightArrow] is similarly affected, where I expect the cursor to to go the beginning of the next word, but instead it takes the cursor to the end of the current word, although [Ctrl-LeftArrow] does land the cursor at the beginning of the previous word as expected.

There are only 2 editors I have ever encountered that behave this way:

  • PyCharm, and
  • Sublime Text

I tried adding a space to the word_separators list in my Packages/User/Preferences.sublime-settings (since it is not already there), but it didn’t seem to change anything.

Is there a way to get that behavior to behave like other editors? My fingers’ muscle memory would appreciate it if there was a way to do this…

Kind regards,
Vic

0 Likes

#2

Can’t say anything about conventions sublimehq chose to follow, but with regards to word navigation in general, you probably want to have a look at How to set "Word boundaries"?.

ctrl+right is bound to word_ends by default.

{ "keys": ["ctrl+right"], "command": "move", "args": {"by": "word_ends", "forward": true} },

You could tweak it to always jump between word beginnings by creating an override like:

{ "keys": ["ctrl+right"], "command": "move", "args": {"by": "words", "forward": true} },
1 Like

#3

Thank you very much!

Interesting that my inquiry and How to set “Word boundaries”? happened at nearly at the same time… You put in quite some investigation into that! It leaves me wishing I could see the source code for the word and delete_word commands to see what arguments they take. But it also makes me realize that I could direct those keys to my own custom commands as well… That could be interesting.

Indeed changing the “by” argument to “words” changes the behavior of [ctrl+right] but I am finding that if [ctrl-del] behavior doesn’t match, it confuses my muscle memory. My “hands” expect all of the ctrl-modified key combinations to have the same behavior. At least, out of the box, it is consistent. That fact may have more weight than trying to modify it…

0 Likes