Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Vim to treat underscores in a string as a word break?

Tags:

vim

I would like Vim to treat underscores in a string as word-breaks, just like a spaces. For example, if I have:

sub foo_bar {
    return;
}

With the cursor starting at the far left of the first line, (on the 's' of 'sub'), hitting 'w' will place the cursor on the 'f' in 'foo', a second press of 'w' takes me to the curly, and a third hops down to the 'r' of 'return'. I want that second press of 'w' to take me to the 'b' in 'bar'.

like image 773
Drew Stephens Avatar asked Aug 19 '09 05:08

Drew Stephens


2 Answers

:set iskeyword-=_

like image 164
Peter Avatar answered Oct 23 '22 09:10

Peter


Install the camelcasemotion plugin and see the example near the bottom of the linked page, which shows how to map the w key to use CamelCase or underscored_words.

like image 28
DrAl Avatar answered Oct 23 '22 10:10

DrAl