2

Is there a way to select words respecting the case... camelCase, snakeCase...

e.g.: i have a word "trullyAwesomeFunction" and cursor is on "w", is there an Emacs function I could use that would select "Awesome" and then if used again select "trully" and then "Function". and deselect them similarly?

Let's say this function bound to <C-up> I'm gonna have to press <C-up> 3 times to select the entire word. And if it's snake case like: "trully_awesome_function" it would work the similar way.

5

Take a look at subword-mode (see manual), a built-in minor mode that makes standard movement and editing commands treat capital letters in camelCaseWords as word boundaries.

For example, you could enable subword-mode and then use the standard mark-word command (M-@) to mark the fragments of "trulyAwesomeFunction" one at a time.

With snake_case, the underscore is already treated as a word boundary by default. In fact there is another minor mode -- superword-mode -- that can be enabled if you want the standard word commands to not treat _ as a boundary.

  • This is truly awesome. – Meaningful Username Jul 22 '15 at 18:25
  • Worth noting that subword-mode + mark-word won't behave exactly as described. With point on the w in trulyAwesomeFunction you can mark subwords forward or backward but I don't know a command that would mark Awesome, then extend the region backward, then extend it forward. To do that you could use a sequence like: M-@ M-b C-x C-x M-f. That is: mark the word at point; extend the region back one word; jump to the other end of the region; extend the region forward one word. – glucas Jul 23 '15 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.