Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: Enter commands like in gedit

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?

like image 605
phimuemue Avatar asked Jul 27 '10 14:07

phimuemue


People also ask

How do you enter command Mode in Emacs?

The Control key is usually labeled 'Control' or 'CTRL' and is held down while typing the other keys of the command. To enter Emacs, type emacs at the shell prompt. When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt.

What is the best text editor vi or Emacs?

With over 50 billion commands collected across the Cmd user base, we were able to deep dive into the stats and figure out if Vim is actually the preferred text editor compared to Emacs. In our findings, we found 93% of the users on all our clients' projects use Vi/Vim as their primary file editor.

What is the Emacs command in Linux?

Emacs is a text editor designed for POSIX operating systems and available on Linux, BSD, macOS, Windows, and more. Users love Emacs because it features efficient commands for common but complex actions and for the plugins and configuration hacks that have developed around it for nearly 40 years.


2 Answers

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

like image 96
deinst Avatar answered Sep 24 '22 21:09

deinst


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

like image 32
monotux Avatar answered Sep 22 '22 21:09

monotux