How to Cut from Cursor to End of Line in Vim
Learn the Vim commands to cut or copy from you cursor to the end of the line.
Vim provides many different ways to copy, cut, and paste text. Moving code around your file quickly and efficiently can be a massive productivity boost. When using a mouse, we are accustomed to getting the exact text selection we want, but in Vim, things can be a little more complicated. Here is how to cut from the cursor to the end of the line in Vim.
How to Cut from Cursor to End of Line in Vim
To cut from the cursor to the End of the Line in Vim, use the D (uppercase) key while in Normal mode. You can follow up with a p (lowercase) to paste your selection.
Pressing uppercase D while in Normal mode will move your cursor to the end of the line from its current position and perform a cut, saving the selection to your clipboard. You can then move to the desired location and hit p to paste after the cursor. Alternatively, you can hit uppercase P to paste before the cursor.
- D (uppercase) – Cut from cursor to end of line
- p (lowercase) – Paste after the cursor
- P (uppercase) – Paste before the cursor
Another method to achieve a similar result is to use the keys v$d. Hitting v (lowercase) will put you into Visual mode, hitting $ (dollar sign) will move the cursor to the end of the line, and finally, hitting d (lowercase) will perform a cut operation.
How to Copy from Cursor to End of Line in Vim
To copy from the cursor to the end of the line in Vim, use the y (lowercase) key combined with the $ (dollar sign) key while in Normal mode. With y$ you will perform a “yank” operation from the cursor to the end of the line and only copy the text. You can then move to the desired location and paste as you did before with p or P.
Here are a few more “yank” (copy) operations you can perform with the y key:
- Y (uppercase) or yy – Copy the entire line
- y$ – Copy from the cursor to the end of the line
- yaw – Copy the current word, including trailing whitespace
- yiw – Copy the current word, excluding trailing whitespace
- ytx – Copy from the cursor to the character before x
- yfx – Copy from the cursor to the character including x
We hope you found this guide helpful. Check out our Vim section for more useful Vim tips, tricks, and cheat sheets.