(Move categories to tip template) |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(One intermediate revision by the same user not shown) | |||
Line 4: | Line 4: | ||
|previous=975 |
|previous=975 |
||
|next=977 |
|next=977 |
||
− | |created= |
+ | |created=2005 |
|complexity=intermediate |
|complexity=intermediate |
||
|author=Suresh Govindachar |
|author=Suresh Govindachar |
||
Line 14: | Line 14: | ||
This tip requires Perl and overwrites the unnamed register. |
This tip requires Perl and overwrites the unnamed register. |
||
− | The output of < |
+ | The output of <code>:ls</code> is sorted by buffer number. |
− | The following command results in a user defined command named < |
+ | The following command results in a user defined command named <code>:Ls</code> (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. |
The output of :Ls is the same as the output of :ls except that the output is sorted by buffer name. |
||
Line 23: | Line 23: | ||
<pre> |
<pre> |
||
− | command! -bang Ls redir @" | silent ls |
+ | command! -bang Ls redir @" | silent ls<bang> | redir END | echo " " | |
\ perl { |
\ perl { |
||
\ my $msg=VIM::Eval('@"'); |
\ my $msg=VIM::Eval('@"'); |
||
Line 43: | Line 43: | ||
\ VIM::Msg($msg); |
\ VIM::Msg($msg); |
||
\ } |
\ } |
||
− | \ |
+ | \ <CR> |
</pre> |
</pre> |
||
==Comments== |
==Comments== |
||
− | |||
− | ---- |
Latest revision as of 06:01, 13 July 2012
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>