Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ignore trailing spaces when yanking a word in neovim

So my issue when yanking a word (yw) is that it copies the trailing spaces as well:

Example:
Doing a yw on this:

‖Hello World

Results in copying Hello

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

But the same applies to:

‖LongVariableName                        = 'SomeValue';

Results in copying LongVariableName

Is there a way to make as such I copy without copying any space? (which for me makes sense when copying words)

>Solution :

You can use yiw to yank the ‘inner word’ text object (yaw would include an additional space). See :help text-objects.

A nice feature of text objects is that the cursor can be anywhere on the object (in this case the word) for it to work.

There are many text objects in vim:

  • is means inner sentence
  • ip means inner paragraph
  • i) means inner parentheses

And many more!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading