2

I'm writing a vim function to set hard tabs and refactor indents in a whole file. This is the function:

function RefInd()
    :set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4
    gg=G
endfunction

And this is the error:

Error executing the function RefInd:
Line 2:
E492: Not an editor command: ^Igg=G
Press ENTER or type command to continue

Any help?

4
  • 3
    gg=G is a normal mode command. Use normal gg=G.
    – muru
    Mar 23, 2016 at 17:11
  • 4
    @muru You typically want to use normal! to make sure you're not running user-defined mappings. Mar 23, 2016 at 17:13
  • @Carpetsmoker of course! My, bad.
    – muru
    Mar 23, 2016 at 17:14
  • 4
    Take a look at :retab and :retab!.
    – jamessan
    Mar 23, 2016 at 17:50

1 Answer 1

7

The problem is that gg, = and G are normal mode commands, as opposed to ex commands which are used within a script. Writing normal gg=G should solve your problem.

As @Carpetsmoker has pointed out in his comment, using normal! instead of normal might be prudent to avoid running user-defined mappings by accident.

See also :help :normal.

1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.