vim 插件安装

使用Vundle管理,以保存lua文件立即格式化为例。

  • 首先需要安装lua-format

方案一:

  luarocks install --server=https://luarocks.org/dev luaformatter

方案二:

  源码安装,地址:https://github.com/Koihik/LuaFormatter

  ReadMe.md文件有详细的安装说明

    安装成功后,可以测试 lua-format file.lua。输出的就是格式化后代码,lua-format -i file.lua可以直接将格式化后代码覆盖原来文件

  • vim配置步骤:

1. mkdir ~/.vim/bundle

2. 下载Vundle

  cd ~/.vim/bundle 

  git clone "https://github.com/VundleVim/Vundle.vim.git"

3. vim ~/.vimrc新增内容:

" 设置Vundle的路径
set rtp+=~/.vim/bundle/Vundle.vim
 
" 使用Vundle管理插件
call vundle#begin()
 
" 保存插件列表
Plugin 'VundleVim/Vundle.vim'
 
" 你想要安装的其他插件
" Plugin 'tpope/vim-fugitive'
" Plugin 'airblade/vim-gitgutter' 
" 格式化lua插件 是github仓库地址
Plugin 'andrejlevkovitch/vim-lua-format'
 
" 结束Vundle的配置
call vundle#end() " 结束插件列表
 
"lua文件保存自动格式化代码
autocmd FileType lua nnoremap :call LuaFormat()
autocmd BufWrite *.lua call LuaFormat()
 
4. 保存后执行,:PluginInstall,直接插件通过git clone "https://github.com/andrejlevkovitch/vim-lua-format.git" 下载到~/.vim/bundle/

posted @ 2024-11-13 12:00  零下¥六度  阅读(19)  评论(0)    收藏  举报