one input to many lines

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

one input to many lines

byro-byro
Hi. My name is Marcelo I'm new in this list and in VIM. My question is about
one "input" to many lines and columns in just one render (evaluation,
returns ...) For example, if i have a table of numbers and need add 10 for
the forth columns in the 420, 530 and 710 lines. Could you point any script,
code, theme to read,...
Thanks in advance,
            Marcelo

Reply | Threaded
Open this post in threaded view
|

Re: one input to many lines

Tim Chase-2
> Hi. My name is Marcelo I'm new in this list and in VIM.

Welcome!

> My question is about one "input" to many lines and
> columns in just one render (evaluation, returns ...) For
> example, if i have a table of numbers and need add 10 for
>  the forth columns in the 420, 530 and 710 lines. Could
> you point any script, code, theme to read,...

I'm not sure I fully understand what you're getting at here,
but I'll give a try (your English is a heckuva lot better
than my Portugese).

It sounds like you want to add "10" to either

-numbers on each row of a file, where those numbers are
found at columns 420, 530, and 710

or

-numbers found in column 4 of a table, but only make the
changes on certain line numbers

I *think* you mean the second rather than the first
interpretation.  You also don't specify whether they're
character-columns (in which case, adding 10 could bump the
number up to an additional column), if they're positional
columns (such as "column #4 starts at character 21 in the
line"), or delimited columns (such as with a CSV file).

My first thought would be (totally untested)

:g/./if '420,430,710'=~'\<'.line(".").'\>'| [action] |endif

where [action] is

s/\%4c\d\+/=submatch(0)+10/e

This *should* do [action] on each of the lines in the
comma-separated list.  An ugly hack, but it looks like it
should work.

As for the [action], this is where it would need
clarification regarding what defines a column.

Some sample data of the rows in question might help sort out
that matter.

Hope this helps.  If you have further questions, feel free
to ask.

-tim







Reply | Threaded
Open this post in threaded view
|

^M problems with migrating VIM from WinXP to Linux

Eric Leenman-2
Hi,

I'm using VIM on WinXP and want to move my files now also to Linux.
I copied the files and VIM reads in my .vimrc.
It comes up with a bounce of errors all related to ^M.

When I open this file on my WinXP I don't see them.
What do I need to do to make these ^M also visible on my WinXP machine?
Or do I need to change the files in a different way?

I want to remove the ^M on my WinXP machine and then copy them over again to
my linux machine.

Thanks
Eric

_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/

Reply | Threaded
Open this post in threaded view
|

Re: one input to many lines

Tim Chase-2
In reply to this post by Tim Chase-2
> Thanks a lot Tim. You is right about what I meant. To make it more clear,
> here are the rows.
> .
> .
> i1 0 9 180       /*this is the 420 line number*/
> .
> i2 0 17.1 220   /*430*/
> .
> i3 + 7.875 365 /*710*/
>
> the numbers in question are 180, 220 and 365.
> No tested your code yet. I'll give a try tomorrow.
[cut some of the bottom posting]
>>where [action] is
>>
>>s/\%4c\d\+/=submatch(0)+10/e

It looks like your columns are delimiter-based (using
whitespace), rather than columns based on physical/character
position.  That would change the previously-mentioned
[action] so that it becomes something like

s/^\(\S\+\s\+\)\{3\}\zs\(\d\+\)/=submatch(2)+10/e

You might have to tweak it a bit, but it *should* do the trick.

If you want some help deciphering it, it's easy enough to
explain any of the process, if you'd like.

-tim

PS:  Your reply came only to me.  It's best to "Reply to
All" in your mailer so that the whole list gets copied in on
the reply.  That way, you access the collective brain which
is a whole lot smarter than my solitary brain.  You also
have their time.  Fortunately, I check my email fairly
regularly, but in the event I was on holiday, you'd be
waiting for just me rather than getting a reply from anybody
on the list that had an answer.





Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

Thomas Adam
In reply to this post by Eric Leenman-2
--- Eric Leenman <[hidden email]> wrote:

> I want to remove the ^M on my WinXP machine and then copy them over again
> to
> my linux machine.

:h fileformat

You set it to whichever one you want to use at the time.

-- Thomas Adam


               
___________________________________________________________
Switch an email account to Yahoo! Mail, you could win FIFA World Cup tickets. http://uk.mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

Tim Chase-2
In reply to this post by Eric Leenman-2
> I want to remove the ^M on my WinXP machine and then copy
> them over again to my linux machine.

This is the ever-popular line-break-delimiter problem.

If you do

        :set ff?

Vim will likely currently come back with "dos".

You should be able to solve it by executing

        :set ff=unix

on either box, and then writing the file.  This file should
be recognized on both sides of matters.

-tim




Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

RICHARD PITMAN
In reply to this post by Eric Leenman-2
--- Eric Leenman <[hidden email]> wrote:

> Hi,
>
> I'm using VIM on WinXP and want to move my files now
> also to Linux.
> I copied the files and VIM reads in my .vimrc.
> It comes up with a bounce of errors all related to
> ^M.
>
> When I open this file on my WinXP I don't see them.
> What do I need to do to make these ^M also visible
> on my WinXP machine?
> Or do I need to change the files in a different way?
>
> I want to remove the ^M on my WinXP machine and then
> copy them over again to
> my linux machine.

Google is your friend :)

http://www.google.co.uk/search?hl=en&q=%22%5EM%22+dos2unix&btnG=Google+Search&meta=
http://www.vim.org/tips/tip.php?tip_id=26

HTH

Rich
Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

John (Eljay) Love-Jensen
In reply to this post by Eric Leenman-2
Hi Eric,

Do this to see which line-endings the buffer is associated with...

:set ff?

Do this to change them...

:set ff=unix
:wq

For info...

:help 'fileformat

On WinXP, I strictly use the unix (0A) line endings, I do not use mac (0D)
or dos (0D 0A).  I wish Vim internally supported nul (00) line endings, but
alas.  Note: if you transfer files to/fro Unix and Windows with FTP, you can
transfer text files as ASCII to do the end-of-line conversion for you.

Note, mac (0D) line endings are found on Apple DOS, ProDOS, GS/OS, and
System 9 and earlier OS's.  OS X is unix (0A) line endings, mostly, these
days.

Note, dos (0D 0A) line endings are CP/M, QDOS, PC-DOS, MS-DOS, DR-DOS,
Win16, Win32, WinNT (3.1, 3.5, 4.0, 2000, XP), WinNT64, OS/2 1.x (16-bit),
OS/2 2.x (32-bit) and later.  (There were some feeble, short-lived, unviable
attempts by IBM to make OS/2 use unix line endings.  Likewise, there were
some feeble, short-lived, unviable attempts by Microsoft to make WinNT use
unix line endings.)

Note, unix (0A) line endings are on Unix and Unix-like OS's (including OS
X), Amiga OS, and are an option as default for the Cygwin environment on
Windows.

Vim doesn't internally support "backwards" lf+cr (0A 0D), which was sometime
seen back in the 70's on teletype machines and preferentially used by some
printers and as the communication protocol by some dial-up BBS's.  I don't
know of any OS that utilizes lf+cr as the convention for end-of-line marker.

Vim doesn't internally support nel (85) "next line", from ECMA-048 (approved
as ISO 6429).  I don't know of anyone that uses nel for encoding
end-of-line.  Even the Amiga OS, which supported nel (85), did not use it
for end-of-line in files, and only rarely seen as an operational control
character in certain data streams.  Besides, since Windows code pages have
usurped this (80 - 9F) range of encoding code points, and MacRoman puts
glyphs there too, I don't expect there will be much of a revival for them.

HTH,
--Eljay

Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

Tim Chase-2
> I wish Vim internally supported nul (00) line endings,
> but alas.

You might be able to set up a before/after filter, much like
the gzip example (":help gzip-example"), using tr, of the form

        tr '\000\012' '\012\000'

This will swap all NUL characters in the file and 0x0A
(octal 012) characters.  Vim can then interpret the file
normally with the NUL characters as the line-breaks.  Then,
before writing the file, pipe it through the same "tr"
command to reswap your null bytes and your place-holder
character.

You don't have to use a LF/0x0A as your alternate byte...as
a matter of fact, it might be best to use a character that
doesn't occur anywhere in your source file, and that Vim
isn't likely to have conniptions about.  I'd adjust accordingly.

Just a few ideas for how to make Vim use NUL characters as
line delimiters :)

-tim





Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux + VIMs difference prblem

Eric Leenman-2
In reply to this post by John (Eljay) Love-Jensen
Thank you all I got it working.

One thing that seems to be broken is the VIM tip
On http://www.vim.org/tips/tip.php?tip_id=892

fun! InitBex()
let myvar = strftime("(%y%m%d)[%Hh%M]")
let myvar = "set backupext=_". myvar
execute myvar
echo myvar
endfun
map <ESC> :call InitBex()<CR>

On my WinXP I use gvim 6.3
On my Linux I use vim 6.3.86

What do I need to change so that this works on both versions?

Best Regards,
Eric

_________________________________________________________________
On the road to retirement? Check out MSN Life Events for advice on how to
get there! http://lifeevents.msn.com/category.aspx?cid=Retirement

Reply | Threaded
Open this post in threaded view
|

RE: ^M problems with migrating VIM from WinXP to Linux

Roy Fulbright
In reply to this post by Eric Leenman-2
A matched set of external utilities I often use in the *nix world are
"dos2unix" and "unix2dos".

HTH
Roy Fulbright


>From: "Eric Leenman" <[hidden email]>
>To: [hidden email]
>Subject: ^M problems with migrating VIM from WinXP to Linux
>Date: Wed, 03 May 2006 10:15:18 +0000
>
>Hi,
>
>I'm using VIM on WinXP and want to move my files now also to Linux.
>I copied the files and VIM reads in my .vimrc.
>It comes up with a bounce of errors all related to ^M.
>
>When I open this file on my WinXP I don't see them.
>What do I need to do to make these ^M also visible on my WinXP machine?
>Or do I need to change the files in a different way?
>
>I want to remove the ^M on my WinXP machine and then copy them over again
>to my linux machine.
>
>Thanks
>Eric
>
>_________________________________________________________________
>Don’t just search. Find. Check out the new MSN Search!
>http://search.msn.click-url.com/go/onm00200636ave/direct/01/
>


Reply | Threaded
Open this post in threaded view
|

Re: ^M problems with migrating VIM from WinXP to Linux

Eric Arnold-3
As for nulls as line breaks, you're not out of the woods yet.  Try:

:let @a='a^V^@b^V^@c'

which should set @a to 'a<00>b<00>c'.  Now put reg a,   "ap    into a
buffer.  The nulls will be treated as newlines.

Now yank back all the lines into reg b, and try

:echo strtrans(@b)
Reply | Threaded
Open this post in threaded view
|

Getting mappings working again on Linux machine

Eric Leenman-2
In reply to this post by Eric Leenman-2
Hi,

On my WinXP machine in gvim 6.3.0 my mapping works
On my Linux machine it partly works.

One of the things that doesn't work is the windows behaviour.
Like CTRL-C, CTRL-V , CTRL-X, ect

But also my own mappings work partly.
For example; i have a mapping like this which works on WinXP

  noremap <C-Left>  b
  inoremap <c-\><c-n> <C-left>

  noremap <C-Right> w
  inoremap <c-\><c-n> <C-Right>

But under Linux it doesn't
b and w itself does work.
Are C-Left and C-right special keys under Linux?

Best Regards
Eric

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

Reply | Threaded
Open this post in threaded view
|

Re: Getting mappings working again on Linux machine

Eddy Petrișor
On 5/4/06, Eric Leenman <[hidden email]> wrote:

> Hi,
>
> On my WinXP machine in gvim 6.3.0 my mapping works
> On my Linux machine it partly works.
>
> One of the things that doesn't work is the windows behaviour.
> Like CTRL-C, CTRL-V , CTRL-X, ect
>
> But also my own mappings work partly.
> For example; i have a mapping like this which works on WinXP
>
>   noremap <C-Left>  b
>   inoremap <c-\><c-n> <C-left>
>
>   noremap <C-Right> w
>   inoremap <c-\><c-n> <C-Right>
>
> But under Linux it doesn't
> b and w itself does work.
> Are C-Left and C-right special keys under Linux?

:behaviour mswin

--
Regards,
EddyP
=============================================
"Imagination is more important than knowledge" A.Einstein
Reply | Threaded
Open this post in threaded view
|

Re: Getting mappings working again on Linux machine

Eddy Petrișor
On 5/4/06, Eddy Petrişor <[hidden email]> wrote:

> On 5/4/06, Eric Leenman <[hidden email]> wrote:
> > Hi,
> >
> > On my WinXP machine in gvim 6.3.0 my mapping works
> > On my Linux machine it partly works.
> >
> > One of the things that doesn't work is the windows behaviour.
> > Like CTRL-C, CTRL-V , CTRL-X, ect
> >
> > But also my own mappings work partly.
> > For example; i have a mapping like this which works on WinXP
> >
> >   noremap <C-Left>  b
> >   inoremap <c-\><c-n> <C-left>
> >
> >   noremap <C-Right> w
> >   inoremap <c-\><c-n> <C-Right>
> >
> > But under Linux it doesn't
> > b and w itself does work.
> > Are C-Left and C-right special keys under Linux?
>
> :behaviour mswin

err, :behave mswin

and load the mswin.vim script

--
Regards,
EddyP
=============================================
"Imagination is more important than knowledge" A.Einstein
Reply | Threaded
Open this post in threaded view
|

Re: Getting mappings working again on Linux machine

Georg Dahn
In reply to this post by Eric Leenman-2
Hi!

--- Eric Leenman <[hidden email]> wrote:
> On my WinXP machine in gvim 6.3.0 my mapping works
> On my Linux machine it partly works.
>
> One of the things that doesn't work is the windows behaviour.
> Like CTRL-C, CTRL-V , CTRL-X, ect

Just add

source $VIMRUNTIME/mswin.vim

Best wishes,
Georg









               
___________________________________________________________
Too much spam in your inbox? Yahoo! Mail gives you the best spam protection for FREE! http://uk.mail.yahoo.com