Loading ...
Sorry, an error occurred while loading the content.

60720Re: raw fixed width data

Expand Messages
  • Marian Csontos
    Aug 2, 2005
      On Tue, 02 Aug 2005 22:52:40 +0200, Wes Potts <wespotts@...> wrote:

      > On 8/2/05, Tim Chase <vim@...> wrote:
      >> > For example: if I have a data file containing a sequence of
      >> > characters like:
      >> >
      >> > 123456789012345678901
      >> >
      >> > Can I set a "record length" of say... 3, such that vim
      >> > displays lines of 3 characters:
      >> >
      >> > 123
      >> > 456
      >> > 789
      >>
      >> If you don't mind actually editing your data (or a copy thereof),
      >> its something I've done before with simply
      >>
      >> :%s/.\{3}/&\r/g
      >>
      >> which will insert a newline after every third character. Adjust
      >> accordingly for your favorite record-length :)
      >>
      >> If the files are huge and slow Vim down, you can do something
      >> similar with sed, if you've got access to it:
      >>
      >> sed 's/.\{3\}/&\n/g' infile.txt > outfile.txt
      >
      > I've added newlines with perl before but, I'm hoping to find a
      > "better" solution as these files are sometimes HUGE (Gigabytes) and
      > when making edits repeatedly, a 4 or 5 step process ( copy, add EOLs,
      > edit, remove EOLs, copy back ) can be tedious. So, I'd prefer a
      > solution that would allow "in-place" editing. What I'm looking for is
      > a "record" editor.
      >

      Try
      :set wrap
      :set columns=<record-width>

      You can't move using standard keys - up, down arrows, jk, ^, 0, $, home,
      end,... - instead you have to use gj, gk, g^, g0, g$,...
      But You can map them:
      nmap <down> gj
      imap <down> <C-O>gj
      nmap <up> gk
      imap <up> <C-O>gk
      ...

      Regards

      -- Marian


      ________ Information from NOD32 ________
      This message was checked by NOD32 Antivirus System for Linux Mail Server.
      http://www.nod32.com
    • Show all 10 messages in this topic