更多分享内容可访问我的个人博客
本文简要介绍如何在 neovim 中使用 lua 来代替 vimscript。
vim
默认情况下不被 lsp 识别,因此后续的补全无法进行。这一点或许可以通过配置 lsp 解决。)。lua_single_target_luajit
。使用packer.nvim
代替原来的包管理器。
git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim
在~/.config/nvim/lua/plugins.lua
中写插件的配置。以下是一个示例,use
之后的很明显是插件,config
中是对packer.nvim
的配置。如果不需要更改配置,则按示例填入即可,注意先把其他插件删除,只留下第一个。
vim.cmd [[packadd packer.nvim]]
return require('packer').startup({
function()
use 'wbthomason/packer.nvim'
use 'vim-airline/vim-airline'
use 'vim-airline/vim-airline-themes'
use 'enricobacis/vim-airline-clock'
use 'liuchengxu/vim-which-key'
use 'voldikss/vim-floaterm'
use 'tpope/vim-surround'
use {'neoclide/coc.nvim', branch = 'release'}
use 'euclio/vim-markdown-composer'
use 'simnalamburt/vim-mundo'
use 'lambdalisue/suda.vim'
use 'hardcoreplayers/dashboard-nvim'
use 'ryanoasis/vim-devicons'
use 'voldikss/vim-codelf'
use 'RRethy/vim-illuminate'
use 'kshenoy/vim-signature'
use 'tpope/vim-repeat'
use 'sheerun/vim-polyglot'
use 'terryma/vim-smooth-scroll'
use 'liuchengxu/vista.vim'
use 'vhda/verilog_systemverilog.vim'
use 'easymotion/vim-easymotion'
use 'Yggdroot/indentLine'
use 'honza/vim-snippets'
use 'lilydjwg/fcitx.vim'
use 'xolox/vim-misc'
use {'cespare/vim-toml', ft = 'toml'}
use {'liuchengxu/vim-clap', run = ':Clap install-binary'}
use {'Yggdroot/LeaderF', run = ':LeaderfInstallCExtension'}
use 'preservim/nerdcommenter'
use 'rbtnn/vim-vimscript_indentexpr'
use 'tpope/vim-fugitive'
use 'airblade/vim-gitgutter'
use 'skywind3000/asynctasks.vim'
use 'skywind3000/asyncrun.vim'
use 'liuchengxu/space-vim-dark'
use 'dhruvasagar/vim-zoom'
use 'sbdchd/neoformat'
use 'leafOfTree/vim-vue-plugin'
use 'arzg/vim-swift'
use 'andymass/vim-matchup'
use 'nvim-treesitter/nvim-treesitter'
use 'jeffkreeftmeijer/vim-numbertoggle'
use 'bagrat/vim-buffet'
use 'luochen1990/rainbow'
use 'puremourning/vimspector'
use {'sindrets/diffview.nvim', requires = 'nvim-lua/plenary.nvim'}
end,
config = {
ensure_dependencies = true,
plugin_package = 'packer',
max_jobs = nil,
auto_clean = true,
compile_on_sync = true,
disable_commands = false,
opt_default = false,
transitive_opt = true,
transitive_disable = true,
auto_reload_compiled = true,
git = {
cmd = 'git',
subcommands = {
update = 'pull --ff-only --progress --rebase=false',
install = 'clone --depth %i --no-single-branch --progress',
fetch = 'fetch --depth 999999 --progress',
checkout = 'checkout %s --',
update_branch = 'merge --ff-only @{u}',
current_branch = 'branch --show-current',
diff = 'log --color=never --pretty=format:FMT --no-show-signature HEAD@{1}...HEAD',
diff_fmt = '%%h %%s (%%cr)',
get_rev = 'rev-parse --short HEAD',
get_msg = 'log --color=never --pretty=format:FMT --no-show-signature HEAD -n 1',
submodules = 'submodule update --init --recursive --progress'
},
depth = 1,
clone_timeout = 60,
default_url_format = 'https://github.com/%s'
},
display = {
non_interactive = false,
open_fn = nil,
open_cmd = '65vnew \\[packer\\]',
working_sym = '⟳',
error_sym = '✗',
done_sym = '✓',
removed_sym = '-',
moved_sym = '→',
header_sym = '━',
show_all_info = true,
prompt_border = 'double',
keybindings = {
quit = 'q',
toggle_info = '<CR>',
diff = 'd',
prompt_revert = 'r'
}
},
luarocks = {python_cmd = 'python'},
log = {level = 'warn'},
profile = {enable = false, threshold = 1}
}
})
然后在init.vim
顶部写入lua require('plugins')
,即可加载plugins.lua
配置文件。
如果你对 lua 配置很熟悉,可以直接用
init.lua
。该配置存在时init.vim
会失效。
安装插件只需要在plugins.lua
中写入配置,然后使用:PackerSync
即可。
该命令会一次性完成安装、更新、清理、配置。
以上只是该包管理器最基本的使用,更多功能应查看github。
所有lua
配置文件默认应当放在~/.config/nvim/lua
下。然后在init.vim
中调用。
比如有一个插件叫xxx
,然后可以使用配置文件~/.config/nvim/lua/plugins/Xxx.lua
。注意配置文件的名称尽量与插件名不同,比如这里将首字母大写。这是因为如果插件是 lua 插件,那么该插件很可能有一个文件叫xxx.lua
,一旦配置文件与该文件重名就会发生错误。
调用时只需要按路径写入即可。如lua require('plugins/Xxx')
。
一份中文学习资料。
建议掌握度较高之后再使用init.lua
,一开始还是用init.vim
缓冲一下,慢慢把配置从vimscript
转为lua
。
尚未完全转到 lua,个人配置仅供参考。