Skip to content

Instantly share code, notes, and snippets.

@hectorperez
Created August 7, 2014 13:37
Show Gist options
  • Star 28 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save hectorperez/1f6cbe9a55bfb34e577a to your computer and use it in GitHub Desktop.
Save hectorperez/1f6cbe9a55bfb34e577a to your computer and use it in GitHub Desktop.
copy word under cursor in Vim
copy/delete word under cursor in Vim
yw / byw
Assuming that the cursor is at the first character of the word simply do this in command mode:
yw
y is for yank and w is for word.
Other ways of doing the same thing which are not as efficient:
vey
the v starts visual select mode. e tells vim to move to end of word. y yanks or copies the word. to delete replace y with x.
if the cursor is somewhere in the middle of the word, add a b before the command as in:
byw
or
bvey
# http://www.littletechtips.com/2011/05/how-to-copydelete-word-under-cursor-in.html
@tyler-dane
Copy link

Thank you. You can also yaw to yank the entire word regardless of where the cursor is located.

@pancutan
Copy link

Thanks guys! You rock!

@risteFront
Copy link

Thanks , this is helpful.

@natanshalva
Copy link

Thanks, there is a small mistake on the first row, these combination will only copy, not delete.

@mochsner
Copy link

mochsner commented Sep 3, 2021

Any shortcut to SELECT an entire word that you guys are aware of?

This is great, but I would love to use in conjunction with the ability to highlight another word to replace it with, I think.

EDIT: this would be vaw - duh. Only issue is doing yaw and then vaw seems to add a space. No solution from me on this yet. If anyone else has one feel free to share!

@Dotrar
Copy link

Dotrar commented Sep 22, 2021

@mochsner
viw and yiw will select and copy entire word without the leading space.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment