簡體   English   中英

新 Doom Emacs 用戶 - 嘗試設置全局設置密鑰

[英]New Doom Emacs user - trying to set global-set-key

我已經在 Doom Emacs 中安裝了 neotree。我想使用 global-set-key 綁定 function key 8 ([f8])。 我已經把

(global-set-key [f8] 'neotree-toggle)

在 init.el、config.el 和 custome.el 中。 當我按 f8 時,emacs 說“未定義”。

如果我輸入“:neotree-toggle”,它會起作用。

你能幫我嗎?

我有幾分鍾的時間,因為我已經在使用 doom,所以我做了一些實驗。 這應該適合你:

(global-set-key (kbd "<f8>") #'neotree)

在 emacs-lisp (elisp) 中,鍵可以用不同的方式表示,向量或字符串。 表示它們的常用方法是使用宏 kbd(當然是用於鍵綁定),它將一個簡單的字符串(如“Ch f”)轉換為表示 CTRL+h f 的鍵。

如果您想了解更多相關信息,可以在此處閱讀有關密鑰的 emacs 手冊,或在此處閱讀這篇非常不錯的博客文章

最后,如果您查看帶有Ch f RET global-set-key的 function global-set-key 的描述:

global-set-key is an interactive compiled Lisp function in ‘subr.el’.

(global-set-key KEY COMMAND)

  Probably introduced at or before Emacs version 1.4.

Give KEY a global binding as COMMAND.
COMMAND is the command definition to use; usually it is
a symbol naming an interactively-callable function.
KEY is a key sequence; noninteractively, it is a string or vector
of characters or event types, and non-ASCII characters with codes
above 127 (such as ISO Latin-1) can be included if you use a vector.

Note that if KEY has a local binding in the current buffer,
that local binding will continue to shadow any global binding
that you make with this function.

你必須給它一個鍵而不是一個命令,所以在你的情況下,它會是這樣的:

(global-set-key (kbd "<f8>") 'neotree-toggle)

在此處查看kbd 如何處理特殊鍵。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM