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?

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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