3

I'm trying to figure out how to delete a whole line in command mode. I see lots of example .vimrc's with:

cnoremap <C-a>  <Home>
cnoremap <C-b>  <Left>
cnoremap <C-f>  <Right>
cnoremap <C-d>  <Delete>
cnoremap <M-b>  <S-Left>
cnoremap <M-f>  <S-Right>
" This doesn't delete a word as I'd expect
cnoremap <M-d>  <S-Right><Delete>

All of these work as expected with exception of <M-d>. I'd expect that do delete a whole word, but it just jumps to the end and deletes a single character. Is there a <Delete Word> or <Delete Line>?

1
  • The title of the question doesn't reflect its content. Do you want to delete the whole line or a whole word?
    – romainl
    Nov 7, 2013 at 6:43

1 Answer 1

5

In the command-line (like in insert mode), the command for deleting a whole word backward is <C-w> and the one for deleting the whole line until the cursor is <C-u>. They are not that hard to type so I don't think you should remap them at all. Anyway…

"delete word, backward
cnoremap <M-d> <C-w>

"delete word, forward
cnoremap <M-d> <S-Right><C-w>

But, if you do a lot of editing on the command-line, you should look into the command-line window: press <C-f> to edit the current command or q: to open the command-line window directly.

:help cmdline-widow
:help cmdline-editing
4
  • Thanks! The reason for remap is I use those motions everywhere. It's very hard to overcome muscle memory for one instance. I use q: for bigger changes but opening it for one word change seems silly. Nov 7, 2013 at 16:09
  • Also where is the list of all the abbreviations for those in vimscript? Nov 7, 2013 at 16:14
  • See :viusage.
    – romainl
    Nov 7, 2013 at 16:20
  • if the command line is abc/def, the cursor is on a, with <S-Right><C-w>, the command line becomes abc/, but I am expecting /def, seems the two commands have a different definition of "word".
    – georgexsh
    Sep 11, 2019 at 10:14

You must log in to answer this question.

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