5

Most programming languages use CamelCase ("anIdentifier") naming conventions for identifiers. With Evil, you could navigate inside those identifiers using Evil built-in motions is the [count]f{char} motion, i.e. f{uppercase-char} or f_, respectively. But I would like to have this easier. I noticed there are many plugins available for Vim, which enables you to move camelCase-wise.

These packages defines motions ,w ,b and ,e (similar to w b e), which do not move word-wise (forward/backward), but Camel-wise; i.e. to word boundaries and uppercase letters. Outside of "words" (e.g. in non-keyword characters like // or ;), the new motions move just like the regular motions.

For example, with the CamelCase plugin the cursor ([]) is on the following sentence:

[]AnotherExampleOfFoobar

When I type dw, it will change to the following:

[]ExampleOfFoobar.

When I googled around for an alternative package for Evil, I found no alternative package for CamelCase motion. It deletes the whole AnotherExampleOfFoobar, instead deleting Another.

So I guess there is a missing feature, that I need to implement it in some way. So have anyone any suggestion to start with it?

4
  • 10
    You're probably looking for subword-mode.
    – Dan
    Aug 3, 2015 at 21:37
  • 1
  • @wasamasa Thanks wasama, after trying out evil-little-word package, it seems it adds new commands next to the existing Evil commands. It adds a layer of complexitiy to Evil, which I don't want. The CamelCase plugin in Vim works with the default Vim commands. It stops on subwords, I would prefer that, instead adding new commands from evil-little-word next to the default Evil commands. Any suggestion?
    – ReneFroger
    Aug 10, 2015 at 13:26
  • Perhaps this can work, but we just remap things like w to evil-forward-little-word-end and iw to evil-inner-little-word? I'm not sure about how to rebind evil keybindings, but it seems like a promising approach...
    – modulitos
    Feb 7, 2016 at 11:24

1 Answer 1

3

Using the evil-little-word library as suggested by @wasamasa above, you can rebind your standard vim bindings to the evil-little-word versions.

For example, once you load that library in your path, put this in your init file:

(require 'evil-little-word)
(define-key evil-normal-state-map (kbd "w") 'evil-forward-little-word-begin)
(define-key evil-normal-state-map (kbd "b") 'evil-backward-little-word-begin)
(define-key evil-operator-state-map (kbd "w") 'evil-forward-little-word-begin)
(define-key evil-operator-state-map (kbd "b") 'evil-backward-little-word-begin)
(define-key evil-visual-state-map (kbd "w") 'evil-forward-little-word-begin)
(define-key evil-visual-state-map (kbd "b") 'evil-backward-little-word-begin)
(define-key evil-visual-state-map (kbd "i w") 'evil-inner-little-word)

I think that covers the bindings, but let me know if I am missing something!

To figure this out, I asked another question here about the details of re-binding evil-mode keys.

3
  • Whoa, that worked surprisingly well. Sorry for the belated response. But I couldn't get it working earlier. Later I thought I could give a try again, and it works now! Thanks for that, it's appreciated!
    – ReneFroger
    Feb 13, 2016 at 23:19
  • 2
    Haha, your welcome! As with most things in life (and emacs), it was a concerted effort. Thanks wasamasa for finding the library, and @Dan for helping with the configuration. Enjoy :D
    – modulitos
    Feb 14, 2016 at 8:19
  • This was very helpful, thanks. It's nice to know that this still lets you replace the whole word with cio!
    – sk29910
    May 13, 2018 at 20:26

Your Answer

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

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