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

Itty bitty ARM module starts at $27

Variscite’s rugged, 50 x 25mm “DART-6UL” COM runs Linux on an i.MX6 UltraLite SoC, offers NAND, eMMC, and wireless, and starts at $27 in volume. In April, Variscite announced the world’s smallest i.MX6 computer-on-module with its 50 x 20mm, Freescale i.MX6-based DART-MX6. At 50 x 25mm, the DART-6UL doesn’t quite match those dimensions, but it offers greater power efficiency, making it well suited for IoT applications and battery-powered devices. Variscite claims it consumes only 5mA in suspend mode. Read more

Cleaning Linux: Jed’s Nappy /boot

My home NAS machine is an Ubuntu 14.04 machine with a ZFS volume. I need the linux-headers packages in order to compile my ZFS dkms modules. Those take more space than the kernels tend to, so I try and stay on top of removing them. Wonder how many I have? (Read the rest at FreedomPenguin)