scorpio 9 months ago
parent
commit
b927bfe291
5 changed files with 65 additions and 22 deletions
  1. 1 0
      lazy-lock.json
  2. 3 3
      lua/keymap.lua
  3. 43 0
      lua/plugins/conform.lua
  4. 1 1
      lua/plugins/hop.lua
  5. 17 18
      lua/plugins/lsp-zero.lua

+ 1 - 0
lazy-lock.json

@@ -8,6 +8,7 @@
   "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" },
   "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
   "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
+  "conform.nvim": { "branch": "master", "commit": "8b407bb6175846cdc4c499e2a8d28109615a2089" },
   "dashboard-nvim": { "branch": "master", "commit": "63df28409d940f9cac0a925df09d3dc369db9841" },
   "friendly-snippets": { "branch": "main", "commit": "53d3df271d031c405255e99410628c26a8f0d2b0" },
   "gruvbox.nvim": { "branch": "main", "commit": "0940564208a490c173216c3b7d2188b0a5ad3491" },

+ 3 - 3
lua/keymap.lua

@@ -20,6 +20,6 @@ keymap.set("n", "<A-Right>", "<C-w>l", {})
 keymap.set("n", "<A-Down>", "<C-w>j", {})
 keymap.set("n", "<A-Up>", "<C-w>k", {})
 keymap.set("n", "<A-Left>", "<C-w>h", {})
-keymap.set("n", "<leader>ca", ":lua vim.lsp.buf.code_action<CR>",{})
-keymap.set("n", "<leader>lsp", ":Mason<CR>",{})
- keymap.set("n", "<leader>cr", ":lus vim.lsp.buf.format{async=true}<CR>",{ desc = "Reformat code"})
+keymap.set("n", "<leader>ca", ":lua vim.lsp.buf.code_action<CR>", {})
+keymap.set("n", "<leader>lsp", ":Mason<CR>", {})
+keymap.set("n", "<leader>cr", ":lus vim.lsp.buf.format{async=true}<CR>", { desc = "Reformat code" })

+ 43 - 0
lua/plugins/conform.lua

@@ -0,0 +1,43 @@
+-- formart 格式化
+return {
+  "stevearc/conform.nvim",
+  event = { "BufWritePre" },
+  cmd = { "ConformInfo" },
+  keys = {
+    {
+      -- Customize or remove this keymap to your liking
+      "<leader>f",
+      function()
+        require("conform").format({ async = true, lsp_fallback = true })
+      end,
+      mode = "",
+      desc = "Format buffer",
+    },
+  },
+  -- Everything in opts will be passed to setup()
+  opts = {
+    -- Define your formatters
+    formatters_by_ft = {
+      lua = { "stylua" },
+      python = { "isort", "black" },
+      html = { 'htmlbeautifier' },
+      css = { 'stylelint' },
+      yaml = { 'yamlfix' },
+      shell = { 'shellcheck' },
+      json = { "ixjson" },
+      javascript = { { "prettierd", "prettier" } }
+    },
+    -- Set up format-on-save
+    format_on_save = { timeout_ms = 100, lsp_fallback = true },
+    -- Customize formatters
+    formatters = {
+      shfmt = {
+        prepend_args = { "-i", "2" },
+      },
+    },
+  },
+  init = function()
+    -- If you want the formatexpr, here is the place to set it
+    vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
+  end,
+}

+ 1 - 1
lua/plugins/hop.lua

@@ -9,7 +9,7 @@ return {
         }
       )
       vim.keymap.set("n","<leader>hw",":HopWord<CR>",{desc="find any word"})
-      vim.keymap.set("n","<leader>hs",":HopLineStart<CR>",{desc="find any word"})
+    vim.keymap.set("n","<leader>hs",":HopLineStart<CR>",{desc="find any word"})
     end
   }
 }

+ 17 - 18
lua/plugins/lsp-zero.lua

@@ -1,24 +1,24 @@
 return {
   'VonHeikemen/lsp-zero.nvim',
-        branch = 'v1.x',
-        dependencies = {
-            -- LSP Support
-            {'neovim/nvim-lspconfig'},             -- Required
-            {'williamboman/mason.nvim'},           -- Optional
-            {'williamboman/mason-lspconfig.nvim'}, -- Optional
+  branch = 'v1.x',
+  dependencies = {
+    -- LSP Support
+    { 'neovim/nvim-lspconfig' },                   -- Required
+    { 'williamboman/mason.nvim' },                 -- Optional
+    { 'williamboman/mason-lspconfig.nvim' },       -- Optional
 
-            -- Autocompletion
-            {'hrsh7th/nvim-cmp'},         -- Required
-            {'hrsh7th/cmp-nvim-lsp'},     -- Required
-            {'hrsh7th/cmp-buffer'},       -- Optional
-            {'hrsh7th/cmp-path'},         -- Optional
-            {'saadparwaiz1/cmp_luasnip'}, -- Optional w
-            {'hrsh7th/cmp-nvim-lua'},     -- Optional
+    -- Autocompletion
+    { 'hrsh7th/nvim-cmp' },               -- Required
+    { 'hrsh7th/cmp-nvim-lsp' },           -- Required
+    { 'hrsh7th/cmp-buffer' },             -- Optional
+    { 'hrsh7th/cmp-path' },               -- Optional
+    { 'saadparwaiz1/cmp_luasnip' },       -- Optional w
+    { 'hrsh7th/cmp-nvim-lua' },           -- Optional
+
+    -- Snippets
+    { 'L3MON4D3/LuaSnip' },                   -- Required
+    { 'rafamadriz/friendly-snippets' },       -- Optional
 
-            -- Snippets
-            {'L3MON4D3/LuaSnip'},             -- Required
-            {'rafamadriz/friendly-snippets'}, -- Optional
-        
   },
   config = function()
     local config = require("lsp-zero")
@@ -27,5 +27,4 @@ return {
     config.setup()
     -- set keymap
   end
-
 }