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?
  • 5
    vim is developed in C. only the "runtime" like plugins and filetype support is written in vim script. can you clarify your question? – Mass Sep 9 '20 at 16:26
  • 1
    Please clarify your question and vote to reopen it once it is done. Visiting github.com/vim/vim should give you a pretty good view of what language Vim is written in: The program itself is in C, Vimscript is used for the configuration and the plugins of the editor. – statox Sep 9 '20 at 17:01
  • there is some "pros" of using Vimscript language (see my answer). What are the "cons" in your opinion? – ewen-goisot Sep 9 '20 at 17:40
  • Vimscript language has started from the ex-commands (that came from vi, that came from ed/ex...). What can be interpreted in in the command-line, like :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. – Luc Hermitte Sep 9 '20 at 18:42
  • Welcome on the Stack Exchange! You can often formulate your question to become on-topic. For example, "why is X better than Y", that is "opinion-based" and is closed. But asking, "what are the reasons of the supporters of X", that is already not opinion-based, even an anti-X supporter can answer it. – peterh Sep 9 '20 at 19:50

Vim is written in C language.

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.

Why is there also Vimscript code?

Vimscript is a simpler language, usufull for

  • very short commands while you are using Vim, with :. 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).
  • user-made config file like ~/.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).
  • plugins made by yourself or someone else. Vimscript is probably easier to use if you don't want to make your plugin too complex and if it has to interact with other Vim's components. Actually, some Vim's plugins are written in other languages, like Python, example: deoplete.
  • syntax files (for tasks like syntax highlighting in many languages), as we seen in Vim's repository on Github. Some users will need to do syntax-related command, either in a personal config file or in some plugins to use colors. By the way, syntax does not have to be related to a programming language, it can colors symbols like in undotree. Lots of plugins have a syntax file.

There is some cases where Vimscript can be better than other script languages:

  • You can have very short commands like 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.
  • It has its own regex engine with some features sed does not have (and you can still do :%!sed if you prefer).
  • Python also has a very simple syntax without too much symbols (don't need ; 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.

Note: some other notable editors also have their own languages.

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.