emacs:通过下划线突出显示当前行

Joe*_*oel 16 emacs

在vim中,我们可以使用dotvim文件中的"set cursorline"将其打开.有没有办法在emacs中执行此操作?

Tre*_*son 21

在.emacs中,使用以下内容自定义面部hl-line-mode:

(global-hl-line-mode 1)
(set-face-attribute hl-line-face nil :underline t)
Run Code Online (Sandbox Code Playgroud)

hl-line-face是一个变量,用于存储用于显示当前行的面部 名称hl-line-mode.您可以根据:foreground :background自己的喜好自定义其他一些属性.在这里查看文档.

global-hl-line-mode突显在所有的缓冲区当前行圈.如果您只想在某些缓冲区中使用它,请将其打开M-x hl-line-mode.


Sim*_*ter 13

关于这个主题有一篇很好的博客文章:Mx all-things-emacs

以下代码(输入机智M-:或〜/ .emacs)使用RGB代码#222作为背景颜色(如果您处于256色模式!)并在当前行上加下划线.取消设置前景色使用默认颜色,例如,在突出显示的行上保留C++颜色.

(global-hl-line-mode 1)
(set-face-background 'highlight "#222")
(set-face-foreground 'highlight nil)
(set-face-underline-p 'highlight t)
Run Code Online (Sandbox Code Playgroud)

您可以使用Mx 检查是否需要更改highlight或(afaik较旧)hl-line和:

describe-face <RET> highlight
describe-face <RET> hl-line
Run Code Online (Sandbox Code Playgroud)

此命令显示用于突出显示当前行的字体的所有设置.你应该得到这样的输出:

Face: highlight (sample) (customize this face)
Documentation:
Basic face for highlighting.

        Family: unspecified
       Foundry: unspecified
         Width: unspecified
        Height: unspecified
        Weight: unspecified
         Slant: unspecified
    Foreground: unspecified
    Background: #222
     Underline: t
      Overline: unspecified
Strike-through: unspecified
           Box: unspecified
       Inverse: unspecified
       Stipple: unspecified
          Font: unspecified
       Fontset: unspecified
       Inherit: unspecified
Run Code Online (Sandbox Code Playgroud)


Por*_*lus 2

我认为没有完全等效的内置功能。您可以使用 hl-line-mode 来突出显示当前行,并且自定义该模式可以让您将突出显示设置为下划线,而不是默认的不同背景颜色 - 但下划线您会在该行文本的末尾处停止,而不是继续到窗口的边缘。