2

In my .vimrc I list my vundle bundles like so:

cat ~/.vimrc

...
Bundle 'Raimondi/delimitMate'
Bundle 'kien/ctrlp.vim'
Bundle 'matchit.zip'
Bundle 'upAndDown'
Bundle 'rking/ag.vim'
...

Now, I would like to quickly sort my Bundle list by the bundles name, which works for lines where / is present, like so:

cat ~/.vimrc | sort -t "/" -k2,2

...
Bundle 'matchit.zip'
Bundle 'upAndDown'
Bundle 'rking/ag.vim'
Bundle 'kien/ctrlp.vim'
Bundle 'Raimondi/delimitMate'
...

How would I sort lines where there is nofoo/ prepended to the bundles name, as is the case e.g. for Bundle 'matchit.zip'?

1 Answer 1

1

You could always prepend a ./ and then remove it again. Eg:

sed "/\// ! s:^Bundle[[:space:]][[:space:]]*':&./:" ~/.vimrc |
  sort -t "/" -k2,2 |
  sed "s:\(^Bundle[[:space:]][[:space:]]*\)'\./:\1:"

Or with GNU sed, this can be shortened slightly with extended regular expressions:

sed -r "/\// ! s:^Bundle[[:space:]]+:&./:" ~/.vimrc |
  sort -t "/" -k2,2 |
  sed -r "s:(^Bundle[[:space:]]+)'\./:\1:"

Or just use a single literal space if you are sure the file is consistent.

1
  • Thank you @Graeme for your suggestion. I was hoping it could be possible to let solely sort itself to do the job, without the roundtrip over sed. I'll leave this open for now, in the hope that someone still comes with a terser solution
    – jottr
    Mar 27, 2014 at 18:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .