Emacs yasnippet provides a lot of snippets for different program language, even markdown file. Also you can add your snippets if you like. For example, when I write blog with code, I don’t want to enter “{% highlight javascript %} {% endhighlight %}” everytime, with yasnippet help, I just need enter highlight
then press ‘Tab’, the highlight snippet code is generated automatically.
To make your emacs easy to use, I strongly suggest you use existing good emacs configuration if you are junior emacs user, like Steve Purcell. You can find detail how to install and use it from previous link. This configuration sets up a strong tool ido, which helps you to easy find your file. But sometimes it’s annoy when you want to open a directory or create a new file.
In ido mode, to create a new file you can enter C-x C-f
to find the directory you want to save to, then enter C-f
again to switch to normal mode, then you can continue enter your file name to create a new file.
In ido mode, to open directory you can enter C-x C-f
to find the directory first, then enter C-d
to open that directory.
You can find more information about ido from here
Now let’s install yasnippet.
-
M-x
, selectlist-packages
-
On the list,
C-s
to find “yasnippet”, you can find some plugin like “yasnippet yet another snippet extension for emacs”. Enterenter
to open it, then on the openned page you can seeInstall
on the top, move your cursor to there and pressenter
to install it. -
Now you have to add some config into ~/.emacs.d/lisp/init-local.el, if it’s not exist please create a new one like below:
- restart your emacs, and open any markdown file with extension ‘.md’, you can enter
highlight
and then pressTab
, you can see snippet works!!!