Create Command to Fix Indentation

Viewed 108

I am familiar with the = filter. == key sequence indents the current line, while gg=G indents the entire file. I am trying to create a command:FixIndentation to get a similar effect, to fix indentation in the entire file.

# vim documentation provides example to map to key 
map <F7> gg=G<C-o><C-o>

# my attempt to map to a command fails
command ReIndent execute "gg=G"
:ReIndent

E492: Not an editor command: gg=G
1 Answers

add normal! to tell it to execute it in normal mode:

command ReIndent execute "normal! gg=G"
Related