In normal mode, I want to set a mark (ma
) and then yank until the end of the line, including the last character ($
and y`a
). But $
doesn't include the last character. What is the solution?
1 Answer
But
$
doesn't include the last character.
$
does include the last character, it is `a
that doesn't. :help mark-motions
says that `a
is exclusive, which is why the last character of the line is not yanked. See :help exclusive
.
What is the solution?
Here are a few suggestions…
You could use visual mode, which is inclusive by default:
v`ay
You could make use of the mechanism provided by Vim for momentarily forcing exclusivity or inclusivty, described under
:help forced-motion
:yv`a
Instead of placing the mark, then moving to the end of the line, then yanking from there to the mark, you could simply yank to the end of line without all those superfluous intermediary steps:
y$
i<cr>
) then yank it all (yy
), which includes the carriage return, then undo the line split. So:i<cr><esc>yyu