hello Jose,
I don't know how clear and helpful this post was: please don't hesitate
to ask questions.
On Sun, Apr 28, 2024 at 07:51:39PM +0100, Jose Caballero wrote:
> I am just curious about it. I have just been experimenting with it, and it is
> possible to send the selected range of lines, or even the entire buffer, to an
> external script. Right? In my case, in python.
not only filter with a pipe but also write and read from them.
stats about the abstract of your article:
:%w !wc
execute commands from a doc
:'<,'>w !sh
:'<,'>w !perl
:'<,'>w !raku
poor man package navigator (I use it all the time)
:r!aptitude search '~nvim'
then you move the cursor to the package name and type:
:r! apt-cache show <cfile
also
> I find python, or even bash, to be more readable and friendly than vimscript.
we're typing vim langage all day long and there is no way another
langage can compete for tasks like
1
%d
/Subject/
w/tmp/a
1,/foo/w/tmp/a
the sad part is that the rest of the vim9script syntax is inspired by
langages like python, js which implies so many useless parentheses
(in contrary of langages like awk, ruby, perl and the *awesome* raku)
> What would be the advantage of keeping using vimscript instead of writing
> plugins in your favourite language?
I use both of them for different things:
* vim9script has no competitor when in comes to tune the editor
* langages like perl, raku, awk, sed, ed and shell (zsh, dash, ksh, rc, …)
to transform vim to a multipurpose UI.
The most simple example I have in mind is a process manager:
command! Update %!pstree -Up
command! Kill !kill <cword>
command! NextPid /[0-9]\+/
set fdm=marker fmr=┬,└ fdt=getline(v:foldstart)
(don't define mappings, define commands that can be mapped)
I also try to make my "widgets" available both from vim and zsh.
As exemple: that's the way I use my MRU (commands ED(it) and CD)
# ~/.vim/r/was_fzy.vim:
au DirChanged window,global silent !echo "<afile>:p:s!/$!!" >> ~/.was-here
au BufNewFile,BufReadPre * silent !echo "<afile>:p" >> ~/.was-edit
command -nargs=0 CD silent exec "!>~/.v echo lcd $( was_fzy ~/.was-here )" |so ~/.v |redraw!
command -nargs=0 ED silent exec "!>~/.v echo ed $( was_fzy ~/.was-edit )" |so ~/.v |redraw!
From my zsh:
was_fzy () { _was_fzy_db $1 | _was_fzy_ui }
_was_fzy_db () {
perl -E '
# delete from the list
# * older occurrences of the same name
# * (re)moved entries
# reverse is important to keep the most recent one
@s = reverse grep {chomp; !$seen{$_}++ && -e} reverse <>;
# release stdout first so the pipe can go on
say for @s;
# then save the deletations
open U, ">", $ARGV;
say U for @s;
' "$@"
}
_was_fzy_ui () {
tac | fzy
}
I can access to the same features from zsh bindings.
regards,
--
Marc Chantreux
Pôle CESAR (Calcul et services avancés à la recherche)
Université de Strasbourg
14 rue René Descartes,
BP 80010, 67084 STRASBOURG CEDEX
03.68.85.60.79