2

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.

3
  • 4
    SHIFT + D or what did you mean?
    – FaxMax
    Dec 5 '17 at 16:46
  • Right, but that only works in normal mode. In command-line mode it inserts a D character. Dec 5 '17 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?
    – roaima
    Dec 5 '17 at 16:52
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.

mapping

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.

plugin

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.

0

You can use

:,.d$

To delete from the cursor to the end of file.

Hope this is helpful!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.