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

Leftovers: KDE

  • KDE's Project Neon Begins Publishing Daily Wayland Images
    KDE -- KDE's Project Neon has begun publishing daily images of the latest KDE Plasma stack powered atop Wayland rather than the X.Org Server. Jonathan Riddell passed along word that daily ISOs are now being spun of the freshest KDE development code with KWin acting as a Wayland compositor. The OS base is still Ubuntu 16.04 LTS.
  • The Qt Company's Qt Start-Up
    The Qt Company is proud to offer a new version of the Qt for Application Development package called Qt Start-Up, the company's C++-based framework of libraries and tools that enables the development of powerful, interactive and cross-platform applications and devices. Now used by around one million developers worldwide, the Qt Company seeks to expand its user base by targeting smaller enterprises.

Linux 4.5.3

I'm announcing the release of the 4.5.3 kernel. All users of the 4.5 kernel series must upgrade. The updated 4.5.y git tree can be found at: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-4.5.y and can be browsed at the normal kernel.org git web browser: http://git.kernel.org/?p=linux/kernel/git/stable/linux-st... thanks, greg k-h Read more Also: Linux 4.4.9 Linux 3.14.68

Open source near ubiquitous in IoT, report finds

Open source is increasingly standard operating procedure in software, but nowhere is this more true than Internet of Things development. According to a new VisionMobile survey of 3,700 IoT developers, 91% of respondents use open source software in at least one area of their software stack. This is good news for IoT because only open source promises to reduce or eliminate the potential for lock-in imposed by proprietary “standards.” What’s perhaps most interesting in this affection for open source, however, is that even as enterprise developers have eschewed the politics of open source licensing, IoT developers seem to favor open source because “it’s free as in freedom.” Read more

Ubuntu 16.04 – My Experience so Far and Customization

While I earnestly anticipated the release of Unity 8 with Xenial Xerus (after watching a couple of videos that showcased its function), I was utterly disappointed that Canonical was going to further push its release — even though it was originally meant to debut with Ubuntu 14.04. Back to the point at hand, I immediately went ahead and installed Unity Tweak Tool, moved my dash to the bottom (very important) and then proceeded to replace Nautilus with the extensive Nemo file manager which is native to Linux Mint and by far superior to the former (my opinion). Read more