Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A short command to clear the current line?

Tags:

vim

Sometimes I want to clear a line in vim rather than delete it.

Before:

foo
bar
lineToClear
baz

After

foo
bar

baz

Of the vim commands I know, the closest I can get to this is D (upper case d), but usually this requires me to type 0 first to go to the beginning of the line.

I know, I'm lazy.

Does there exist a command that just clears the entire line, not just the characters after the cursor?

Maybe some sort of Containment-esque type of direct brain interface?

like image 304
Cory Klein Avatar asked Jul 26 '13 16:07

Cory Klein


People also ask

How do you clear a command line?

Clear Command Prompt with CLS Command Enter multiple standard commands into the blank cmd screen. Next type CLS and press Enter button. This will clear all the previously entered commands from the CMD screen in Windows.

How do I clear the command line in terminal?

A common way to do that is to use the `clear` command, or its keyboard shortcut CTRL+L.

How do I clear the command line in Linux?

Clear Terminal via Ctrl+L / Ctrl+Shift+K Shortcut Keyboard shortcuts also work for clearing the terminal, depending on the terminal emulator. An alternative in some terminal emulators is Ctrl + Shift + K .


1 Answers

You can use S. It clears the line, then puts you into insert mode. If you don't want to do insert mode, 0D will be the quickest command set.

As glts mentioned, you can create a custom mapping by running one of the following commands. The first argument (S/D) can be changed to whatever you'd like.

:nnoremap S S<Esc>

or

:nnoremap D 0D

Reference

like image 83
Chris Forrence Avatar answered Oct 17 '22 20:10

Chris Forrence