Language Selection

English French German Italian Portuguese Spanish

Vim vs. Emacs: Indenting text before copying

Filed under
Software

I use Markdown on my blog for posts and comments, and I post at other sites that use Markdown (e.g. Stack Overflow). In Markdown, text indented four spaces is displayed as code, in pre tags.

I find myself often writing code in Vim or Emacs and needing to copy/paste it into a browser in a Markdown-suitable way.it back. This is easy to do in Vim and Emacs, only a few keystrokes. But "a few" is still greater than "one", so the heck with that. Let's script it.

Vim version

This keymapping in Vim will do it all for me:

vmap y :s/^/ /gv"+ygv:s/^ //

One clumsy thing about Vim is needing to restore the previous visual selection after each regex-replacement. I could use the marks '< and '> as ranges to :s instead, but that's more typing than simply doing gv in the mapping. Copying to the system clipboard is easy because Vim has a register "+ for that purpose.

This took me maybe 45 seconds to write, probably due to being pretty familiar with Vim already. But in Vim, mappings are easy. You just type the characters that you'd type if you were doing it manually.

Emacs version




More in Tux Machines

Kernel 3.18 development – the kernel column

Linus Torvalds announced Linux 3.17, the Shuffling Zombie Juror, saying, “The past week was fairly calm, and so I have no qualms about releasing 3.17 on the normal schedule”. The latest kernel includes a number of nice headline features, such as the new getrandom() system call and sealed files APIs that we covered in previous issues of LU&D. Linux 3.17 also includes support for less highlighted new features, such as new signature checking of kexec()’d kernel images and sparse files on Samba file systems (which is significant for those mounting Windows and Mac shares). Read more

Qt 5.4 Release Candidate Available

I am happy to announce that Qt 5.4 Release Candidate is now available. After the Qt5.4 Beta release we have done some build & packaging related updates in addition to large number of error fixes based on feedback from Beta release. Read more

Weston's IVI Shell Sees New Version

There hasn't been much in the way of exciting Wayland/Weston developments to report on this month, but its development is continuing in its usual manner. Out today is another version of the Weston IVI Shell as it still works to being accepted upstream. The weston-ivi-shell is a reference shell for Wayland's Weston compositor running on In-Vehicle Infotainment (IVI) systems. The Weston-IVI work dates back many months and today's revision to the shell marks its eighth public version as it still seeks to be accepted into mainline Weston. Read more

Python 3 Support Added To The GNOME Shell

The GNOME Shell 3.15.2 release fixes some visual glitching, improves the layout of the extension installation dialog, supports the CSS margin property, and offers other bug fixes and minor enhancements. Most notable to GNOME Shell 3.15.2 though is there's finally Python 3 support. Many GNOME components have long ported their Python 2 code to Python 3 while GNOME Shell's Python support has just received the Py3 treatment. Details on GNOME's overall Python 3 porting work can be found via this Wiki page. Read more