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

ChromeOS 42.0.2311.87 (Official Build) (64-bit) – A brief look

ChromeOS is a crafty devil. If you are not paying attention you can miss the fact that you’ve received an update. Its a little like a dog near to a buffet table, turn away and it will have a cake off there and carry on as normal without you being any the wiser. I decided to pen a few thoughts on the latest build which has found its way through the interwebs and landed on my HP 14″. When I say land, the image I’d like to convey is not so much a smooth journey opening up a wealth of treats but more of a thump and an exercise in wasting my time. These are the things I’ve noticed within the first few hours of the update. There will be more. Read more

Debian 8.0 Installer RC3 "Jessie" Officially Released

Debian Installer, the official installation system for the Debian distribution since the Sarge release, developed the Debian Installer Team, has been upgraded to version 8.0 RC3 and is now available for download and testing. Read more

LibreOffice 5.0 to Arrive in July, Bug Hunt Organized

The Document Foundation is preparing the groundwork for the next major version of LibreOffice, 5.0, which should be available by the end of July, if everything goes according to plan. Read more

KaOS 2015.04 is here -- Download the KDE-focused Linux distro now!

There are too many Linux distributions nowadays. Choice and variety is wonderful, but in this case, it spreads resources very thin. Linux-based operating systems might be further along by now if more developers came together to work on projects. For someone new to Linux, finding a distro can be a daunting task. Many of the releases are simply noise, making it hard to find the quality operating systems. KaOS is one of those quality operating systems. It is a wonderful Linux distribution that focuses on KDE. Quite frankly, if you are a KDE purist, this should be on your radar. To cerebrate the two-year anniversary of the distro, the team releases 2015.04. Whether you are a Linux noob, or even an an expert, you should give it a try. Read more