创建修复缩进的命令

Create Command to Fix Indentation

我熟悉 = 过滤器。 == 键序列缩进当前行,而 gg=G 缩进整个文件。我正在尝试创建一个 command:FixIndentation 来获得类似的效果,以修复整个文件中的缩进。

# 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

添加正常!告诉它以正常模式执行它:

command ReIndent execute "normal! gg=G"