如何自动删除vim中的尾随空格 [英] How can you automatically remove trailing whitespace in vim

查看:31
本文介绍了如何自动删除vim中的尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试在 Git 中提交一些文件时遇到尾随空格"错误.

我想在保存 Python 文件之前自动删除这些尾随空白字符.

你能配置 Vim 来做到这一点吗?如果是,怎么办?

解决方案

我找到了答案here.

将以下内容添加到我的 .vimrc 文件即可:

autocmd BufWritePre *.py :%s/s+$//e

末尾的 e 标志意味着如果搜索模式失败,该命令不会发出错误消息.有关更多信息,请参阅 :h :s_flags.>

I am getting 'trailing whitespace' errors trying to commit some files in Git.

I want to remove these trailing whitespace characters automatically right before I save Python files.

Can you configure Vim to do this? If so, how?

解决方案

I found the answer here.

Adding the following to my .vimrc file did the trick:

autocmd BufWritePre *.py :%s/s+$//e

The e flag at the end means that the command doesn't issue an error message if the search pattern fails. See :h :s_flags for more.

这篇关于如何自动删除vim中的尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆