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

Leftovers: KDE

  • Kubuntu Wily Alpha 2
    The Second Alpha of Wily (to become 15.10) has now been released!
  • Plasma Mobile References Images by Kubuntu
    We launched Plasma Mobile at KDE’s Akademy conference, a free, open and community made mobile platform.
  • The Sun Sets on KDE-Solaris
    The KDE-Solaris site has been shuttered. The subdomain now redirects to KDE techbase, which documents the last efforts related to KDE on then-OpenSolaris. From the year 2000 or earlier until 2013, you could run KDE — two, three or four — on Solaris, either SPARC or (later) x86. I remember doing packaging for my university, way back when, on a Sun Enterprise 10000 with some ridiculous amount of memory — maybe 24GB, which was ridiculous for that time. This led — together with some guy somewhere who had a DEC Alpha — to the first 64-bitness patches in KDE. Solaris gave way to OpenSolaris, and Stefan Teleman rebooted the packaging efforts in cooperation with Sun, using the Sun Studio compiler. This led to a lot of work in the KDE codebase in fixing up gcc-isms. I’d like to think that that evened up the road a little for other non-gcc compilers later.
  • What It Takes Porting Qt Applications To Wayland

Tizen Leftovers

  • Tizen 2.3.1 and Tizen 2.4 Beta SDK Mobile Preview announced at Tizen Developer Summit 2015 Bengaluru India
    At the Tizen Developer Summit 2015 (TDS) event in Bengaluru, India July 30-31, Samsung has announced new Tizen SDKs for their Smartphones, Smartwatches, and Smart TVs. The Summit is focused in helping to grow the Tizen ecosystem by educating developers to the Tizen Operating System. Samsung are still offering developers 100% revenue for their apps until January 2016, making it an attractive proposition.
  • [Developer] AIDA64 now available for Tizen
    AIDA64 is a Hardware and software information utility for tizen based devices. Based on the extensive hardware knowledge of the AIDA64 for Windows application, AIDA64 for Tizen is capable of showing various diagnostic information for the phones and tablets including:

Android Leftovers