Move to the end of line character in Vi, past the last character in the line
How come in Vi, when I hit $
, it goes to the last character in the line instead 开发者_运维百科of the end of the line character? How would I go to the end of the line character in one keystroke, and what is the fastest way to delete the end of the line character?
How come in Vi, when I hit
$
, it goes to the last character in the line instead of the end of the line character?
Because that’s sufficient for anything you might want to achieve.
How would I go to the end of the line character in one keystroke
You basically never need to. You just do different things in the next step depending on what you wanted to achieve by going to the newline character. Eg.:
what is the fastest way to delete the end of the line character?
Just hit J
to join the lines. (If you have autoindent
or friends enabled, that will even take care of removing indentation from the joined line for you.) Follow up with an x
if you didn’t want the extra space character you just got; or use gJ
to begin with, instead.
You could use the sequence 'A
Del
ESC
' to delete the newline character from a line.
A: Append after line
more information can be found here: http://www.lagmonster.org/docs/vi.html
It is just annoying that when you learn vi/vim, most people out there tell you to type "i"
to start insert mode, but almost all skip telling what is basic "editing" because of how other editors do it. (and many are not aware of this until too late, and maybe ashamed to admit in public, I am not)
in command mode, you go ahead and find a location/character where your cursor blinks, and you are given 3 editing choices:
"i"
- edit before that character (insert, continue editing until you hit ESC)"r"
- edit at that character (replace, one-time action, returns to command mode immediately )"a"
- edit after that character (append, continue editing until you hit ESC)
so, using "l"
, "$"
or "END"
keys takes you only to the last character. there, you decide the fate of editing, and it is "a"
to continue editing in the case we got here. the remaining part is to press ESC after editing is done.
EDIT: adding to i,r,a
, it is also possible to use their capitalized versions, by SHIFT
or CAPS LOCK
.
I
- jump to the beginning of the line and start inserting until ESCR
- start continuously replacing until ESCA
- jump to the end of the line after the last character and start appending until ESC
here in the situation of this question, A
would be much preferable.
精彩评论