In Vim, how to delete the suffix of a word?

 ̄綄美尐妖づ 提交于 2020-01-03 09:08:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!