outis
outis

Reputation: 831

What is the vim equivalent of emacs' ctrl-k?

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.

Upvotes: 6

Views: 1666

Answers (4)

HellaMad
HellaMad

Reputation: 5374

If you also want bind <C-k> to kill-line in command-line mode, you can use the getcmdline() and getcmdpos() functions:

cnoremap <C-k> <C-\>e(" ".getcmdline())[:getcmdpos()-1][1:]<CR>

Upvotes: 0

johnsyweb
johnsyweb

Reputation: 141780

There is no built-in equivalent (to the best of my knowledge).

The simplest way from insert mode is to use Ctrl-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.

Upvotes: 0

Alain M. Lafon
Alain M. Lafon

Reputation: 1720

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 .

Upvotes: 0

Xophmeister
Xophmeister

Reputation: 9211

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+oD

Upvotes: 7

Related Questions