我想让emacs突出显示末尾空格。我尝试使用WhiteSpace,并将show-trailing-whitespace
变量设置为true,但在每种情况下,它都会将换行符和空格字符的表示更改为$
和·
字符,如此截图所示。
理想情况下,我希望只看到以红色突出显示的末尾空格,而没有任何其他字符。
免责声明:我是emacs的新手,所以这可能很显然。
我想让emacs突出显示末尾空格。我尝试使用WhiteSpace,并将show-trailing-whitespace
变量设置为true,但在每种情况下,它都会将换行符和空格字符的表示更改为$
和·
字符,如此截图所示。
理想情况下,我希望只看到以红色突出显示的末尾空格,而没有任何其他字符。
免责声明:我是emacs的新手,所以这可能很显然。
show-trailing-whitespace
设置为t
,任何尾随的空格都会以红色显示。换行符和空格字符的表示方式没有改变。".emacs"
文件包含这一简单的代码行:(setq-default show-trailing-whitespace t)
如果您不想编辑".emacs"
文件,可以尝试以下方法:
C-h v show-trailing-whitespace RET
,然后点击customize
链接M-x customize-variable RET show-trailing-whitespace RET
)toggle
按钮将其设置为on (non-nil)
State
>Set for Current Session
State
>Save for Future Sessions
[编辑](感谢Francesco Frassinelli的评论)
使用setq-default
,值将更改为每个模式。
如果要禁用某些模式(例如term-mode
),则必须执行以下操作:
查找当前缓冲区的模式名称。通常,您可以使用M-x describe-mode RET
(快捷键C-h m
或<f1> m
)从缓冲区中获取它。
查找此模式的“hook”条目。通常,它是带有后缀-hook
的模式名称。您可以通过在描述模式的缓冲区中搜索“hook”来找到它。例如,您可以阅读:
Entry to this mode runs the hooks on ‘term-mode-hook’
将以下内容添加到您的".emacs"
文件中:
(add-hook 'term-mode-hook (lambda () (setq show-trailing-whitespace nil)))
或者您可以尝试:
M-x customize-variable RET term-mode-hook RET
INS
按钮(lambda () (setq show-trailing-whitespace nil))
State
>Set for Current Session
State
>Save for Future Sessions
请注意,使用setq
设置show-trailing-whitespace
时,它会自动变为缓冲区本地。
whitespace-style
变量的值更改为(face trailing)
如果更改生效需要重新启动空格模式。
要设置变量,请使用M-xset-variable
Enter。
另一个答案是使用库highlight-chars.el
(描述:高亮库)。
命令hc-toggle-highlight-trailing-whitespace
可以实现您的要求。
您也可以自动开启此类突出显示,无论是在所有地方还是在特定缓冲区或特定模式中。
whitespace-style
的(face trailing)
设置没有突出显示尾随空格,所以我很高兴我们有了这个解决方案。 - modulitoscounsel
的东西显示尾随空格。有没有什么办法解决这个问题?为counsel-mode
添加一个钩子以将show-trailing-whitespace
设置为 nil 似乎没有任何效果:https://imgur.com/a/GvFEaT0。 - adentinger