问题
In vim, in normal mode, if the cursor is in a word, not the last letter, de
deletes the suffix of the word, from the position of the cursor. If the cursor is on the last letter, x
does it too, while de
would jump to the end of the next word.
What command would you use that would work in both cases, last letter or not?
The purpose is to include the command in a macro.
回答1:
Try vwged
instead of de
, and define a mapping like the following, if you
like it.
:nnoremap <leader>de vwged
It seems to do exactly what you want.
回答2:
You could also try d/\>
which translates to delete upto next end word boundary.
回答3:
If your word separator is space, dt<space>
will work. t
will match all characters until the specified character.
回答4:
:s/\w\+//
This will substitute at the beginning of the line.
To make it substitute at the position of the cursor you have to add some lines to your vimrc. Follow the instructions here
http://vim.wikia.com/wiki/Repeating_a_substitute_from_current_cursor_position
来源:https://stackoverflow.com/questions/6086848/in-vim-how-to-delete-the-suffix-of-a-word