I like to use shell style shortcuts in insert and command-line mode, such as CTRL-K to delete to end of line. This mapping works in insert mode:

inoremap <C-K> <C-O>D

But I can't figure out an equivalent for command-line mode. Any ideas?

I'm using Vrapper in case it matters.

  • 4
    SHIFT + D or what did you mean?
    – FaxMax
    Dec 5, 2017 at 16:46
  • Right, but that only works in normal mode. In command-line mode it inserts a D character. Dec 5, 2017 at 16:47
  • 5
    "shell style shortcuts". Do you mean emacs-mode line editing, as in bash's set -o emacs? If so, why not just use emacs instead of vi(m) and be done with it? Dec 5, 2017 at 16:52
  • The thing is CTRL-K is not just used in emacs and bash. On Mac OS it deletes to EOL in almost every app. Sep 11, 2022 at 16:23

2 Answers 2


alternative approach

The :help command-line-window is one of the lesser-known features of Vim. You can enter it with <C-f> by default when you're already on the commandline, or q: from normal mode. As in any other Vim buffer, you can edit the current or previous command-lines using Vim commands, and press <Enter> to execute and close it. In it, you can use D just like anywhere else.


If you want that functionality directly in the command-line itself, you can define this simple mapping:

cnoremap <C-k> <C-\>e(strpart(getcmdline(), 0, getcmdpos() - 1))<CR>

Note that your suggested left-hand side clobbers the useful digraphs entry.


My CmdlineSpecialEdits plugin has (among many others) a CTRL-G D mapping that removes all characters between the cursor position and the end of the line.


You can use


To delete from the cursor to the end of file.

Hope this is helpful!

  • Nope. I want to delete what's on the command line, in command-line mode. Dec 18, 2017 at 14:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .