Reputation: 1789
I want to delete the part after the cursor position in a line in vim
. For example, a line looks like that:
abcdefghijklmn
And the position of a cursor is in character c
, I want to delete characters starting with d
. In other words, I want to delete defghijklmn
and leave abc
. How can I use vim
command gracefully?
PS: Currently I just keep pressing the Backspace
key.
UPDATE:
How to delete from cursor position to the begining
of the current line?
Upvotes: 0
Views: 274
Reputation: 1522
d$
will delete from your cursor (including the character under it!) to the end of the current line and also
d^
will delete from your cursor (keeping the letter under the cursor) to the start of the current line.
In your case ab[X]defghijklmn
, where [X] is the cursor, move the cursor right by one and type d$
.
Upvotes: 1
Reputation: 172520
If you're new to Vim (and its navigation and editing commands), you should spend 30 minutes on the vimtutor
that comes with it. Then, there are several good resources, cheatsheets, and vi / Vim tutorials out there on the net. http://vimcasts.org/ has several short entertaining episodes that go beyond the basics.
Learn how to look up commands and navigate the built-in :help
; it is comprehensive and offers many tips. You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor.
Upvotes: 2
Reputation: 66
l (letter ell) moves one character to the right
D deletes until the end of the line
de deletes until the end of the word
so it depends exactly what you want if it is a complete line the lD otherwise lde
Upvotes: 5
Reputation: 44360
dt[char]
- Delete from cursor position to [char]
.
cw
- Change word (delete word and enter insert mode).
dw
- Delete a word.
d3w
- Delete 3 next word.
x
- Delete the character under the cursor.
D
- Delete from cursor position to the end of the current line.
From this source
Upvotes: 1