Say I do a regex search for a class of characters, e.g.:
/[clsktb]
Is there a way to either sort lines by the number of matched characters, or to show the number of matches next to the line numbers?
Here is a variation:
:%s/^/\=len(split(getline('.'), '[clsktb]\zs')).' '/
That searches for line start, and for each line, gets its content and checks how many matches it has and puts the result back on the line.
If you must (using a Vim linked sausage command):
:sign unplace *
:g/^/ let n = 0 | let c = -1 | while c != 0 | let c = search('[-]', '', line('.')) | let n = n + 1 | endwhile | if n > 1 | exe 'sign define ' . n . ' text=' . (n-1) | exe 'sign place ' . n . ' line=' . line('.') . ' name=' . n . ' file=' . expand('%:p') | endif
Many Vims provide support for some scripting languages (Perl, Ruby, Python). If your vim has Perl support (some distributions don't provide it) you can use :perl perl-command
and :perldo perl-command
.
:perldo $_ = y/clsktb// . " :: $_"
Perl's y///
returns the number of occurrences of the chars in the default string ($_
). The new $_ is concatenation of that number followed by " :: " and the line.
\thanks{EvergreenTree}