bph
bph

Reputation: 11268

Tranpose words either side of underscore in emacs

Is there some means of transposing words separated by a _ (underscore) in Emacs?

M-t doesn't do it, I think it's looking for a whitespace separator.

This would be handy when dealing with C-style variable/function names, e.g. my_var, my_other_var, a_really_complex_function.

Another annoyance is C-M-t opening a new terminal in Ubuntu rather than performing M-x transpose_sexps.

Upvotes: 1

Views: 149

Answers (1)

Chris
Chris

Reputation: 137096

Enable subword-mode or global-subword-mode. That should give you the behaviour you're looking for.

This can be done interactively using M-x or it can be added to your Emacs configuration.

For example:

;; Enable for C-mode
(add-hook 'c-mode-hook (lambda ()
  (subword-mode 1))

;; Enable by default
(global-subword-mode 1)

Upvotes: 4

Related Questions