Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting entire word that includes dashes

Tags:

vim

Let's say I have the string

hello how-ar[]e-you doing

where [] is my cursor. How would I efficiently select how-are-you such that

hello [how-are-you] doing

So far what I could come up with is Bvt<space>

like image 725
axsuul Avatar asked Feb 28 '18 01:02

axsuul


2 Answers

Vim has the notion of "word" and "WORD", where a "word" is a sequence of characters in the 'iskeyword' option and a "WORD" is a sequence of non-whitespace characters.

Thus…

  • the w motion ("word") would jump to the - after are because - is not part of 'iskeyword',
  • the W motion ("WORD") would jump to doing,
  • the iw text-object ("inner word") would cover are,
  • the iW text-object ("inner WORD") would cover how-are-you,
  • and so on for other motions and text-objects.

What you are looking for is the iW text-object:

viW

:help navigation will blow your mind.

like image 86
romainl Avatar answered Oct 23 '22 03:10

romainl


besides the other answers (using Word instead of word) if you want this to be the default behaviour (such that - will be considered a word character - not a word delimiter) you may add this to your vimrc

set iskeyword+="-"

after that viw will give you the expected result. type :h iskeyword for more info about it

like image 28
sudavid4 Avatar answered Oct 23 '22 02:10

sudavid4