From 622889647d743896e8d98188895132d960c6e886 Mon Sep 17 00:00:00 2001 From: Young Xu Date: Sat, 4 Feb 2023 23:42:06 +0800 Subject: [PATCH] format lua code --- lua/keybindings.lua | 2 + lua/plugins-config.lua | 25 +++++++++ lua/plugins.lua | 117 ++++++++++++++++++++--------------------- 3 files changed, 83 insertions(+), 61 deletions(-) diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 7582567..d3012da 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -33,3 +33,5 @@ map('n', '2', ':BufferLineGoToBuffer 2', opt) map('n', '3', ':BufferLineGoToBuffer 3', opt) map('n', '4', ':BufferLineGoToBuffer 4', opt) map('n', '5', ':BufferLineGoToBuffer 5', opt) +map("n", "bp", ":BufferLineCyclePrev", opt) +map("n", "bn", ":BufferLineCycleNext", opt) diff --git a/lua/plugins-config.lua b/lua/plugins-config.lua index 65a5977..c15d902 100644 --- a/lua/plugins-config.lua +++ b/lua/plugins-config.lua @@ -11,3 +11,28 @@ require("nvim-dap-virtual-text").setup() vim.o.background = "dark" -- or "light" for light mode vim.cmd([[colorscheme gruvbox]]) + +local null_ls = require("null-ls") +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) +null_ls.setup({ + debug = false, + sources = { + null_ls.builtins.formatting.stylua, + null_ls.builtins.diagnostics.eslint, + null_ls.builtins.completion.spell, + }, + -- 保存自动格式化 + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + -- on 0.8, you should use vim.lsp.buf.format({ bufnr = bufnr }) instead + vim.lsp.buf.format({bufnr = bufnr }) + end, + }) + end + end, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 67cadd3..ed6b3ad 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,22 +1,22 @@ return require('packer').startup(function() - -- Packer can manage itself - use 'wbthomason/packer.nvim' - -- 文件树 - use { - 'nvim-tree/nvim-tree.lua', - requires = { - 'nvim-tree/nvim-web-devicons', -- optional, for file icons - }, - tag = 'nightly' -- optional, updated every week. (see issue #1193) - } + -- Packer can manage itself + use 'wbthomason/packer.nvim' + -- 文件树 + use { + 'nvim-tree/nvim-tree.lua', + requires = { + 'nvim-tree/nvim-web-devicons', -- optional, for file icons + }, + tag = 'nightly' -- optional, updated every week. (see issue #1193) + } -- 欢迎页 use { - 'goolord/alpha-nvim', - requires = { 'nvim-tree/nvim-web-devicons' }, - config = function () - require'alpha'.setup(require'alpha.themes.startify'.config) - end - } + 'goolord/alpha-nvim', + requires = { 'nvim-tree/nvim-web-devicons' }, + config = function () + require'alpha'.setup(require'alpha.themes.startify'.config) + end + } -- 主题 use { "ellisonleao/gruvbox.nvim" } -- 代码缩略图 @@ -35,51 +35,46 @@ return require('packer').startup(function() use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"} } -- 当前工作目录 use { - "ahmedkhalf/project.nvim", - config = function() - require("project_nvim").setup { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below + "ahmedkhalf/project.nvim", + config = function() + require("project_nvim").setup{} + end } - end - } - -- 空白缩进 - use "lukas-reineke/indent-blankline.nvim" - -- 改善启动时间 - use 'lewis6991/impatient.nvim' - -- 终端管理 - use {"akinsho/toggleterm.nvim", tag = '*', config = function() - require("toggleterm").setup() - end} - -- TODO管理 - use { - "folke/todo-comments.nvim", - requires = "nvim-lua/plenary.nvim", - config = function() - require("todo-comments").setup { - -- your configuration comes here - -- or leave it empty to use the default settings - -- refer to the configuration section below + -- 空白缩进 + use "lukas-reineke/indent-blankline.nvim" + -- 改善启动时间 + use 'lewis6991/impatient.nvim' + -- 终端管理 + use {"akinsho/toggleterm.nvim", tag = '*', config = function() + require("toggleterm").setup() + end } - end - } - -- git 管理 - use { - 'lewis6991/gitsigns.nvim', - } - -- 注释管理 - use { - 'numToStr/Comment.nvim', - config = function() - require('Comment').setup() - end - } - -- coc 代码提示 - use {'neoclide/coc.nvim', branch = 'release'} - -- 搜索 - use { - 'nvim-telescope/telescope.nvim', tag = '0.1.1', - requires = { {'nvim-lua/plenary.nvim'} } - } + -- TODO管理 + use { + "folke/todo-comments.nvim", + requires = "nvim-lua/plenary.nvim", + config = function() + require("todo-comments").setup{} + end + } + -- git 管理 + use { + 'lewis6991/gitsigns.nvim', + } + -- 注释管理 + use { + 'numToStr/Comment.nvim', + config = function() + require('Comment').setup() + end + } + -- coc 代码提示 + use {'neoclide/coc.nvim', branch = 'release'} + -- 搜索 + use { + 'nvim-telescope/telescope.nvim', tag = '0.1.1', + requires = { {'nvim-lua/plenary.nvim'} } + } + -- lua 代码格式化 + use({ "jose-elias-alvarez/null-ls.nvim", requires = "nvim-lua/plenary.nvim" }) end)