Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in vim command line mode: how to kill the line from the current cursor position to the end

Tags:

bash

vim

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?

like image 238
kevin Avatar asked Oct 11 '14 02:10

kevin


People also ask

How do I move the cursor to the end of the line in Linux?

Ctrl+E or End – moves the cursor to the end of the line. Ctrl+B or Left Arrow – moves the cursor back one character at a time.

How do I go to the bottom of a file in Vim?

Move cursor to end of file in vim In short press the Esc key and then press Shift + G to move cursor to end of file in vi or vim text editor under Linux and Unix-like systems.

Which Vim command will enter insert mode and move the cursor to the end of the line?

Use CTRL + o while in insert mode to temporarily enter normal mode for the next command, and then $ to go to the end of the line (after which you will be returned to insert mode) Use ESC to return to normal mode, and then A which both moves the cursor to the end of the line and enters insert mode.


1 Answers

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.

like image 70
Yosh Avatar answered Oct 03 '22 03:10

Yosh