Inserting output from external command into a buffer in Emacs

I recently found a keyboard shortcut for Emacs that I think can prove to be very helpful at times. The keyboard shortcut enables you to run an external command and insert its output into the buffer you are currently editing. An example of when this can be useful is putting a date marker in a file, to document when it was written/saved/modified/etc.

The keyboard shortcut is this: C-u M-!

For example, I might run the command date to insert the current date into the buffer. Or I might prefer my dates formatted in a way more familiar to my locale: date +'%F %R %Z'. (This makes the date format as YYYY-MM-DD HH:MM TZ, where TZ is the current “alphabetic time zone abbreviation”, e.g. 2087-02-26 06:00 CET.)

Another example is to include the directory listing of a certain folder into the current buffer. The command to run would then be ls.

Very handy indeed!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: