Emacs:像在 gedit 中一样输入命令
在 gedit 中,可以定义所谓的“片段”以简化输入。
例如,有一个片段while
。这意味着:如果您输入 while ->
(->
代表 Tab 键)。 gedit 会自动将其转换为以下内容(包括正确的缩进):
while (condition){
}
在 vim 中(与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请参阅 yasnippet。它提供了大多数主要语言的片段,并且很容易添加新的或修改旧的。
See yasnippet. It provides snippets for most major languages, and it is easy to add new ones or modify the old ones.
是的,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 :)
不要忘记缩写模式。
Don't forget abbrev-mode.