Emacs:像在 gedit 中一样输入命令

发布于 2024-09-11 18:59:56 字数 558 浏览 2 评论 0原文

在 gedit 中,可以定义所谓的“片段”以简化输入。

例如,有一个片段while。这意味着:如果您输入 while ->-> 代表 Tab 键)。 gedit 会自动将其转换为以下内容(包括正确的缩进):

while (condition){

}

在 vi​​m 中(与 Latex-suite 结合使用)我看到以下内容: 如果您输入 (,vim 只插入一个 (<如果你再次输入 (,vim 会自动将其转换为 \left( \right)

我发现 abbrev-mode但这种模式不能正确放置光标(即在括号之间或 while 循环内),

我设法创建了具有相同功能的自定义 emacs 键绑定/宏(无需按 Tab 键),所以我知道这是可能的。 但是,

是否已经有一个包可以让您毫不费力地定义此类“片段”?或者是否有任何严重的理由不使用此类东西?

in gedit it's possible to define so-called "snippets" for simpler input.

For example, there is a snippet while. This means: If you type while -> (-> stands for tab key). And gedit automatically converts it to the following (including correct indentation):

while (condition){

}

In vim (in conjunction with latex-suite) I saw the following: If you type (, vim inserts just a (. If you type ( a second time, vim automatically converts it to \left( \right).

I found abbrev-mode but this mode doesn't place the cursor properly (i.e. between parentheses or inside the while loop).

I managed to create custom emacs keybindings/macros that do just the same (without having to press the tab key), so I know it's possible.

However, is there already and package where you can define such "snippets" without much effort? Or are there even any serious reasons not to use such things?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

朦胧时间 2024-09-18 18:59:56

请参阅 yasnippet。它提供了大多数主要语言的片段,并且很容易添加新的或修改旧的。

See yasnippet. It provides snippets for most major languages, and it is easy to add new ones or modify the old ones.

画骨成沙 2024-09-18 18:59:56

是的,yasnippet 可能是正确的选择。但请确保您了解用于编辑的主要模式 - 在使用 LaTeX 编写时,请学习 auctex。主要模式可能包含使某些片段变得毫无意义的功能,并且可以更好地完成同样的事情。因此,不要在 LaTeX 缓冲区中使用开始/结束片段,而是尝试在 auctex 中使用 Cc Ce。 ETC :)

Yes, yasnippet is probably the way to go. But make sure you learn the major mode you're using for your editing - when writing in LaTeX, learn auctex. Major modes can contain functionality that makes some snippets pointless, and do the same thing even better. So instead of using a begin/end-snippet in a LaTeX buffer, try C-c C-e in auctex. Etc :)

櫻之舞 2024-09-18 18:59:56

不要忘记缩写模式。

Don't forget abbrev-mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文