Language Selection

English French German Italian Portuguese Spanish

Vim vs. Emacs: Indenting text before copying

Filed under

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

Data indicates that Android picked up global market share from iOS last month

Tracking mobile web traffic, NetMarketShare computes the market share for mobile operating systems. Based on the data from last month, Android was able to widen its gap over iOS globally. Considering that the Apple iPhone 6s and Apple iPhone 6s Plus weren't launched until September 25th, the recently released phones accounted for a miniscule part of the data. The new models won't have a major effect on the results until the figures for this month are released. Read more

RapidDisk / RapidCache 3.4 now available.

RapidDisk is an advanced Linux RAM Disk which consists of a collection of modules and an administration tool. Features include: Dynamically allocate RAM as block device. Use them as stand alone disk drives or even map them as caching nodes to slower local disk drives. I pushed 3.4 into the mainline earlier this morning. Changes include:
  • Added ability to autoload RapidDisk volumes during module insertion.
  • Fixed bug in RapidDisk (volatile) volume size definition across 32 to 64 bit types.
  • Making use of BIT() macro in the driver.
  • Removed RapidDisk-NV support. It was redundant with the recently kernel integrated pmem code.
You can pull it from the git, yum, ZYpp & apt repos or download it from the SourceForge project page. To stay updated, you can follow the RapidDisk Google+ page.