On Do, 03 Aug 2017, Stephan Sinz wrote:
> I want to fold lines starting with similar ip addresses in a log file.
>
> ":set
> foldexpr=getline(v:lnum)=~'^\\([0-9]\\+\\)\\.'&&getline(v:lnum+1)=~'^\\1\\.'"
>
> doesn't work for folding similar ip adresses. what's wrong ?
That doesn't work, because the =~ operation does not understand the \1
marked group. BTW: for more complex expressions, it is a alot easier to
write specific functions, instead on trying to squeeze everything into a
single command line and having to double escape all kind of things...
This should work:
function! MyFoldExpr(lnum)
let content = getline(a:lnum)
let next_cont = getline(a:lnum+1)
if content =~ '\.' && next_cont =~ '\.'
if split(content, '\.')[0] == split(next_cont, '\.')[0]
return 1
else
" does not match, fold should end here
return '<1'
endif
else
" use foldlevel from previous line, if line contains a '.'
return content =~ '\.' ? '=' : 0
endif
endfunction
Best,
Christian
--
Manche wären sehr erstaunt zu erfahren, worauf ihre Achtung vor den
Menschen beruht.
-- Luc de Clapiers Vauvenargues (Nachgelassene Maximen)
--
--
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
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thursday, August 3, 2017
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment