1

I wanted a quick way to delete all the lines in a buffer, so I added this to my .vimrc

if !exists(“:Dall”)
    command Dall ggdG
endif

However, when I try to run it, I get an error that “ggdG” is not an editor command.

What is the mistake I am making?

2
  • 1
    If you have that literally as shown, with curly quotes, I think your exists test will not be valid. You should use regular ASCII double-quote ("). Commented Oct 5, 2015 at 14:23
  • @DanLowe Safari smart quoting. Commented Nov 1, 2015 at 3:53

1 Answer 1

4

When you create a command that way, it's as though you're typing the new command into the command bar. So when you execute :Dall, it becomes the equivalent of typing :ggdG, which is obviously not a valid command.

What you want to do instead is have that execute in normal mode. You can make your command do that be using the normal command, like this:

command Dall normal ggdG
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.