我正在尝试从中学习 Vimscript,LearnVimscriptTHW并且遇到了:execute and :normal.
:normal! gg/a<cr>
从书中:
问题是normal!不识别“特殊字符”,如<cr>. 有很多方法可以解决这个问题,但最容易使用和阅读的是execute.
现在,当我使用:execute "normal! gg/a<cr>"它时,它对我不起作用。它不会a(char)在我当前的文件中搜索,而是它只是执行gg而不是什么都不做,但如果使用:execute "normal! gg/a\r"它,它可以工作并成功突出显示char a我的文件中的。
我也尝试了以下方法,但都没有奏效。
:execute "normal! gg/a"<cr>
:execute normal! gg/a<cr>
:execute "normal! gg/a<cr>"<cr>
从书中看来,execute内部转换<cr> to \r。那么,为什么在我的情况下没有发生。