5
votes

the <c-k>: kill-line feature of bash, which means kill the line from the current cursor position to the end of the line. how to do this in vim command-line mode when editing the command?

for example:
when typing :echo 'hell|o world' this command in vim command line mode and the cursor is in | position, how to kill the line to become :echo 'hell?

2

2 Answers

2
votes

I found this key binding in Shougo's vimrc that sets up Ctrl+k to delete until the end of the line:

" <C-k>, K: delete to end.
cnoremap <C-k> <C-\>e getcmdpos() == 1 ?
      \ '' : getcmdline()[:getcmdpos()-2]<CR>

Note that this doesn't preserve the rest of the line in a register, the way the equivalent binding in bash or Emacs does.

Check :h eval for more help on what you can do on the command line.

0
votes

Editing the command-line is not supposed to happen in the command-line itself but in an editor.

That's why you have <C-x>e in bash and <C-f> in Vim.