format internet:

…please wait (42% completed)…

Archive for October, 2009

Pasting code into vi

Posted by javier ramirez on October 5, 2009

Every time I try to paste a big chunk of code into vi, it gets all messed up because of the autoindent. Each line gets indented taking the previous one as a reference, so when I try to paste something like..


global $wp_query;
parse_str($args, $r);
if (!isset($r['current'])) $r['current'] = -1;
if (!isset($r['show_all_parents'])) $r['show_all_parents'] = 0;
if (!isset($r['show_root'])) $r['show_root'] = 0;
if (!isset($r['list_tag'])) $r['show_root'] = 1;

..what I really get is..


global $wp_query;
  parse_str($args, $r);
    if (!isset($r['current'])) $r['current'] = -1;
      if (!isset($r['show_all_parents'])) $r['show_all_parents'] = 0;
        if (!isset($r['show_root'])) $r['show_root'] = 0;
          if (!isset($r['list_tag'])) $r['show_root'] = 1;

..and that’s no good. Fortunately the solution is really simple. Just enter command mode and write

:set paste

Now you can paste in all its glory. When you are done, you can get back to normal with

:set nopaste

So now you don’t have any excuses left to write original code. Get out there and copy the whole internet before I format it!!!

Advertisements

Posted in development, internet, javier ramirez, ubuntu | 10 Comments »