Vim's line endings are a bit complicated. Whether a <CR> or <NL> is
treated as a literal character or a line break depends on context.
First, what is the value of "fileformat"? This will determine whether
\n or \r\n is the standard line break.
Secondly, how are you using the "lineString" value? When I use
let lineString="\r".substitute(lineString, ....
let @a = lineString
put a
I get a line break at the front. You don't say if you're using
setline() or what. Both setline() and append() will use the literal
values for \r and \n. As far as I know, the only way to get it to use
them as line breaks is to use some form of "put" (after deleting the
existing text, of course).
If there's a better way, I'd like to hear it, as this has always been
an annoyance for me also.
In Vim7 you have the option of giving a list to setline() and
append() , which solves the line break ambiguity:
call setline(".", [ '"", lineString ] )
Also, keep in mind that \n is stored as a NULL (which is the ^@) you are seeing.
On 6/15/06, Sylvain <[EMAIL PROTECTED]> wrote:
Ok, thank you very much, it's works now :-)
But I have another little problem, if, always for example, I put let
lineString="\r".substitute(lineString, '\(\w\+\)\(\s\+\)\(\w\+\)','\3\2\1',
'g') or change the \r by \n or \r\n or \n\r (always between double quote
;-)) Vim add ^M or ^@
Note : always in a function, not a map with a single line
Thanks
----- Original Message -----
From: "Yakov Lerner" <[EMAIL PROTECTED]>
To: "Sylvain" <[EMAIL PROTECTED]>
Cc: <[email protected]>
Sent: Thursday, June 15, 2006 3:39 PM
Subject: Re: ***SPAM*** Problem with regexp in macro
> On 6/15/06, Sylvain <[EMAIL PROTECTED]> wrote:
>> For example, consider this regexp :
>>
>> s:\(\w\+\)\(\s\+\)\(\w\+\):\3\2\1:
>>
>> It swap 2 first words on a line, if we test it, it's works..
>>
>> Now I want to make a function to do this job so I put in my .vimrc :
>>
>> map <F7> :call Swap2Words()<CR>
>>
>> function! Swap2Words()
>> let lineNumber=line(".")
>> let lineString=getline(lineNumber)
>> let lineString=substitute(lineString, "\(\w\+\)\(\s\+\)\(\w\+\)",
>> "\3\2\1", "g")
>
> You need single quotes here (apostrophes '...') not double quotes.
> Double quotes srew the backslashes inside. SIngle quotes
> preserve backslashes which is what you want.
>
> Yakov
>