Thomas 1 年之前
父節點
當前提交
c6238ea581
共有 9 個文件被更改,包括 423 次插入40 次删除
  1. 13 0
      init.lua
  2. 20 0
      lazy-lock.json
  3. 63 15
      lua/config/mappings.lua
  4. 137 0
      lua/plugins/completion.lua
  5. 10 4
      lua/plugins/mason.lua
  6. 25 0
      lua/plugins/nonels.lua
  7. 23 0
      lua/plugins/rust.lua
  8. 43 21
      lua/plugins/transparent.lua
  9. 89 0
      lua/plugins/utils.lua

+ 13 - 0
init.lua

@@ -20,5 +20,18 @@ opt.spell = true
 
 vim.cmd("autocmd BufRead,BufNewFile *.typ set filetype=typst")
 
+local symbols = { Error = "󰅙", Info = "󰋼", Hint = "󰌵", Warn = "" }
+
+for name, icon in pairs(symbols) do
+	local hl = "DiagnosticSign" .. name
+	vim.fn.sign_define(hl, { text = icon, numhl = hl, texthl = hl })
+end
+
+vim.diagnostic.config({
+  virtual_text = {
+    prefix = "●",
+  },
+})
+
 require("config.lazy")
 require("config.mappings")

+ 20 - 0
lazy-lock.json

@@ -1,28 +1,48 @@
 {
   "Comment.nvim": { "branch": "master", "commit": "e30b7f2008e52442154b66f7c519bfd2f1e32acb" },
+  "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
+  "auto-pairs": { "branch": "master", "commit": "39f06b873a8449af8ff6a3eee716d3da14d63a76" },
   "bufferline.nvim": { "branch": "main", "commit": "99337f63f0a3c3ab9519f3d1da7618ca4f91cffe" },
+  "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
+  "cmp-emoji": { "branch": "main", "commit": "e8398e2adf512a03bb4e1728ca017ffeac670a9f" },
+  "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
+  "cmp-nvim-lsp-signature-help": { "branch": "main", "commit": "031e6ba70b0ad5eee49fd2120ff7a2e325b17fa7" },
+  "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
+  "cmp-r": { "branch": "main", "commit": "37d75623b4d3119c60676bb1ba77902b62ad3405" },
+  "cmp-spell": { "branch": "master", "commit": "694a4e50809d6d645c1ea29015dad0c293f019d6" },
+  "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" },
   "conform.nvim": { "branch": "master", "commit": "cd75be867f2331b22905f47d28c0c270a69466aa" },
+  "crates.nvim": { "branch": "main", "commit": "5d2751f3d31c952663ade44669b6b63efa06e295" },
   "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" },
+  "dressing.nvim": { "branch": "master", "commit": "6741f1062d3dc6e4755367a7e9b347b553623f04" },
   "edgy.nvim": { "branch": "main", "commit": "9ea7b22048f08a1a0d49a4a789e36c2fe1b8579f" },
+  "fidget.nvim": { "branch": "main", "commit": "d855eed8a06531a7e8fd0684889b2943f373c469" },
+  "friendly-snippets": { "branch": "main", "commit": "45a1b96e46efe5fce8af325d4bed45feb9d29d0f" },
   "fzf-lua": { "branch": "main", "commit": "3d214f8db4a4119723ab5148b7a333aab3fa9063" },
   "gitsigns.nvim": { "branch": "main", "commit": "e9c4187c3774a46df2d086a66cf3a7e6bea4c432" },
   "image.nvim": { "branch": "master", "commit": "61c76515cfc3cdac8123ece9e9761b20c3dc1315" },
   "lazy.nvim": { "branch": "main", "commit": "b02c9eae6a250f98908c146d1dc1a891f5019f0a" },
   "lualine.nvim": { "branch": "master", "commit": "6a40b530539d2209f7dc0492f3681c8c126647ad" },
   "mason-lspconfig.nvim": { "branch": "main", "commit": "37a336b653f8594df75c827ed589f1c91d91ff6c" },
+  "mason-null-ls.nvim": { "branch": "main", "commit": "de19726de7260c68d94691afb057fa73d3cc53e7" },
   "mason.nvim": { "branch": "main", "commit": "f96a31855fa8aea55599cea412fe611b85a874ed" },
   "neo-tree.nvim": { "branch": "v3.x", "commit": "29f7c215332ba95e470811c380ddbce2cebe2af4" },
   "neogit": { "branch": "master", "commit": "a20031fb5d7d12148764764059243135085e5c9b" },
+  "none-ls.nvim": { "branch": "main", "commit": "0d1b3fa2ad0b371b94cb4b9a27ba6e5a1a915c91" },
   "nui.nvim": { "branch": "main", "commit": "61574ce6e60c815b0a0c4b5655b8486ba58089a1" },
+  "nvim-cmp": { "branch": "main", "commit": "7e348da6e5085ac447144a2ef4b637220ba27209" },
   "nvim-lspconfig": { "branch": "master", "commit": "216deb2d1b5fbf24398919228208649bbf5cbadf" },
+  "nvim-surround": { "branch": "main", "commit": "ec2dc7671067e0086cdf29c2f5df2dd909d5f71f" },
   "nvim-treesitter": { "branch": "master", "commit": "7f4ac678770175cdf0d42c015f4a5b6e18b6cb33" },
   "nvim-web-devicons": { "branch": "master", "commit": "c0cfc1738361b5da1cd0a962dd6f774cc444f856" },
   "onedark": { "branch": "master", "commit": "fae34f7c635797f4bf62fb00e7d0516efa8abe37" },
   "plenary.nvim": { "branch": "master", "commit": "a3e3bc82a3f95c5ed0d7201546d5d2c19b20d683" },
+  "rustaceanvim": { "branch": "master", "commit": "047f9c9d8cd2861745eb9de6c1570ee0875aa795" },
   "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
   "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
   "transparent.nvim": { "branch": "main", "commit": "fd35a46f4b7c1b244249266bdcb2da3814f01724" },
   "trouble.nvim": { "branch": "main", "commit": "03c1fbf518bef683422a3be9643c3da190903488" },
+  "vim-lastplace": { "branch": "master", "commit": "e58cb0df716d3c88605ae49db5c4741db8b48aa9" },
   "vim-tmux-navigator": { "branch": "master", "commit": "5b3c701686fb4e6629c100ed32e827edf8dad01e" },
   "which-key.nvim": { "branch": "main", "commit": "4d5b8959fd2a4df065ff76ccb39019aaa70cb0dc" }
 }

+ 63 - 15
lua/config/mappings.lua

@@ -1,6 +1,6 @@
 local wk = require("which-key")
-local builtin = require("telescope.builtin")
-local gitsigns = require('gitsigns')
+local telescope = require("telescope.builtin")
+local gitsigns = require("gitsigns")
 
 -- local tree = require "nvim-tree.api"
 
@@ -30,46 +30,54 @@ wk.add({
 		{
 			"<leader>ff",
 			function()
-				builtin.find_files()
+				telescope.find_files()
 			end,
 			desc = "Find file",
 		},
 		{
 			"<leader>fg",
 			function()
-				builtin.live_grep()
+				telescope.live_grep()
 			end,
 			desc = "Live grep",
 		},
 		{
 			"<leader>fb",
 			function()
-				builtin.buffers()
+				telescope.buffers()
 			end,
 			desc = "List buffers",
 		},
 		{
 			"<leader>fh",
 			function()
-				builtin.help_tags()
+				telescope.help_tags()
 			end,
 			desc = "Help",
 		},
 		{
 			"<leader>fs",
 			function()
-				builtin.lsp_document_symbols()
+				telescope.lsp_document_symbols()
 			end,
 			desc = "Find symbols",
 		},
 		{
 			"zz",
 			function()
-				builtin.spell_suggest()
+				telescope.spell_suggest()
 			end,
 			desc = "Suggest spell",
 		},
 
+		{
+			"<leader>ft",
+			function()
+				FormatBuffer("typstfmt")
+			end,
+			desc = "Typst fmt",
+		},
+
 		-- Centering cursor
 		{ "n", "nzzzv", desc = "Center cursor when n (next) during search" },
 		{ "N", "Nzzzv", desc = "Center cursor when n (next) during search" },
@@ -109,14 +117,54 @@ wk.add({
 			desc = "Typst formater",
 		},
 
-    -- Lsp
-    { "K", function() vim.lsp.buf.hover() end, desc = "LSP toggle" },
-    { "<leader>ca", function() vim.lsp.buf.code_action() end, desc = "LSP code action" },
-    { "<leader>cd", function() vim.diagnostic.setqflist() end, desc = "LSP code diagnostic" },
+		-- Lsp
+		{
+			"K",
+			function()
+				vim.lsp.buf.hover()
+			end,
+			desc = "LSP toggle",
+		},
+		{
+			"<leader>ca",
+			function()
+				vim.lsp.buf.code_action()
+			end,
+			desc = "LSP code action",
+		},
+		{
+			"<leader>cd",
+			function()
+				vim.diagnostic.setqflist()
+			end,
+			desc = "LSP code diagnostic",
+		},
+
+		-- Gitsigns
+		{
+			"<leader>nc",
+			function()
+				gitsigns.nav_hunk("next")
+			end,
+			desc = "Next change",
+		},
+		{
+			"<leader>pc",
+			function()
+				gitsigns.nav_hunk("prev")
+			end,
+			desc = "Previous change",
+		},
+
+		-- increment/decrement numbers
+		{ "<leader>+", "<C-a>", desc = "Increment number" }, -- increment
+		{ "<leader>-", "<C-x>", desc = "Decrement number" }, -- decrement
 
-    -- Gitsigns
-    { "<leader>nc", function() gitsigns.nav_hunk('next') end, desc = "Next change" },
-    { "<leader>pc", function() gitsigns.nav_hunk('prev') end, desc = "Previous change" },
+		{ "<leader>to", "<cmd>tabnew<CR>", desc = "Open new tab" }, -- open new tab
+		{ "<leader>tx", "<cmd>tabclose<CR>", desc = "Close current tab" }, -- close current tab
+		{ "<leader>tn", "<cmd>tabn<CR>", desc = "Go to next tab" }, --  go to next tab
+		{ "<leader>tp", "<cmd>tabp<CR>", desc = "Go to previous tab" }, --  go to previous tab
+		{ "<leader>tf", "<cmd>tabnew %<CR>", desc = "Open current buffer in new tab" }, --  move current buffer to new tab
 	},
 	{
 		mode = "v",

+ 137 - 0
lua/plugins/completion.lua

@@ -0,0 +1,137 @@
+return {
+	{ "hrsh7th/cmp-nvim-lsp" },
+	{
+		"L3MON4D3/LuaSnip",
+		-- follow latest release.
+		version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
+		-- install jsregexp (optional!).
+		build = "make install_jsregexp",
+		dependencies = { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets" },
+	},
+	{
+		"hrsh7th/nvim-cmp",
+		dependencies = { "hrsh7th/cmp-buffer", "f3fora/cmp-spell", "hrsh7th/cmp-path", "hrsh7th/cmp-emoji", "R-nvim/cmp-r", "hrsh7th/cmp-nvim-lsp-signature-help" },
+		config = function()
+			local cmp = require("cmp")
+			local luasnip = require("luasnip")
+
+			require("luasnip.loaders.from_vscode").lazy_load()
+
+			cmp.setup({
+				snippet = {
+					-- REQUIRED - you must specify a snippet engine
+					expand = function(args)
+						-- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
+						require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
+						-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
+						-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
+						-- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
+					end,
+				},
+				window = {
+					-- completion = cmp.config.window.bordered(),
+					-- documentation = cmp.config.window.bordered(),
+				},
+				mapping = cmp.mapping.preset.insert({
+					["<C-b>"] = cmp.mapping.scroll_docs(-4),
+					["<C-f>"] = cmp.mapping.scroll_docs(4),
+					["<C-Space>"] = cmp.mapping.complete(),
+					["<C-e>"] = cmp.mapping.abort(),
+					["<CR>"] = cmp.mapping(function(fallback)
+						if cmp.visible() then
+							if luasnip.expandable() then
+								luasnip.expand()
+							else
+								cmp.confirm({
+									select = true,
+								})
+							end
+						else
+							fallback()
+						end
+					end),
+
+					["<Tab>"] = cmp.mapping(function(fallback)
+						if cmp.visible() then
+							cmp.select_next_item()
+						elseif luasnip.locally_jumpable(1) then
+							luasnip.jump(1)
+						else
+							fallback()
+						end
+					end, { "i", "s" }),
+
+					["<S-Tab>"] = cmp.mapping(function(fallback)
+						if cmp.visible() then
+							cmp.select_prev_item()
+						elseif luasnip.locally_jumpable(-1) then
+							luasnip.jump(-1)
+						else
+							fallback()
+						end
+					end, { "i", "s" }),
+				}),
+				sources = cmp.config.sources({
+					{ name = "nvim_lsp" },
+					{ name = "buffer" },
+					{ name = "luasnip" }, -- For luasnip users.
+          { name = 'emoji' },
+          { name = "crates" }, -- cf rust
+          { name = 'cmp_r' },
+          { name = 'nvim_lsp_signature_help' },
+					{
+						name = "spell",
+						option = {
+							keep_all_entries = false,
+							enable_in_context = function()
+								return true
+							end,
+							preselect_correct_word = true,
+						},
+					},
+					{
+						name = "path",
+						option = {
+							-- Options go into this table
+						},
+					},
+					-- { name = 'ultisnips' }, -- For ultisnips users.
+					-- { name = 'snippy' }, -- For snippy users.
+				}, {
+					{ name = "buffer" },
+				}),
+			})
+
+			-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
+			-- Set configuration for specific filetype.
+			--[[ cmp.setup.filetype('gitcommit', {
+    sources = cmp.config.sources({
+      { name = 'git' },
+    }, {
+      { name = 'buffer' },
+    })
+ })
+ require("cmp_git").setup() ]]
+			--
+
+			-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
+			cmp.setup.cmdline({ "/", "?" }, {
+				mapping = cmp.mapping.preset.cmdline(),
+				sources = {
+					{ name = "buffer" },
+				},
+			})
+
+			-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
+			-- cmp.setup.cmdline(":", {
+			-- 	mapping = cmp.mapping.preset.cmdline(),
+			-- 	sources = cmp.config.sources({
+			-- 		{ name = "path" },
+			-- 	}, {
+			-- 		{ name = "cmdline" },
+			-- 	}),
+			-- 	matching = { disallow_symbol_nonprefix_matching = false },
+			-- })
+		end,
+	},
+}

+ 10 - 4
lua/plugins/mason.lua

@@ -14,6 +14,7 @@ return {
 					"rust_analyzer",
 					"tsserver",
 					"typst_lsp",
+          "html",
 					"r_language_server", --[[ "vscode-html-language-server" ]]
 				},
 			})
@@ -22,12 +23,17 @@ return {
 	{
 		"neovim/nvim-lspconfig",
 		config = function()
-			-- After setting up mason-lspconfig you may set up servers via lspconfig
-			require("lspconfig").lua_ls.setup({})
-			require("lspconfig").rust_analyzer.setup({})
-			require("lspconfig").r_language_server.setup({})
+      local capabilities = require('cmp_nvim_lsp').default_capabilities()
+
 
+			-- After setting up mason-lspconfig you may set up servers via lspconfig
+			require("lspconfig").lua_ls.setup({capabilities = capabilities})
+			-- require("lspconfig").rust_analyzer.setup({capabilities = capabilities})
+			require("lspconfig").r_language_server.setup({capabilities = capabilities})
+			require("lspconfig").html.setup({capabilities = capabilities})
+			require("lspconfig").typst_lsp.setup({capabilities = capabilities})
 			require("lspconfig").tsserver.setup({
+        capabilities = capabilities,
 				init_options = {
 					plugins = {},
 				},

+ 25 - 0
lua/plugins/nonels.lua

@@ -0,0 +1,25 @@
+return {
+	{
+		"jay-babu/mason-null-ls.nvim",
+		event = { "BufReadPre", "BufNewFile" },
+		dependencies = {
+			"williamboman/mason.nvim",
+			"nvimtools/none-ls.nvim",
+		},
+		config = function()
+			local null_ls = require("null-ls")
+
+      null_ls.setup()
+			-- null_ls.setup({
+			-- 	sources = {
+			-- 		null_ls.builtins.formatting.stylua,
+			-- 		null_ls.builtins.completion.spell,
+			-- 		require("none-ls.diagnostics.eslint"), -- requires none-ls-extras.nvim
+			-- 	},
+			-- })
+			require("mason-null-ls").setup({
+				ensure_installed = { "stylua", "jq", "html", "rust" },
+			})
+		end,
+	},
+}

+ 23 - 0
lua/plugins/rust.lua

@@ -0,0 +1,23 @@
+return {
+	{
+		"saecki/crates.nvim",
+		tag = "stable",
+		config = function()
+			require("crates").setup({
+				completion = {
+					cmp = {
+						enabled = true,
+					},
+				},
+				null_ls = {
+					enabled = true,
+				},
+			})
+		end,
+	},
+	{
+		"mrcjkb/rustaceanvim",
+		version = "^4", -- Recommended
+		lazy = false, -- This plugin is already lazy
+	},
+}

+ 43 - 21
lua/plugins/transparent.lua

@@ -1,23 +1,45 @@
 return {
-  "xiyaowong/transparent.nvim",
-  lazy = false,
-  config = function()
-    require("transparent").setup({ -- Optional, you don't have to run setup.
-      groups = { -- table: default groups
-        'Normal', 'NormalNC', 'Comment', 'Constant', 'Special', 'Identifier',
-        'Statement', 'PreProc', 'Type', 'Underlined', 'Todo', 'String', 'Function',
-        'Conditional', 'Repeat', 'Operator', 'Structure', 'LineNr', 'NonText',
-        'SignColumn', 'CursorLine', 'CursorLineNr', 'StatusLine', 'StatusLineNC',
-        'EndOfBuffer',
-      },
-      extra_groups = {
-        "NormalFloat", -- plugins which have float panel such as Lazy, Mason, LspInfo
-        "NvimTreeNormal", -- NvimTree}, -- table: additional groups that should be cleared
-        "WhichKeyFloat",
-      },
-      exclude_groups = {}, -- table: groups you don't want to clear
-    })
-  end
+	"xiyaowong/transparent.nvim",
+	lazy = false,
+	config = function()
+		require("transparent").setup({ -- Optional, you don't have to run setup.
+			groups = { -- table: default groups
+				"Normal",
+				"NormalNC",
+				"Comment",
+				"Constant",
+				"Special",
+				"Identifier",
+				"Statement",
+				"PreProc",
+				"Type",
+				"Underlined",
+				"Todo",
+				"String",
+				"Function",
+				"Conditional",
+				"Repeat",
+				"Operator",
+				"Structure",
+				"LineNr",
+				"NonText",
+				"SignColumn",
+				"CursorLine",
+				"CursorLineNr",
+				"StatusLine",
+				"StatusLineNC",
+				"EndOfBuffer",
+			},
+			extra_groups = {
+				"NormalFloat", -- plugins which have float panel such as Lazy, Mason, LspInfo
+				"NvimTreeNormal", -- NvimTree}, -- table: additional groups that should be cleared
+				"WhichKeyFloat",
+				"DiagnosticVirtualTextError",
+				"DiagnosticVirtualTextWarn",
+				"DiagnosticVirtualTextInfo",
+				"DiagnosticVirtualTextHint",
+			},
+			exclude_groups = {}, -- table: groups you don't want to clear
+		})
+	end,
 }
-
-

+ 89 - 0
lua/plugins/utils.lua

@@ -0,0 +1,89 @@
+return {
+	{
+    -- <S> to add ", (... Around selected text 
+    "kylechui/nvim-surround",
+		version = "*", -- Use for stability; omit to use `main` branch for the latest features
+		event = "VeryLazy",
+		config = function()
+			require("nvim-surround").setup({
+				-- Configuration here, or leave empty to use defaults
+			})
+		end,
+	},
+	{
+    -- Automatically add brackets by pairs
+		"jiangmiao/auto-pairs",
+		lazy = false,
+	},
+  {
+    "farmergreg/vim-lastplace"
+  },
+	{
+		"nvim-tree/nvim-web-devicons",
+		config = function()
+			require("nvim-web-devicons").setup({
+				-- your personnal icons can go here (to override)
+				-- you can specify color or cterm_color instead of specifying both of them
+				-- DevIcon will be appended to `name`
+				override = {
+					zsh = {
+						icon = "",
+						color = "#428850",
+						cterm_color = "65",
+						name = "Zsh",
+					},
+				},
+				-- globally enable different highlight colors per icon (default to true)
+				-- if set to false all icons will have the default icon's color
+				color_icons = true,
+				-- globally enable default icons (default to false)
+				-- will get overriden by `get_icons` option
+				default = true,
+				-- globally enable "strict" selection of icons - icon will be looked up in
+				-- different tables, first by filename, and if not found by extension; this
+				-- prevents cases when file doesn't have any extension but still gets some icon
+				-- because its name happened to match some extension (default to false)
+				strict = true,
+				-- same as `override` but specifically for overrides by filename
+				-- takes effect when `strict` is true
+				override_by_filename = {
+					[".gitignore"] = {
+						icon = "",
+						color = "#f1502f",
+						name = "Gitignore",
+					},
+				},
+				-- same as `override` but specifically for overrides by extension
+				-- takes effect when `strict` is true
+				override_by_extension = {
+					["log"] = {
+						icon = "",
+						color = "#81e043",
+						name = "Log",
+					},
+				},
+				-- same as `override` but specifically for operating system
+				-- takes effect when `strict` is true
+				override_by_operating_system = {
+					["apple"] = {
+						icon = "",
+						color = "#A2AAAD",
+						cterm_color = "248",
+						name = "Apple",
+					},
+				},
+			})
+			-- code
+		end,
+	},
+	{
+		"j-hui/fidget.nvim",
+		opts = {
+			-- options
+		},
+	},
+	{
+		"stevearc/dressing.nvim",
+		opts = {},
+	},
+}