1

Using Neovim 0.6.1.

I use a lot of snake_case_variable_names and have a frequent need to navigate within their individual components instead of treating these names as a single word.

Right now, the only trick I've found is to put this line in my config: set iskeyword-=_

However this poses several problems:

  1. When using the native completion engine, the individual components are registered in a list of available words. This tends to bloat completion lists with useless symbols (some_integer, some, integer).

    • For instance, if I declare some_integer in python, the jedi completion engine will recognise some_integer as a symbol available for completion. Which is good.
    • The native nvim completion engine, on the other hand, will recognise some and word as symbols available for completion. Which is bad.
  2. The ability to navigate around full_names with w,e,b motions is either removed or severely impaired.

    • I can sometimes use W,E,B to select an entire_name, but it doesn't behave as w,e,b used to behave before using set iskeyword-=_. It usually overshoots and selects special characters such as parentheses, punctuation, brackets, etc.
  3. * and # do not select the whole_name, but whatever word is delimited by underscores.

Does anyone know how I could get around either (hopefully both) of these problems?

Ideally, I'd like a setup that would function as follows:

  • w,e,b to navigate within snake_case_names
  • W,E,B behaving exactly as the default w,e,b

1 Answer 1

1

Right before submitting this question I dove into a rabbit hole and emerged with a solution mentioned in this post: https://vi.stackexchange.com/a/677/31358

The provided answer was to install this plugin: https://github.com/bkad/CamelCaseMotion

And with the following config, it seems that my wishes have been granted:

map <silent> b <Plug>CamelCaseMotion_b
map <silent> e <Plug>CamelCaseMotion_e
sunmap w
sunmap b
sunmap e
3
  • 1
    You forgot to remove set iskeyword-=_ from your configuration file. This causes more problems than it solves. Keep the original iskeyword and use the CamelCaseMotion plugin.
    – r_31415
    Jun 2, 2022 at 18:48
  • Hey, good point. I just checked and I no longer have that bug and have removed the iskeyword line so maybe that completion curfufle was caused by neovim not being properly reset. Amending post.
    – jwav
    Jun 2, 2022 at 19:42
  • Excellent. I'm glad both issues are fixed :)
    – r_31415
    Jun 2, 2022 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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