From c7757805dfa4a0f28b03d8fad4c56b6cb7b010ed Mon Sep 17 00:00:00 2001 From: gameloader Date: Tue, 18 Oct 2022 22:12:27 +0800 Subject: [PATCH] add some plugin and complete config --- init.lua | 11 ++- lua/basic.lua | 3 +- lua/keybindings.lua | 4 +- lua/lsp/cmp.lua | 1 + lua/lsp/config/lua.lua | 84 +++++++++---------- lua/plugin-config/buffer_line.lua | 3 + lua/plugin-config/bufferline.lua | 4 - lua/plugin-config/cmake_tool.lua | 11 +++ lua/plugin-config/coderunner.lua | 1 + lua/plugin-config/dashboard.lua | 39 ++++++++- lua/plugin-config/hop.lua | 14 ++++ lua/plugin-config/indent-blankline.lua | 7 ++ .../{lualine.lua => lua_line.lua} | 2 +- lua/plugin-config/neoscroll.lua | 12 +++ lua/plugin-config/orgmode.lua | 13 +++ lua/plugin-config/spectre.lua | 1 + lua/plugins.lua | 44 +++++++++- readme.md | 34 ++++++-- 18 files changed, 225 insertions(+), 63 deletions(-) create mode 100644 lua/plugin-config/buffer_line.lua delete mode 100644 lua/plugin-config/bufferline.lua create mode 100644 lua/plugin-config/cmake_tool.lua create mode 100644 lua/plugin-config/hop.lua create mode 100644 lua/plugin-config/indent-blankline.lua rename lua/plugin-config/{lualine.lua => lua_line.lua} (96%) create mode 100644 lua/plugin-config/neoscroll.lua create mode 100644 lua/plugin-config/orgmode.lua create mode 100644 lua/plugin-config/spectre.lua diff --git a/init.lua b/init.lua index 18bbcab..c49dce6 100644 --- a/init.lua +++ b/init.lua @@ -5,20 +5,25 @@ require("plugins") require("keybindings") require("plugin-config/nvim-tree") -require("plugin-config/bufferline") +require("plugin-config/buffer_line") +require("plugin-config/spectre") require("plugin-config/treesitter") require("plugin-config/telescope") require("plugin-config/whichkey") require("plugin-config/comment") require("plugin-config/mason") -require("plugin-config/lualine") +require("plugin-config/lua_line") require("plugin-config/notify") require("plugin-config/nvim-autopairs") require("plugin-config/table-mode") +require("plugin-config/orgmode") require("plugin-config/project") require("plugin-config/dashboard") -require("plugin-config/JABS") +require("plugin-config/neoscroll") +require("plugin-config/hop") +-- require("plugin-config/JABS") require("plugin-config/toggleterm") +require("plugin-config/indent-blankline") require("plugin-config/coderunner") require("plugin-config/lazygit") -- require("plugin-config/neogit") diff --git a/lua/basic.lua b/lua/basic.lua index b4b7218..9a131bd 100644 --- a/lua/basic.lua +++ b/lua/basic.lua @@ -28,7 +28,7 @@ M.load_default_options = function() timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) title = true, -- set the title of window to the value of the titlestring -- opt.titlestring = "%<%F%=%l/%L - nvim" -- what the title of the window will be set to - undodir = undodir, -- set an undo directory + -- undodir = undodir, -- set an undo directory undofile = true, -- enable persistent undo updatetime = 100, -- faster completion writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited @@ -58,6 +58,7 @@ M.load_default_options = function() loaded_netrwPlugin = 1, -- set leaderkey to space mapleader = " ", + copilot_node_command = "~/.nodenv/versions/16.17.0/bin/node", } for k, v in pairs(let_options) do diff --git a/lua/keybindings.lua b/lua/keybindings.lua index 3cf0d4d..846a15a 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -50,6 +50,7 @@ wk.register({ r = { ":Telescope oldfiles", "Recent files" }, f = { ":Telescope file_browser", "File browser" }, n = { ":enew", "New file" }, + s = { ":Telescope live_grep", "Search in project" }, }, }) @@ -103,9 +104,10 @@ wk.register({ name = "+Buffer", k = { ":bd!", "Kill buffer" }, o = { ":BufferLineCloseRight:BufferLineCloseLeft", "Close other buffer" }, - b = { ":JABSOpen", "Open buffers" }, + b = { ":Telescope buffers", "Open buffers" }, n = { ":ls", "Buffer numbers" }, c = { ":noh", "Cancel highlight" }, + s = { ":lua require('spectre').open_file_search()", "Searching in buffer" }, }, }) -- change left and right tab diff --git a/lua/lsp/cmp.lua b/lua/lsp/cmp.lua index 8cdcbc5..d1720e9 100644 --- a/lua/lsp/cmp.lua +++ b/lua/lsp/cmp.lua @@ -19,6 +19,7 @@ cmp.setup({ }, -- 来源 sources = cmp.config.sources({ + { name = "orgmode" }, { name = "nvim_lsp" }, -- For vsnip users. -- { name = "vsnip" }, diff --git a/lua/lsp/config/lua.lua b/lua/lsp/config/lua.lua index f2970eb..e80ed7c 100644 --- a/lua/lsp/config/lua.lua +++ b/lua/lsp/config/lua.lua @@ -4,56 +4,56 @@ table.insert(runtime_path, "lua/?.lua") table.insert(runtime_path, "lua/?/init.lua") local opts = { - settings = { - Lua = { - runtime = { - -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) - version = "LuaJIT", - -- Setup your lua path - path = runtime_path, - }, - diagnostics = { - -- Get the language server to recognize the `vim` global - globals = { "vim" }, - }, - workspace = { - -- Make the server aware of Neovim runtime files - library = vim.api.nvim_get_runtime_file("", true), - checkThirdParty = false, - }, - -- Do not send telemetry data containing a randomized but unique identifier - telemetry = { - enable = false, - }, - }, - }, - flags = { - debounce_text_changes = 150, - }, - on_attach = function(client, bufnr) - -- 禁用格式化功能,交给专门插件插件处理 - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false + settings = { + Lua = { + runtime = { + -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + version = "LuaJIT", + -- Setup your lua path + path = runtime_path, + }, + diagnostics = { + -- Get the language server to recognize the `vim` global + globals = { "vim" }, + }, + workspace = { + -- Make the server aware of Neovim runtime files + library = vim.api.nvim_get_runtime_file("", true), + checkThirdParty = false, + }, + -- Do not send telemetry data containing a randomized but unique identifier + telemetry = { + enable = false, + }, + }, + }, + flags = { + debounce_text_changes = 150, + }, + on_attach = function(client, bufnr) + -- 禁用格式化功能,交给专门插件插件处理 + client.server_capabilities.document_formatting = false + client.server_capabilities.document_range_formatting = false - -- local function buf_set_keymap(...) - -- vim.api.nvim_buf_set_keymap(bufnr, ...) - end - -- -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end - -- -- 绑定快捷键 - -- require("keybindings").mapLSP(buf_set_keymap) - -- end, + -- local function buf_set_keymap(...) + -- vim.api.nvim_buf_set_keymap(bufnr, ...) + end, + -- -- local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end + -- -- 绑定快捷键 + -- require("keybindings").mapLSP(buf_set_keymap) + -- end, } local capabilities = vim.lsp.protocol.make_client_capabilities() -capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities) +capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) opts.capabilities = capabilities -- 查看目录等信息 -- print(vim.inspect(server)) return { - on_setup = function(server) - -- opts = require("lua-dev").setup({ lspconfig = opts }) - server.setup(opts) - end, + on_setup = function(server) + -- opts = require("lua-dev").setup({ lspconfig = opts }) + server.setup(opts) + end, } diff --git a/lua/plugin-config/buffer_line.lua b/lua/plugin-config/buffer_line.lua new file mode 100644 index 0000000..2c5be00 --- /dev/null +++ b/lua/plugin-config/buffer_line.lua @@ -0,0 +1,3 @@ +require("bufferline").setup({ + options = {}, +}) diff --git a/lua/plugin-config/bufferline.lua b/lua/plugin-config/bufferline.lua deleted file mode 100644 index 14b3e4a..0000000 --- a/lua/plugin-config/bufferline.lua +++ /dev/null @@ -1,4 +0,0 @@ -require("bufferline").setup { - options = { - } -} diff --git a/lua/plugin-config/cmake_tool.lua b/lua/plugin-config/cmake_tool.lua new file mode 100644 index 0000000..d13d872 --- /dev/null +++ b/lua/plugin-config/cmake_tool.lua @@ -0,0 +1,11 @@ +require("cmake-tools").setup({ + cmake_command = "cmake", + cmake_build_directory = "build", + cmake_build_type = "Debug", + cmake_generate_options = { "-D", "CMAKE_EXPORT_COMPILE_COMMANDS=1" }, + cmake_build_options = {}, + cmake_console_size = 10, -- cmake output window height + cmake_show_console = "always", -- "always", "only_on_error" + cmake_dap_configuration = { name = "cpp", type = "codelldb", request = "launch" }, -- dap configuration, optional + cmake_dap_open_command = require("dap").repl.open, -- optional +}) diff --git a/lua/plugin-config/coderunner.lua b/lua/plugin-config/coderunner.lua index d65c487..fae7f30 100644 --- a/lua/plugin-config/coderunner.lua +++ b/lua/plugin-config/coderunner.lua @@ -3,5 +3,6 @@ require("code_runner").setup({ filetype = { c = "cd $dir && gcc $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt", cpp = "cd $dir && g++ $fileName -o $fileNameWithoutExt -g && $dir/$fileNameWithoutExt", + go = "cd $dir && go run $fileName", }, }) diff --git a/lua/plugin-config/dashboard.lua b/lua/plugin-config/dashboard.lua index f55f7f3..5209709 100644 --- a/lua/plugin-config/dashboard.lua +++ b/lua/plugin-config/dashboard.lua @@ -1 +1,38 @@ -local db = require('dashboard') +local db = require("dashboard") +db.custom_header = { + "", + "┳┻| ", + "┻┳| ", + "┳┻|ヘ ∧ ", + "┻┳| ● w ● )", + "┳┻|⊂ノ ", + "┻┳|J ", + "", +} + +db.custom_center = { + { + icon = " ", + desc = "Find File ", + action = "Telescope find_files find_command=rg,--hidden,--files", + shortcut = " f", + }, + { + icon = " ", + desc = "Recently opened files ", + action = "Telescope oldfiles", + shortcut = "SPC f r", + }, + { + icon = " ", + desc = "Open Project ", + action = "Telescope Project ", + shortcut = "SPC f p", + }, + { + icon = " ", + desc = "File Browser ", + action = "Telescope file_browser", + shortcut = "SPC f f", + }, +} diff --git a/lua/plugin-config/hop.lua b/lua/plugin-config/hop.lua new file mode 100644 index 0000000..8f51e41 --- /dev/null +++ b/lua/plugin-config/hop.lua @@ -0,0 +1,14 @@ +require("hop").setup({}) +--- place this in one of your configuration file(s) +local hop = require("hop") +local directions = require("hop.hint").HintDirection +vim.keymap.set("", "f", function() + hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true }) +end, { remap = true }) +vim.keymap.set("", "F", function() + hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) +end, { remap = true }) + +vim.keymap.set("", "t", function() + hop.hint_char1({ direction = directions.AFTER_CURSOR, current_line_only = true, hint_offset = 0 }) +end, { remap = true }) diff --git a/lua/plugin-config/indent-blankline.lua b/lua/plugin-config/indent-blankline.lua new file mode 100644 index 0000000..4cd0d5e --- /dev/null +++ b/lua/plugin-config/indent-blankline.lua @@ -0,0 +1,7 @@ +require("indent_blankline").setup({ + -- for example, context is off by default, use this to turn it on + show_current_context = true, + indent_blankline_use_treesitter = true, + indent_blankline_use_treesitter_scope = true, + indent_blankline_char = "¦", +}) diff --git a/lua/plugin-config/lualine.lua b/lua/plugin-config/lua_line.lua similarity index 96% rename from lua/plugin-config/lualine.lua rename to lua/plugin-config/lua_line.lua index 402f186..b1960d4 100644 --- a/lua/plugin-config/lualine.lua +++ b/lua/plugin-config/lua_line.lua @@ -36,5 +36,5 @@ require("lualine").setup({ tabline = {}, winbar = {}, inactive_winbar = {}, - extensions = {}, + extensions = { "quickfix" }, }) diff --git a/lua/plugin-config/neoscroll.lua b/lua/plugin-config/neoscroll.lua new file mode 100644 index 0000000..aa0de75 --- /dev/null +++ b/lua/plugin-config/neoscroll.lua @@ -0,0 +1,12 @@ +require("neoscroll").setup({ + -- All these keys will be mapped to their corresponding default scrolling animation + mappings = { "", "", "", "", "", "", "zt", "zz", "zb" }, + hide_cursor = true, -- Hide cursor while scrolling + stop_eof = true, -- Stop at when scrolling downwards + respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file + cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further + easing_function = nil, -- Default easing function + pre_hook = nil, -- Function to run before the scrolling animation starts + post_hook = nil, -- Function to run after the scrolling animation ends + performance_mode = false, -- Disable "Performance Mode" on all buffers. +}) diff --git a/lua/plugin-config/orgmode.lua b/lua/plugin-config/orgmode.lua new file mode 100644 index 0000000..c27b5c9 --- /dev/null +++ b/lua/plugin-config/orgmode.lua @@ -0,0 +1,13 @@ +-- Load custom tree-sitter grammar for org filetype +require("orgmode").setup() +require("orgmode").setup_ts_grammar() + +-- Tree-sitter configuration +require("nvim-treesitter.configs").setup({ + -- If TS highlights are not enabled at all, or disabled via `disable` prop, highlighting will fallback to default Vim syntax highlighting + highlight = { + enable = true, + additional_vim_regex_highlighting = { "org" }, -- Required for spellcheck, some LaTex highlights and code block highlights that do not have ts grammar + }, + ensure_installed = { "org" }, -- Or run :TSUpdate org +}) diff --git a/lua/plugin-config/spectre.lua b/lua/plugin-config/spectre.lua new file mode 100644 index 0000000..36d7999 --- /dev/null +++ b/lua/plugin-config/spectre.lua @@ -0,0 +1 @@ +require("spectre").setup({}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 3d5f1f5..368386a 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -27,9 +27,14 @@ return require("packer").startup(function() -- 一个好的nvim内终端 use({ "akinsho/toggleterm.nvim", tag = "*" }) - -- git plugin like magit - -- 类似magit的插件neogit - -- use({ "TimUntersberger/neogit", requires = "nvim-lua/plenary.nvim" }) + -- chrome intergration + -- 浏览器集成 + -- use({ + -- "glacambre/firenvim", + -- run = function() + -- vim.fn["firenvim#install"](0) + -- end, + -- }) -- lazygit support -- 使用lazygit接口 @@ -46,6 +51,14 @@ return require("packer").startup(function() -- 优化markdown添加表格 use("dhruvasagar/vim-table-mode") + -- nvim-markdown + -- markdown 增强 + use("ixru/nvim-markdown") + + -- orgmode support + -- orgmode 支持 + use({ "nvim-orgmode/orgmode" }) + -- nvim-tree for file manage use({ "kyazdani42/nvim-tree.lua", @@ -56,12 +69,16 @@ return require("packer").startup(function() -- vim 开始界面 use({ "glepnir/dashboard-nvim" }) + -- smooth neovim scroll + -- 顺滑的neovim滚动 + use("karb94/neoscroll.nvim") + -- bufferline on the top -- 顶部状态栏 use({ "akinsho/bufferline.nvim", requires = "kyazdani42/nvim-web-devicons" }) -- 更方便的切换buffer - use({ "matbme/JABS.nvim" }) + -- use({ "matbme/JABS.nvim" }) -- treesitter use({ @@ -92,11 +109,24 @@ return require("packer").startup(function() "folke/which-key.nvim", }) + --------------------- buffer related ----------------- + -- search and replace + use("windwp/nvim-spectre") + + -- indent-blankline + -- 竖向加竖线显示对齐 + use({ "lukas-reineke/indent-blankline.nvim" }) -- comment use({ "numToStr/Comment.nvim", }) + -- hop plugin + -- 快速跳转 + use({ + "phaazon/hop.nvim", + branch = "v2", -- optional but strongly recommended + }) -- lualine for bottom stausline -- 底部状态栏 use({ @@ -120,6 +150,10 @@ return require("packer").startup(function() -- 代码运行 use({ "CRAG666/code_runner.nvim", requires = "nvim-lua/plenary.nvim" }) + -- cmake support + -- cmake 支持 + use("Civitasv/cmake-tools.nvim") + ------------------- lsp -------------------------- -- mason for lsp dap linter and others use({ @@ -158,6 +192,8 @@ return require("packer").startup(function() use("rafamadriz/friendly-snippets") -- UI 增强 use("onsails/lspkind-nvim") + -- copilot 增强 + use("github/copilot.vim") ------------------- dap ----------------------- -- dap for neovim diff --git a/readme.md b/readme.md index 761611c..5b21026 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,7 @@ | \S | 保存所有文件 | | \ | 切换回上一个buffer,用于两buffer间来回切换 | | , | 运行当前文件代码,需要自行配置各种语言 | +| Ctrl-\\ | 打开终端 | ### Packer | key | function | @@ -76,15 +77,36 @@ | \ | step over | ### buffer -| key | function | -|-------------|----------------| -| \bb | 打开某个buffer | -| \bk | 关闭当前buffer | +| key | function | +|-------------|--------------------------------| +| \bb | 打开某个buffer | +| \bk | 关闭当前buffer | +| \bc | 取消高亮(可用于搜索后取消高亮) | +| \bo | 关闭其他buffer | + +### window +| key | function | +|-------------------|--------------------| +| \wo | 关闭其他窗口 | +| \wd | 关闭当前窗口 | +| \wh,j,k,l | 切换其他方向的窗口 | +| \ws | 水平分割窗口 | + + +### file +| key | function | +|-------------|------------------------| +| \ff | telescope 文件浏览 | +| \fr | 最近打开的文件 | +| \fs | 在项目文件中搜索字符串 | +| \fp | 打开项目 | ## 问题 - ### 根据文件类型启动某些功能 -可以在ftplugin文件夹中放入对应文件类型的lua文件,如markdown.lua对应markdown文件.写入要执行的命令即可.例子可见ftplugin/markdown中启动markdown table mode +可以在ftplugin文件夹中放入对应文件类型的lua文件,如markdown.lua对应markdown文件.写入要执行的命令即可.例子可见ftplugin/markdown中启动markdown table mode() + + +