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

Next Tizen Smartphone, Samsung Z3 SM-Z300H, Imported to india for Testing

The Samsung Z3 SM-Z300H is going to be the second Tizen based Smartphone to begin testing in India and hopefully final release. We Initially reported on the existence of the Z3 with Sammobile confirming it will be the next Tizen mobile phone to be released. Now our friends at Best Tizen Apps have noticed a shipment of a few “SM-Z300H” Smartphones making the journey from Korea to Bangalore India, reported for testing purposes. The phone is shipped as costing $205 USD per unit around 13,039 INR, but this is more of a speculated price and does not reflect final retail pricing. Read more

It's Now Easier Managing Systemd In KDE

For those running KDE on a systemd-based Linux system, the KDE Control Module for controlling this init system and its options has been updated. Read more

See How Your Linux PC Compares To The Core i7 5775C With Iris 6200 Graphics

Now that I seem to have found a workaround for my Core i7 5775C Broadwell Linux issue that resulted in very frequent kernel panics, it's off to the benchmark races. Here are some preliminary Linux benchmark figures for this first socketed Intel Broadwell LGA-1150 desktop CPU with Iris 6200 graphics. Read more

Oxide Vulnerabilities Closed in Ubuntu OSes

Canonical has revealed some details in a security notice about a few Oxide vulnerabilities that have been found and repaired in Ubuntu 15.04, Ubuntu 14.10, and Ubuntu 14.04 LTS operating systems. Read more