Aw: Re: How to execute :s command without adding the search pattern to the search history?

2011-06-14 Thread lith


Am Dienstag, 14. Juni 2011 08:27:50 UTC+2 schrieb Ben Schmidt: 
>
> Can't you just use histdel() after :s or :/ to get the unwanted entry
>
 
That's what I do now. There is a problem with that approach though. When a 
function that executes :s + histdel(-1) calls a function that does the same, 
2 items are removed, which is wrong. A Wokula's approach tries to deal with 
that.

Regards,
Tom

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Re: Aw: Re: How to execute :s command without adding the search pattern to the search history?

2011-06-13 Thread ZyX
Reply to message «Aw: Re: How to execute :s command without adding the search 
pattern to the search history?», 
sent 21:08:31 13 June 2011, Monday
by lith:

> Please correct my if I'm wrong, but the use of substitute() would also
> require the use of getline(), :delete, insert() etc. Marks would get lost.
> Cursor positioning would have to be done by hand. Multi-line patterns would
> make it even worse. Or am I missing something?
Generally no, but single-line patterns are normal with getline()+setline():

for lnr in range(a:firstline, a:lastline)
let line=getline(lnr)
let newline=substitute(line, pattern, replacement, flags)
if line isnot# newline
call setline(lnr, newline)
endif
endfor

Marks won't get lost in this case, though I would prefer the following:

let s:F={}
function s:F.histget(history)
let r=[]
while 1
let histentry=histget(a:history, -1)
if histdel(a:history, -1)
call insert(r, histentry)
else
return r
endif
endwhile
endfunction
function s:F.histextend(history, histlst)
while !empty(a:histlst)
call histadd(a:history, remove(a:histlst, 0))
endwhile
return a:histlst
endfunction
function Replace(pat, repl, f) range
let savedhistory=s:F.histget('search')
let savedwinview=winsaveview()
try
keepjumps lockmarks
\ execut a:firstline.','.a:lastline.'sm/'.escape(a:pat, '/').'/'
   \.escape(a:repl, '/').'/'.a:f
finally
call s:F.histextend('search', savedhistory)
call winrestview(savedwinview)
endtry
endfunction

Unlike previous one, it supports multiline patterns.

Original message:
> Am Montag, 13. Juni 2011 14:52:20 UTC+2 schrieb Charles Campbell:
> > For :s, use substitute().
> 
> Please correct my if I'm wrong, but the use of substitute() would also
> require the use of getline(), :delete, insert() etc. Marks would get lost.
> Cursor positioning would have to be done by hand. Multi-line patterns would
> make it even worse. Or am I missing something?
> 
> Regards,
> Tom


signature.asc
Description: This is a digitally signed message part.


Aw: Re: How to execute :s command without adding the search pattern to the search history?

2011-06-13 Thread lith


Am Montag, 13. Juni 2011 14:52:20 UTC+2 schrieb Charles Campbell:
>
> For :s, use substitute().
>
>
Please correct my if I'm wrong, but the use of substitute() would also 
require the use of getline(), :delete, insert() etc. Marks would get lost. 
Cursor positioning would have to be done by hand. Multi-line patterns would 
make it even worse. Or am I missing something?

Regards,
Tom

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Aw: Re: How to execute :s command without adding the search pattern to the search history?

2011-06-09 Thread lith
Hi,

Thanks. I didn't expect to find a function to solve this problem. Thanks.

Regards,
Tom

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php