views:

144

answers:

3

Hey,

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?

+8  A: 

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

deinst
Thank you. I'll have a look at it.
phimuemue
+3  A: 

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 :)

monotux
+1 for mentioning how much functionality the major modes already have that make some snippets more work than just learning the relevant key chords/combinations.
semperos
+1  A: 

Don't forget abbrev-mode.

Charlie Martin