开发者

Emacs: Enter commands like in gedit

开发者 https://www.devze.com 2023-01-09 06:10 出处:网络
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 automatica

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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号