To clear a file I find myself doing something like:
- 1G
- 1000cc (or some large number)
Is there a simpler way to do this for clearing a file? On a normal text editor I normally would do Cmd-A
and then start typing.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityggdG
gg
: Move to the first line in the file
d
: Delete
G
: [until] last line in file
From help:
G Goto line [count], default last line, on the first
non-blank character linewise. If 'startofline' not
set, keep the same column.
G is one of the jump-motions.
...
gg Goto line [count], default first line, on the first
non-blank character |linewise|. If 'startofline' not
set, keep the same column.
Substitute d
with c
if you want to be in insert mode instantly.
p
or P
it will put the previously yanked text... Well, for that, use gg"_dG
, which deletes it into the black hole register.
Fastest is
:%delete
Which can be abbreviated to
:%d
The %
is a range standing for “whole file.”
If you want to use a particular register (e.g., black hole):
:%d_
:%d