Manipulation of strings in vim

In my opinion Vimscript has not a lot of features for manipulating strings. I often use matchstr(), substitute() en less often strpart(). Maybe there's more than that.

What is p.e. the best way to remove all text between linenumbers in the next string "a"?

let a = "\%8l............\|\%11l..........\|\%17l.........\|\%20l...." --> etc 

I want to keep only the digits and put them in a list. (the text between linenumbers can be diffent)

EDIT: output I want to obtain: ['8', '11', '17', '20'] --> etc


You're looking for split()

echo split(a, '[^0-9]\+') 


Given the new constraint: only the numbers from \%d\+l, I'd do:

echo map(split(a, '|'), "matchstr(v:val, '^%\\zs\\d\\+\\zel')")

NB: your vim variable is incorrectly formatted, to use only one backslash, you'd need to write your string with single-quotes. With double-quotes, here you'd need two backslashes. So, with

let b = '\%8l............\|\%11l..........\|\%17l.........\|\%20l....'

it becomes

echo map(split(b, '\\|'), "matchstr(v:val, '^\\\\%\\zs\\d\\+\\zel')")

Need Your Help

How to get the underlying value of an enum

c# .net enums

I have the following enum declared:

Angular ng-repeat causes flickering

javascript html angularjs angularjs-ng-repeat

I'm displaying a list of thumbnails with this code:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.