Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difference between Emacs and Vim on handling _ as word boundary #9740

Closed
Qqwy opened this issue Oct 15, 2017 · 7 comments
Closed

Difference between Emacs and Vim on handling _ as word boundary #9740

Qqwy opened this issue Oct 15, 2017 · 7 comments

Comments

@Qqwy
Copy link

Qqwy commented Oct 15, 2017

In Vim, _ is considered a word character. Soo foo_bar_baz is one word.

In Emacs, _ is considered a separate word alltogether. So foo_bar_baz is five words.

Now, the Unicode standard agrees with what Vim does, and this is also the behaviour I am used to from many different contexts (browsers, command-line interfaces, ritch text editors etc): In many applications, using Ctrl+arrow keys lets you skip back and forth to the beginnings/ends of words quickly.

Because in the end, evil-mode is not entirely like vim, it adheres to emacs' rules of word boundary choice, which means that using the w and b commands in evil-mode will give different results than when using them in command-line vim.

Now I'm not sure what the proper approach might be here; There are ways to override how _ works in most modes (see this stackoverflow answer), but this might not be a silver bullet solution:

  • What to do in hybrid mode?
  • What if a user is used to the emacs-style underscores ?

Maybe the best thing we could do is to add a configuration option in the .spacemacs for this?

@Somelauw
Copy link

What Vim calls a word, Emacs calls a symbol.
Maybe w (and others) could have been bound to evil-next-symbol instead of evil-next-word.

However, I like the Emacs definition of a word better now.

@olymk2
Copy link

olymk2 commented Oct 16, 2017

I have this in my config to change the behaviour.

(with-eval-after-load 'evil
(defalias #'forward-evil-word #'forward-evil-symbol))

@sdwolfz
Copy link
Collaborator

sdwolfz commented Oct 16, 2017

I had this setup as well @olymk2 but it felt weird, so I got used to navigating by W, f 《char》 and /《search words》 which proved to be better overall.

Not saying it's a solution fit for everyone but navigating only with w, e and b felt slow for me after a while, and now incorporating all these movements, I no longer mind it being different than vim. Actually I find the current behaviour better, especially when navigating emacs lisp code.

@Alexander-Miller
Copy link
Contributor

In Emacs, _ is considered a separate word alltogether. So foo_bar_baz is five

Thats not the full truth. Whether a character is treated is part of a word or symbol is determined by a major mode's syntax table.

At any rate I dont think adding something like this to spacemacs is a good idea. Changing syntax definitions opens up a gaping abyss of subtle, difficult to track & debug bugs since everything that uses syntax tables - from autocompletion to syntax highlighting - would be affected by such a change.

@CeleritasCelery
Copy link
Contributor

As @Alexander-Miller said, it would be unwise for Spacemacs to change this. However nothing is stopping your from updating the syntax table for your desired mode(s) so that _ is not considered a word boundary. Also note Spacemacs has the text-object o which grabs the entire symbol, underscore included.

@rudolfkral
Copy link

Does that mean that the issue is decided and closed, as it is advised to update the syntax table instead of changing anything in Spacemacs?

@duianto
Copy link
Collaborator

duianto commented Feb 25, 2020

@rudolfkral I don't have final say for if it is decided, but as alexander said, it would effect other things, so we'll close this.

@duianto duianto closed this as completed Feb 25, 2020
ilyagr added a commit to ilyagr/spacemacs that referenced this issue Mar 6, 2021
This expands the entry on including underscores and dashes in word motions to discuss `*` and `#` searches. There is a new solution for them is different, and simpler, than the solution for the other motions (but it is difficult to find).

For me, personally, this obviates the necessity of messing with the syntax definitions.

Some related issues: syl20bnr#9740, 
syl20bnr#1248, 
syl20bnr#1261.

Many thanks to lyro@ for fixing emacs-evil/evil#360.
smile13241324 pushed a commit that referenced this issue Mar 13, 2021
This expands the entry on including underscores and dashes in word motions to discuss `*` and `#` searches. There is a new solution for them is different, and simpler, than the solution for the other motions (but it is difficult to find).

For me, personally, this obviates the necessity of messing with the syntax definitions.

Some related issues: #9740, 
#1248, 
#1261.

Many thanks to lyro@ for fixing emacs-evil/evil#360.
aam-at pushed a commit to aam-at/spacemacs that referenced this issue Mar 23, 2021
This expands the entry on including underscores and dashes in word motions to discuss `*` and `#` searches. There is a new solution for them is different, and simpler, than the solution for the other motions (but it is difficult to find).

For me, personally, this obviates the necessity of messing with the syntax definitions.

Some related issues: syl20bnr#9740, 
syl20bnr#1248, 
syl20bnr#1261.

Many thanks to lyro@ for fixing emacs-evil/evil#360.
wang-d pushed a commit to wang-d/spacemacs that referenced this issue Jul 22, 2021
This expands the entry on including underscores and dashes in word motions to discuss `*` and `#` searches. There is a new solution for them is different, and simpler, than the solution for the other motions (but it is difficult to find).

For me, personally, this obviates the necessity of messing with the syntax definitions.

Some related issues: syl20bnr#9740, 
syl20bnr#1248, 
syl20bnr#1261.

Many thanks to lyro@ for fixing emacs-evil/evil#360.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants