Allow for sub word selection using ctrl + shift + left/right


#1

While using option + shift + left/right works to select an entire keyword, SL and Xcode let you select individual words within in a camelCase or snake_case formatted string using ctrl + shift + left/right.

E.g. if the cursor is at the beginning of oneTwoThree, pressing ctrl + shift + right would only select one.

Any way to get this feature working in Atom? I see that in the keybindings they’re mapped to native!, but something seems to be blocking them.


Using ctrl-left/right to move sub-words?
#2

I’ve seen this feature being referred to as “subword selection” in other editors.


#3

I’m missing this feature from Sublime as well. I found this package that does it with ctrl+alt instead of ctrl+shift https://atom.io/packages/word-jumper, I’m trying it out to see how it goes.


#4

Thanks for the hint to the package, this is great. I do hope this makes it into Atom proper though.


#5

Thanks for the recommendation! I’ll also check out this package. Subword navigating is my main way of moving around a line while I’m editing, and it’s the biggest thing I’m missing, coming from Sublime Text and trying out Atom. Would very much like to see this feature incorporated into the public release version.


#6

This was one of the only annoyances I had when trying out atom. Fixed it with this:

'.editor':
  'ctrl-left': 'editor:move-to-beginning-of-word'
  'ctrl-right': 'editor:move-to-end-of-word'
  'ctrl-shift-left': 'editor:select-to-beginning-of-word'
  'ctrl-shift-right': 'editor:select-to-end-of-word'

#7

@g105b This is not fixing our issue, we are looking for subword movement, not beginning-of-word (which is already in Atom with alt modifier - for mac os)

I ended up using word-jumper package with the following keymap.cson:

'.editor':
  'ctrl-right': 'word-jumper:move-right'
  'ctrl-left': 'word-jumper:move-left'
  'ctrl-shift-right': 'word-jumper:select-right'
  'ctrl-shift-left': 'word-jumper:select-left'
```

But it should be native to atom.

#8

Is there a bug tracking the implementation of this behavior? Using ctrl+shift+arrows to move tabs in the tab bar by default is a waste of prime key real estate!


#9

Turns out it’s in Atom, just bound to the wrong keys by default. (Why?)

'.editor':
  'ctrl-right': 'editor:move-to-next-subword-boundary'
  'ctrl-left': 'editor:move-to-previous-subword-boundary'
  'ctrl-shift-right': 'editor:select-to-next-subword-boundary'
  'ctrl-shift-left': 'editor:select-to-previous-subword-boundary'

#10

@nikolaus Thank you sir! Now I’m a convert :slight_smile:


#11

There are no right bindings. Users come from a lot of types of editors on a lot of OS’s.


#12

On OS X, ctrl+arrows moves by subwords in Xcode, TextMate, Sublime Text, and all other programming editors that I know of. In that sense, I would call them the right bindings. If you bind those keys to something else, programmers will get confused and frustrated and post on Discourse about how Atom uses the wrong keybindings. :slightly_smiling:


#13

I’ve used four or five programming editors on windows before moving to Atom on linux and my experience does not match yours.

And if you change the bindings to what you want someone else will get confused. Why do you think every editor allows you to change bindings? Your view of what is right is kind of myopic.


#14

I think I see the problem: I think that it should be bound this way by default on OS X, but perhaps you think I think it should be bound this way on all platforms? On Windows and Linux, ctrl+arrows should obviously be bound to move by whole words, because that is the default on those platforms. Perhaps your view of my views is myopic?


#15

Your view of my view of your view is myopic. (grin)

I just meant you didn’t widen your thinking enough to include everyone, but now your good idea of setting defaults by OS can take in everyone.


#16

Back to my original question, then! Is there a bug tracking this behaviour?


#17

Given your new idea it should be a feature request. It is not a bug if it works (by user config) like all the other editors.


#18

It’s awesome, but… This config doesn’t accept “Non Word Characters” from settings (i added underscore for snake-case).


#19

I put in all these bindings because I also use Emacs bindings.

‘atom-text-editor’:
‘alt-b’: ‘editor:move-to-previous-subword-boundary’
‘alt-backspace’: ‘editor:delete-to-beginning-of-subword’
‘alt-d’: ‘editor:delete-to-end-of-subword’
‘alt-f’: ‘editor:move-to-next-subword-boundary’
‘alt-left’: ‘editor:move-to-previous-subword-boundary’
‘alt-right’: ‘editor:move-to-next-subword-boundary’
‘alt-shift-B’: ‘editor:select-to-previous-subword-boundary’
‘alt-shift-F’: ‘editor:select-to-next-subword-boundary’
‘alt-shift-left’: ‘editor:select-to-previous-subword-boundary’
‘alt-shift-right’: ‘editor:select-to-next-subword-boundary’


#20

Hi guys, I have also run into this issue. Some of the work-arounds seem ok, but nothing mimics like visual studio and other editors in Windows for me. In the end, I wrote a couple of functions and put them into my init.coffee file. They seem to be working as I like for now. I wanted to share:

init.coffee

selectSubwordToRight = (editor) ->
  range = new Range()
  range.start = editor.getCursorBufferPosition()
  editor.selectToEndOfWord()
  range.end = editor.getCursorBufferPosition()
  if /[ \t\r\n\f]{1,}[^ \t\r\n\f]/.test editor.getTextInBufferRange range
    editor.selectToBeginningOfWord()

selectSubwordToLeft = (editor) ->
  range = new Range()
  range.start = editor.getCursorBufferPosition()
  editor.selectToBeginningOfWord()
  range.end = editor.getCursorBufferPosition()
  if /[^ \t\r\n\f]{1,}[ \t\r\n\f]/.test editor.getTextInBufferRange range
    selectSubwordToRight editor

atom.commands.add 'atom-workspace atom-text-editor',
  'editor:select-subword-to-right', ->
    return unless editor = atom.workspace.getActiveTextEditor()
    selectSubwordToRight editor

atom.commands.add 'atom-workspace atom-text-editor',
  'editor:select-subword-to-left', ->
    return unless editor = atom.workspace.getActiveTextEditor()
    selectSubwordToLeft editor

user settings (keymap.cson)

'atom-workspace atom-text-editor:not([mini])':
  'ctrl-k ctrl-c': 'editor:toggle-line-comments'
  'ctrl-shift-right': 'editor:select-subword-to-right'
  'ctrl-shift-left': 'editor:select-subword-to-left'