I want to count all ; present at the beginning of a line. ;;;sentence; => should give 3 and not 4 ;;sentence; => should give 2 and not 4 ;sentence; => should give 1 and not 4
On 20 nov, 18:09, Tim Chase <[email protected]> wrote: > > I would like to count number of character ; I have at the beginning of > > a line like that : > > ;;foo;bar;; > > > I want a count = 2 but this command returns 5. > > > :.s/;/&/gn > > I'm not sure I quite understand what you want, but you might be > able to hack something with \= like > > :%s/^;*/\=strlen(0).' '.submatch(0) > > which will count just the ";" at the beginning of the line and > put that count there. If you need the count in a variable > instead of on the line, you could do something like > > :echo strlen(matchstr(getline('.'), '^;*')) > > If you wanted to count all the ";" on the line, you could do > something more complex like: > > :%s/^.*/\=strlen( > substitute(submatch(0), '[^;]\+', '', 'g') > ).' '.submatch(0) > > (broken to make it easy to read, but should be all one line) > > Hope this helps, > > -tim --~--~---------~--~----~------------~-------~--~----~ You received this message from the "vim_use" maillist. For more information, visit http://www.vim.org/maillist.php -~----------~----~----~----~------~----~------~--~---
