As a person that is interested in the tools used to build useful software
- Why does ViM need a built-in language such as VimScript ( VimL )?
- Why It cannot be just C?
According to Wikipedia, Vim is written in both C and Vimscript, not only Vimscript.
The source code of Vim is available here, on Github.
The two biggest folders are
/src
: 26.321M
, mostly written in C. Most of the files are .c
and .h
in the folder itself (not in sub folders), but there is also some .po
files containing stuff like error messages in several languages.
/runtime
: 26.944M
, with Vimscript files, but not only:
/runtime/doc
: 9.155M
, mostly text help files (not vimscript, not code).
/runtime/syntax
: 5.671M
, actually it is Vimscript, but only a subpart of the language.
/runtime/spell
: 4.862M
are not Vimscript.
/runtime/tutor
: 2.409M
for Vim's tutorial. Most of the files are text files: the tutorial's translation in several languages.
So, actually, on Github, you can find more C code than Vimscript code.
And Vimscript isn't "source" code here.
Vimscript is a simpler language, usufull for
:
. Single line commands are often done with script language (for example, you probably use Bash, Fish or Zsh to run commands in your terminal like create a file or update your system). So it could be Python or JavaScript for example, but Vimscript is optimized for tasks related to Vim (like text editing, display and some more advanced tasks).~/.vimrc
. With C config file, you probably would have to compile it every time you want to change something in it, and it would be unusable (I edited my config files hundreds, maybe thousands of times, sometimes changed only one line).There is some cases where Vimscript can be better than other script languages:
iab
to create an abbreviation. If you want to abbreviate bar
by foo
, simply type iab foo bar
(you only need 5 extra chars), with many languages, it will be at least a("foo","bar")
so at least 8 chars.sed
does not have (and you can still do :%!sed
if you prefer).;
at the end of the line or {}
, use indent instead), but with autocmd
+python you would need to add indent on the middle on the line (hard to manage), or with Python only, I'm not sure it's possible to add command line by line in a similar way.Emacs has elisp, a language based on lisp, and used as a scripting language in this text editor. And Emacs also has C in its code
:substitute
is the core of vimscript interpreted language. BTW, a new language is being developed for Vim 9. If you want to start discussions, places like reddit will be more appropriated.