Fandom

Vim Tips Wiki

List buffers sorted by name

Redirected from VimTip976

1,624pages on
this wiki
Add New Page
Talk0 Share

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Tip 976 Printable Monobook Previous Next

created 2005 · complexity intermediate · author Suresh Govindachar · version 6.0


This tip requires Perl and overwrites the unnamed register.

The output of :ls is sorted by buffer number.

The following command results in a user defined command named :Ls (all user defined commands need to start with a capital letter).

The output of :Ls is the same as the output of :ls except that the output is sorted by buffer name.

Here's the command which you can place in your vimrc:

command! -bang Ls redir @" | silent ls<bang> | redir END | echo " " |
 \ perl {
 \ my $msg=VIM::Eval('@"');
 \ my %list=();
 \ my $key, $value;
 \ while($msg =~ m/(.*?line\s+\d+)/g)
 \ {
 \ $value = $1;
 \ $value =~ m/"([^"]+)"/;
 \ $key = $1;
 \ ($^O =~ /mswin/i) and $key = lc($key);
 \ $list{$key} = $value;
 \ }
 \ my $msg = '';
 \ for $key (sort keys %list)
 \ {
 \ $msg .= "$list{$key}\n";
 \ }
 \ VIM::Msg($msg);
 \ }
 \ <CR>

CommentsEdit

Also on Fandom

Random Wiki