我的.vimrc中有这行:
map gu :%s/\s\+$//<enter> :w<enter>
Run Code Online (Sandbox Code Playgroud)
删除尾随空格并同时保存文件.
当文件中有尾随空格时,它工作正常(它删除空格并保存文件),但是当没有尾随空格时它不保存文件,它只是说找不到模式:\ s + $.
注意:我发现了这一点,但我很好奇我的问题.
添加e
到搜索标志以禁止错误消息:
map gu :%s/\s\+$//e<enter> :w<enter>
Run Code Online (Sandbox Code Playgroud)
来自:help substitute
:
[e] When the search pattern fails, do not issue an error message and, in
particular, continue in maps as if no error occurred. This is most
useful to prevent the "No match" error from breaking a mapping. Vim
does not suppress the following error messages, however:
Regular expressions can't be delimited by letters
\ should be followed by /, ? or &
No previous substitute regular expression
Trailing characters
Interrupted
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
278 次 |
最近记录: |