perpetuum
perpetuum

Reputation: 129

Where is '$' under the "normal mode" (after esc-pressing mode) in "Vim" text editor?

I have hard time realizing, as a beginner, why in "Vim" (Windows 10), when I want to delete a word with a d$ and when I simultaneously press shift+4 on non-numeric key above qwerty... why "Vim" does not recognize that as a $?

Upvotes: 1

Views: 122

Answers (2)

perpetuum
perpetuum

Reputation: 129

I've finnaly understand it... a cursor must be BEFORE a related "tail" to be eliminated.

PS: In fact problem was with "e212 error: can't write to file"... instead of changing proposed "sudo permissions", while I'm on Win 10 instead, I've just reinstalled a fresh Vim.

So, problem were not with "$" (as it was where always have been) but when one is unsure where problem lies, often makes a wrong diagnosis.

Upvotes: 0

grochmal
grochmal

Reputation: 3027

I strongly believe that you confusion stems from the fact that d$ is not actually meant to delete a word. Moreover, dw (which sound pretty much like "delete word") is not meant to delete a word either.

d is a command that will perform its action (deletion) on the next movement right after the command. Note that $ moves to the end of the line, and w moves to the beginning of the next word. Therefore:

  • d$ deletes from the cursor position until the end of the line.
  • dw deletes from the cursor position until the beginning of the next word.

For a better example you should try d3j. 3j moves three lines below, therefore d3j deletes the current lines and the next three lines as well.


To delete the word under the cursor (no matter where the cursor is in the word) there are several ways. Some ways to do it:

  • bdw first move to the beginning of the word then delete 'till the next word.
  • vawd visually select the word a word (including the space after the word) and delete it.
  • viwd visually select an inner word and delete it (this leaves the spaces around the word in peace).
  • daw delete a word (without going into visual).
  • diw delete inner word (without visual).

(Try the visual ones first to see how they work, then you can use the non-visual ones.)


Also, we have a vi.SE section of the website.

Upvotes: 2

Related Questions