When writing code in python-mode
my preference would be to include underscores within a word boundary, so variable_with_underscores
is treated as a single word.
How would I limit my word preference only to python-mode
?
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityAdd a hook to modify the python-mode-syntax-table
:
;; Keep underscores within a word boundary
(add-hook 'python-mode-hook
(lambda () (modify-syntax-entry ?_ "w" python-mode-syntax-table)))
It's bird, it's a plane, it's superword-mode
:
Superword mode is a buffer-local minor mode. Enabling it changes the definition of words such that symbols characters are treated as parts of words: e.g., in ‘superword-mode’, "this_is_a_symbol" counts as one word.
It's a minor mode, so you can set it in a hook the normal way: (add-hook 'python-mode-hook #'superword-mode)
. superword-mode
has only existed since 24.4, so you'll need to hack the syntax table by hand in older versions.
I find it very convenient to bind this to a key so I can easily toggle it. It's the sort thing I want sometimes, but not others.
C-u M-x replace-string
this won't work. The accepted answer however, does the trick.
Aug 16, 2018 at 12:02
mark-sexp
instead ofmark-word
?