How can I delete from the current cursor position to the end of line in vim's insert mode?
I know you can do this with D
in command mode, and I know you can delete from the cursor position to the beginning of the line in insert mode with ctrl-u, so I'm guessing this should be possible.
If you're in insert mode and you want to execute a single normal mode command, you can press:
Ctrl+o
After the normal mode command has executed, you'll be returned to insert mode. So, you can use D that way:
Ctrl+o D
There is no built in method for this in VIM, but you can use this map to use Ctrl+k in VIM as you would in Emacs:
inoremap <C-k> <Del>
However, if you want to you the built in digraph functionality of VIM for writing special characters, you should use a different keybinding like .
There is no built-in equivalent (to the best of my knowledge).
The simplest way from insert mode is to useCtrl - O D .
If you'd like to map this to something a little easier to remember, you may wish to create an insert-mode mapping , which will allow you to use the normal-mode D command to delete the characters under the cursor until the end of the line:
:inoremap <Leader>k <C-O>D
Assuming <Leader>
is the default \\
, you would type \\ k in insert mode invoke the mapping.
Insert-mode mappings are not without their drawbacks, as Kent points out in the comments but do have their uses.
Ctrl - K is used for entering digraphs in Vim. I'd suggest that you don't try to re-map this, although it is possible using the technique above.
如果您还希望在命令行模式下将<Ck>
绑定到 kill-line,您可以使用getcmdline()
和getcmdpos()
函数:
cnoremap <C-k> <C-\>e(" ".getcmdline())[:getcmdpos()-1][1:]<CR>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.