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

Android Leftovers

Linux Mint 18.1 Slated to Launch Later This Year, Will Be Codenamed “Serena”

Just a few minutes ago, Linux Mint project leader Clement Lefebvre announced the codename of the next Linux Mint release, versioned 18.1, along with a bit of information regarding its release date and upgrade possibility from previous versions. Read more

Ubuntu 17.04 "Zesty Zapus" Now Tracks Linux Kernel 4.9, Could Ship Kernel 4.10

On October 27, 2016, Joseph Salisbury from the Ubuntu Kernel Team has published yet another newsletter to keep Ubuntu Linux users in the loop with what Canonical is planning for the upcoming Ubuntu 17.04 operating system. Read more

APIStrat Boston to highlight link between APIs and open source projects

This year's API Strategy and Practice (known as APIStrat)—to be held in Boston on November 2-4—has a strong open source component running throughout the event, and with little wonder. Successful API strategies more often than not either contribute new open source projects, or draw on the rich source of tools already built by the open source community. The API mindset has always lent itself to an open source ethos. APIs are all about opening up internal assets, data, and systems in order to connect and collaborate with a wider ecosystem of partners and end users. Amongst leadership businesses that have a strong API strategy, seeing so many contribute and use open source projects is not surprising, and this is reflected throughout this year's APIStrat program. After all, two of the key specifications formats that are used across the industry to describe APIs—the Open API Initiative and RAML—are both open source projects. Projects like Mashape's Kong and Tyk's API Gateway are both open source and gaining greater recognition and uptake. Read more