Why vimscript instead of another language? A philosophical or a technical question?

100 views
Skip to first unread message

Jose Caballero

unread,
Apr 28, 2024, 3:27:46 PMApr 28
to vim use
Hello,

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. 
I find python, or even bash, to be more readable and friendly than vimscript. 

What would be the advantage of keeping using vimscript instead of writing plugins in your favourite language? What am I missing?

Cheers,
Jose

Tony Mechelynck

unread,
Apr 28, 2024, 3:44:10 PMApr 28
to Jose Caballero, vim...@googlegroups.com
What you're missing, I think, is that your favourite language might
not be my favourite language. Indeed, it is possible to write plugins
in Python, Perl, Ruby, Lua, Mzscheme, Tcl, etc., but only a Vim
compiled with the corresponding interpreter interface built-in could
use them; while Vim script uses as commands the very same verbs used
as ex-commands when running Vim interactively, and it is guaranteed
that every Vim executable can use it. For all these reasons (and also
because all these additional languages are foreign to me while I had
to learn Vim ex-commands anyway in order to use it interactively),
_my_ favourite language for use with Vim is Vim script itself.

Best regards,
Tony.

Jose Caballero

unread,
Apr 28, 2024, 3:48:29 PMApr 28
to Tony Mechelynck, vim...@googlegroups.com
Hi Tony, 

Thanks a lot for such a fast response. 
However, I realise now I was not clear in my first post. I didn't mean to use a language that VIM is compiled with. I was simply talking about passing the selected text to your custom script with 

<.>! my_script.py

But I have to say you have a good point: "your favourite language might not be my favourite language"

Cheers,
Jose

Christian Brabandt

unread,
Apr 28, 2024, 3:58:11 PMApr 28
to vim...@googlegroups.com

On So, 28 Apr 2024, Jose Caballero wrote:

> Thanks a lot for such a fast response. 
> However, I realise now I was not clear in my first post. I didn't mean to use a language that VIM is compiled with. I was simply talking about passing the selected text to your custom script with 
>
> <.>! my_script.py

Yes you can do this. And what was your question now again?


Thanks,
Christian
--
"What are we going to do tonight, Bill?"
"Same thing we do every night Steve, try to take over the world!"

Антон Голубев

unread,
Apr 28, 2024, 5:28:44 PMApr 28
to vim...@googlegroups.com
I think there's a lot you can't do from an external script, like controlling windows or highlighting.

вс, 28 апр. 2024 г., 22:48 Jose Caballero <jcaball...@gmail.com>:
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/CACUP1u_pwJtgXU60GBELZE-%3DxaF8-C5L4QvfV%2BJ_4AfztF%2Bm3g%40mail.gmail.com.

Igbanam Ogbuluijah

unread,
Apr 28, 2024, 6:00:23 PMApr 28
to vim...@googlegroups.com
For me, it comes down to this choice: Do I want a setup like this?

        read results back into
  +---------------------------------+
  v                                 |
+-----+  write lines out to       +------+  (1)
| vim | ------------------------> | tool |
+-----+                           +------+


Or do I want this?

+-----+
| vim |   (2)
+-----+


It's amazing we can do 1, but 2 seems a lot more consolidated. 


- Igbanam

Tim Chase

unread,
Apr 28, 2024, 10:26:53 PMApr 28
to vim...@googlegroups.com
On 2024-04-28 22:59, Igbanam Ogbuluijah wrote:
> Do I want a setup like this?
>
> read results back into
> +---------------------------------+
> v |
> +-----+ write lines out to +------+ (1)
> | vim | ------------------------> | tool |
> +-----+ +------+
>
> Or do I want this?
>
> +-----+
> | vim | (2)
> +-----+
>
> It's amazing we can do 1, but 2 seems a lot more consolidated.

Consolidated? perhaps. But the separation is part of the appeal
of using Unix as an IDE[1]. I can replace each component independently
without needing a complete rip-and-replace of everything I know.
When RCS got supplanted by CVS, it didn't change my Makefile or
$EDITOR workflow. Same when Subversion supplanted CVS and when git
supplanted Subversion. Or when vim supplanted vi. (or when vi
displaced ed(1), FWIW). Same with my spell-check utilities. Or
my build-process orchestrator (though Makefiles have held up
remarkably well). When I want to debug Python with pdb instead of
C using GDB, I don't have to do anything special, just like I don't
have to worry that my next programming language doesn't have vim
integration because it has a standalone debugger that works in any
shell or $EDITOR.

I've used the integrated environments and they tend to churn. Visual
Studio, multiple Java IDEs, Sublime, Atom, VS Code, etc. Their
incorporate-everything rigidity becomes their downfall.

-tim

[1]
https://blog.sanctum.geek.nz/series/unix-as-ide/





Marc Chantreux

unread,
Apr 30, 2024, 9:12:28 AMApr 30
to vim...@googlegroups.com
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

Jose Caballero

unread,
May 1, 2024, 11:24:17 AMMay 1
to vim use
Thanks a lot everybody for the comments. Very helpful.

Cheers
Jose

Girish

unread,
May 2, 2024, 4:42:50 AMMay 2
to vim_use
There are some specific advantages. Regex handling, for example, as done in Python of Lua is not so suitable to the needs of an editor. You'll end up with many backslashes. Vim script gives you additional tools and implements regex optimally for editor users.

On a different note, learn vim9 script instead of legacy script. It looks familiar if you are from python or javascript, easy to read, compiled and very responsive. Does not make sense to use Python anymore inside Vim. Python has great standard library but most things can be implemented inside vim9 script without much fuss. 

Marc Chantreux

unread,
May 2, 2024, 5:38:51 AMMay 2
to vim...@googlegroups.com
On Thu, May 02, 2024 at 01:42:50AM -0700, Girish wrote:
> There are some specific advantages. Regex handling, for example, as done in
> Python of Lua is not so suitable to the needs of an editor.

Not to mention that "editor state" specific are just not available

|/\%V| \%V \%V inside Visual area |/zero-width|
|/\%#| \%# \%# cursor position |/zero-width|
|/\%'m| \%'m \%'m mark m position |/zero-width|
|/\%v| \%23v \%23v in virtual column 23 |/zero-width|

regards
Reply all
Reply to author
Forward
0 new messages