Quote:
Originally Posted by roddierod
From my brief reading of VimScript doc it looks to mostly target plugin creators.
|
The biggest upshot of Vim9Script for your vimrc file is that multi-line commands and autocmds are much easier; for example:
Code:
# Go to the last cursor location when a file is opened unless this is a git commit.
au BufReadPost * {
if line("'\"") > 1 && line("'\"") <= line("$") && &filetype != 'gitcommit'
exe 'normal! g`"'
endif
}
# Convert buffer to and from scratch.
command S {
if &buftype == 'nofile'
setl swapfile buftype= bufhidden=
else
setl noswapfile buftype=nofile bufhidden=hide
endif
echo printf('swapfile=%s buftype=%s bufhidden=%s', &swapfile, &buftype, &bufhidden)
}
Previously this was:
Code:
" Go to the last cursor location when a file is opened unless this is a git commit.
au BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") && &filetype != 'gitcommit'
\| exe 'normal! g`"'
\| endif
" Convert buffer to and from scratch.
command! S
\ if &buftype is# 'nofile' | setl swapfile buftype= bufhidden=
\| else | setl noswapfile buftype=nofile bufhidden=hide | endif
\| echo printf('swapfile=%s buftype=%s bufhidden=%s', &swapfile, &buftype, &bufhidden)
All this mucking about with \ and \| was a right pain.
My vimrc is in Vim9Script (
over here, if anyone's interested) and I've written some small plugins with it. It's not all that different from the old VimScript, but with a few "obvious" fixes and typing.
In general I prefer it over the Lua stuff Neovim did; I don't think Lua is a terrible language, but it's not a great language either IMHO, and if I look at what people need to do to call "nnoremap" in Lua then it's doesn't strike me as a great improvement.
Is it worth rewriting your vimrc in Vim9Script or Lua? Probably not; VimScript still works and isn't going away. The main reason I did last year was so that I had some real-world code to try Vim9Script out on so I could provide some feedback to Bram based on that. Also worth pointing out you can mix VimScript and Vim9Script (by using "function" or "def" for function definitions).