Regex search, visual block results and then sort

Viewed 30

Let's say I have a list of URLs separated by a white space with their corresponding titles.

http://url1.com/qfwarsas/ gb_title 1 - 1
http://url2.com/arsas/ xe_title 2 - 2
http://url3.com/qfsas ah_title 3 - 3

I'm trying to sort the lines by the titles to look like this:

http://url3.com/qfsas ah_title 3 - 3
http://url1.com/qfwarsas/ gb_title 1 - 1
http://url2.com/arsas/ xe_title 2 - 2

I can do it by running a simple macro to copy out the first letter of each title to the front of the line, then ctrl+v sort the blocks, then remove the first letters of each line. I wonder if there's a way to do it using regex and visual block selection?

Regex to get title first letters selection is

:s/\v[^ ]* (.)/\1/

but when i try to convert that into visual block selection i'm running into issues.

Any ideas?

1 Answers

If your separator is a white space, you can use

:sort / /

The default behavior of :sort using a search pattern is to sort on whatever follows the match.

Related