diff --git a/.luarc.json b/.luarc.json deleted file mode 100644 index e34fdba..0000000 --- a/.luarc.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", - "Lua.diagnostics.globals": [ - "vim", - "use" - ] -} \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6f0591a --- /dev/null +++ b/init.lua @@ -0,0 +1,29 @@ +-- 基础设置 +require('basic') + +-- 快捷键映射 +require("keybindings") + +-- Packer 插件管理 +require("plugins") + +-- 主题设置 +require("colorscheme") + +-- 插件配置 +require("plugin-config.nvim-tree") + +require("plugin-config.bufferline") + +require("plugin-config.lualine") + +require("plugin-config.telescope") + +require("plugin-config.dashboard") + +require("plugin-config.project") + +require("plugin-config.nvim-treesitter") -- (新增) + +-- 内置LSP (新增) +require("lsp.setup") diff --git a/init.vim b/init.vim deleted file mode 100644 index c481bce..0000000 --- a/init.vim +++ /dev/null @@ -1,11 +0,0 @@ -lua require('basic') -lua require('keybindings') -lua require('plugins') - -" 插件配置 -lua require('plugin-config/nvim-tree') -lua require('plugin-config/nvim-treesitter') -lua require('lsp/setup') - -set background=dark -colorscheme nord diff --git a/lua/basic.lua b/lua/basic.lua index 0143b96..9f929f3 100644 --- a/lua/basic.lua +++ b/lua/basic.lua @@ -1,7 +1,7 @@ -- utf8 vim.g.encoding = "UTF-8" vim.o.fileencoding = 'utf-8' --- jk移动时光标下上方保留8行 +-- jkhl 移动时光标周围保留8行 vim.o.scrolloff = 8 vim.o.sidescrolloff = 8 -- 使用相对行号 @@ -21,9 +21,10 @@ vim.o.shiftround = true -- >> << 时移动长度 vim.o.shiftwidth = 2 vim.bo.shiftwidth = 2 --- 新行对齐当前行,空格替代tab +-- 空格替代tab vim.o.expandtab = true vim.bo.expandtab = true +-- 新行对齐当前行 vim.o.autoindent = true vim.bo.autoindent = true vim.o.smartindent = true @@ -34,18 +35,15 @@ vim.o.smartcase = true vim.o.hlsearch = false -- 边输入边搜索 vim.o.incsearch = true --- 使用增强状态栏后不再需要 vim 的模式提示 -vim.o.showmode = false -- 命令行高为2,提供足够的显示空间 vim.o.cmdheight = 2 -- 当文件被外部程序修改时,自动加载 vim.o.autoread = true vim.bo.autoread = true -- 禁止折行 -vim.o.wrap = false vim.wo.wrap = false --- 行结尾可以跳到下一行 -vim.o.whichwrap = 'b,s,<,>,[,],h,l' +-- 光标在行首尾时可以跳到下一行 +vim.o.whichwrap = '<,>,[,]' -- 允许隐藏被修改过的buffer vim.o.hidden = true -- 鼠标支持 @@ -56,9 +54,8 @@ vim.o.writebackup = false vim.o.swapfile = false -- smaller updatetime vim.o.updatetime = 300 --- 设置 timeoutlen 为等待键盘快捷键连击时间200毫秒,可根据需要设置 --- 遇到问题详见:https://github.com/nshen/learn-neovim-lua/issues/1 -vim.o.timeoutlen = 200 +-- 设置 timeoutlen 为等待键盘快捷键连击时间500毫秒,可根据需要设置 +vim.o.timeoutlen = 500 -- split window 从下边和右边出现 vim.o.splitbelow = true vim.o.splitright = true @@ -75,6 +72,9 @@ vim.o.listchars = "space:·" vim.o.wildmenu = true -- Dont' pass messages to |ins-completin menu| vim.o.shortmess = vim.o.shortmess .. 'c' +-- 补全最多显示10行 vim.o.pumheight = 10 --- always show tabline +-- 永远显示 tabline vim.o.showtabline = 2 +-- 使用增强状态栏插件后不再需要 vim 的模式提示 +vim.o.showmode = false diff --git a/lua/colorscheme.lua b/lua/colorscheme.lua new file mode 100644 index 0000000..48f656e --- /dev/null +++ b/lua/colorscheme.lua @@ -0,0 +1,6 @@ +local colorscheme = "tokyonight" +local status_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not status_ok then + vim.notify("colorscheme " .. colorscheme .. " 没有找到!") + return +end diff --git a/lua/keybindings.lua b/lua/keybindings.lua index d3321b2..297f121 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -1,53 +1,165 @@ vim.g.mapleader = " " vim.g.maplocalleader = " " + local map = vim.api.nvim_set_keymap +-- 复用 opt 参数 local opt = {noremap = true, silent = true } -map("n", "", "9k", opt) -map("n", "", "9j", opt) - --- map('v', '<', '', '>gv', opt) - - +-- 取消 s 默认功能 +map("n", "s", "", opt) +-- windows 分屏快捷键 map("n", "sv", ":vsp", opt) map("n", "sh", ":sp", opt) +-- 关闭当前 map("n", "sc", "c", opt) -map("n", "so", "o", opt) -- close others - +-- 关闭其他 +map("n", "so", "o", opt) +-- Alt + hjkl 窗口之间跳转 map("n", "", "h", opt) map("n", "", "j", opt) map("n", "", "k", opt) map("n", "", "l", opt) --- nvimTree -map('n', 'ct', ':NvimTreeToggle', opt) + +-- 左右比例控制 +map("n", "", ":vertical resize -2", opt) +map("n", "", ":vertical resize +2", opt) +map("n", "s,", ":vertical resize -20", opt) +map("n", "s.", ":vertical resize +20", opt) +-- 上下比例 +map("n", "sj", ":resize +10", opt) +map("n", "sk", ":resize -10", opt) +map("n", "", ":resize +2", opt) +map("n", "", ":resize -2", opt) +-- 等比例 +map("n", "s=", "=", opt) +-- Terminal相关 +map("n", "t", ":sp | terminal", opt) +map("n", "vt", ":vsp | terminal", opt) +map("t", "", "", opt) +map("t", "", [[ h ]], opt) +map("t", "", [[ j ]], opt) +map("t", "", [[ k ]], opt) +map("t", "", [[ l ]], opt) + + +-- visual模式下缩进代码 +map("v", "<", "", ">gv", opt) +-- 上下移动选中文本 +map("v", "J", ":move '>+1gv-gv", opt) +map("v", "K", ":move '<-2gv-gv", opt) + + +-- 上下滚动浏览 +map("n", "", "4j", opt) +map("n", "", "4k", opt) +-- ctrl u / ctrl + d 只移动9行,默认移动半屏 +map("n", "", "9k", opt) +map("n", "", "9j", opt) + +-- 在visual 模式里粘贴不要复制 +map("v", "p", '"_dP', opt) + +-- 退出 +map("n", "q", ":q", opt) +map("n", "qq", ":q!", opt) +map("n", "Q", ":qa!", opt) + +-- insert 模式下,跳到行首行尾 +map("i", "", "I", opt) +map("i", "", "A", opt) + + +-- bufferline +-- 左右Tab切换 +map("n", "", ":BufferLineCyclePrev", opt) +map("n", "", ":BufferLineCycleNext", opt) +-- 关闭 +--"moll/vim-bbye" +map("n", "", ":Bdelete!", opt) +map("n", "bl", ":BufferLineCloseRight", opt) +map("n", "bh", ":BufferLineCloseLeft", opt) +map("n", "bc", ":BufferLinePickClose", opt) + + +-- Telescope +-- 查找文件 +map("n", "", ":Telescope find_files", opt) +-- 全局搜索 +map("n", "", ":Telescope live_grep", opt) + +-- 插件快捷键 local pluginKeys = {} +-- nvim-tree +-- alt + m 键打开关闭tree +map("n", "", ":NvimTreeToggle", opt) +-- 列表快捷键 +pluginKeys.nvimTreeList = { + -- 打开文件或文件夹 + { key = {"", "o", "<2-LeftMouse>"}, action = "edit" }, + -- 分屏打开文件 + { key = "v", action = "vsplit" }, + { key = "h", action = "split" }, + -- 显示隐藏文件 + { key = "i", action = "toggle_custom" }, -- 对应 filters 中的 custom (node_modules) + { key = ".", action = "toggle_dotfiles" }, -- Hide (dotfiles) + -- 文件操作 + { key = "", action = "refresh" }, + { key = "a", action = "create" }, + { key = "d", action = "remove" }, + { key = "r", action = "rename" }, + { key = "x", action = "cut" }, + { key = "c", action = "copy" }, + { key = "p", action = "paste" }, + { key = "s", action = "system_open" }, +} + + +-- Telescope 列表中 插入模式快捷键 +pluginKeys.telescopeList = { + i = { + -- 上下移动 + [""] = "move_selection_next", + [""] = "move_selection_previous", + [""] = "move_selection_next", + [""] = "move_selection_previous", + -- 历史记录 + [""] = "cycle_history_next", + [""] = "cycle_history_prev", + -- 关闭窗口 + [""] = "close", + -- 预览窗口上下滚动 + [""] = "preview_scrolling_up", + [""] = "preview_scrolling_down", + }, +} + -- lsp 回调函数快捷键设置 -pluginKeys.maplsp = function(mapbuf) +pluginKeys.mapLSP = function(mapbuf) -- rename - mapbuf('n', 'rn', 'lua vim.lsp.buf.rename()', opt) + mapbuf("n", "rn", "lua vim.lsp.buf.rename()", opt) -- code action - mapbuf('n', 'ca', 'lua vim.lsp.buf.code_action()', opt) + mapbuf("n", "ca", "lua vim.lsp.buf.code_action()", opt) -- go xx - mapbuf('n', 'gd', 'lua vim.lsp.buf.definition()', opt) - mapbuf('n', 'gh', 'lua vim.lsp.buf.hover()', opt) - mapbuf('n', 'gD', 'lua vim.lsp.buf.declaration()', opt) - mapbuf('n', 'gi', 'lua vim.lsp.buf.implementation()', opt) - mapbuf('n', 'gr', 'lua vim.lsp.buf.references()', opt) + mapbuf("n", "gd", "lua vim.lsp.buf.definition()", opt) + mapbuf("n", "gh", "lua vim.lsp.buf.hover()", opt) + mapbuf("n", "gD", "lua vim.lsp.buf.declaration()", opt) + mapbuf("n", "gi", "lua vim.lsp.buf.implementation()", opt) + mapbuf("n", "gr", "lua vim.lsp.buf.references()", opt) -- diagnostic - mapbuf('n', 'go', 'lua vim.diagnostic.open_float()', opt) - mapbuf('n', 'gp', 'lua vim.diagnostic.goto_prev()', opt) - mapbuf('n', 'gn', 'lua vim.diagnostic.goto_next()', opt) + mapbuf("n", "gp", "lua vim.diagnostic.open_float()", opt) + mapbuf("n", "gk", "lua vim.diagnostic.goto_prev()", opt) + mapbuf("n", "gj", "lua vim.diagnostic.goto_next()", opt) + mapbuf("n", "f", "lua vim.lsp.buf.formatting()", opt) + -- 没用到 -- mapbuf('n', 'q', 'lua vim.diagnostic.setloclist()', opt) - -- leader + = - mapbuf('n', '=', 'lua vim.lsp.buf.formatting()', opt) - -- mapbuf('n', '', 'lua vim.lsp.buf.signature_help()', opt) + -- mapbuf("n", "", "lua vim.lsp.buf.signature_help()", opt) -- mapbuf('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opt) -- mapbuf('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opt) -- mapbuf('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opt) diff --git a/lua/lsp/clangd.lua b/lua/lsp/clangd.lua deleted file mode 100644 index 8b13789..0000000 --- a/lua/lsp/clangd.lua +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lua/lsp/config/lua.lua b/lua/lsp/config/lua.lua new file mode 100644 index 0000000..9ba3beb --- /dev/null +++ b/lua/lsp/config/lua.lua @@ -0,0 +1,54 @@ +-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua +local runtime_path = vim.split(package.path, ';') +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.resolved_capabilities.document_formatting = false + client.resolved_capabilities.document_range_formatting = false + + local function buf_set_keymap(...) + vim.api.nvim_buf_set_keymap(bufnr, ...) + end + + -- 绑定快捷键 + require('keybindings').mapLSP(buf_set_keymap) + -- 保存时自动格式化 + -- vim.cmd('autocmd BufWritePre lua vim.lsp.buf.formatting_sync()') + end, +} + +-- 查看目录等信息 +return { + on_setup = function(server) + server:setup(opts) + end, +} diff --git a/lua/lsp/lua.lua b/lua/lsp/lua.lua deleted file mode 100644 index e69de29..0000000 diff --git a/lua/lsp/setup.lua b/lua/lsp/setup.lua index c2ca1ad..bbf362b 100644 --- a/lua/lsp/setup.lua +++ b/lua/lsp/setup.lua @@ -1,14 +1,14 @@ -local lsp_installer = require "nvim-lsp-installer" +local lsp_installer = require("nvim-lsp-installer") -- 安装列表 --- https://github.com/williamboman/nvim-lsp-installer#available-lsps -- { key: 语言 value: 配置文件 } +-- key 必须为下列网址列出的名称 +-- https://github.com/williamboman/nvim-lsp-installer#available-lsps local servers = { - sumneko_lua = require "lsp.lua", -- /lua/lsp/lua.lua - clangd = require "lsp.lua" -- /lua/lsp/clangd.lua + sumneko_lua = require("lsp.config.lua"), -- lua/lsp/config/lua.lua + clangd = require("lsp.config.lua"), } - --- 自动安装 LanguageServers +-- 自动安装 Language Servers for name, _ in pairs(servers) do local server_is_found, server = lsp_installer.get_server(name) if server_is_found then @@ -19,20 +19,14 @@ for name, _ in pairs(servers) do end end - lsp_installer.on_server_ready(function(server) - local opts = servers[server.name] - if opts then - opts.on_attach = function(_, bufnr) - 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 - opts.flags = { - debounce_text_changes = 150, - } - server:setup(opts) + local config = servers[server.name] + if config == nil then + return + end + if config.on_setup then + config.on_setup(server) + else + server:setup({}) end end) - diff --git a/lua/plugin-config/bufferline.lua b/lua/plugin-config/bufferline.lua new file mode 100644 index 0000000..d77f9eb --- /dev/null +++ b/lua/plugin-config/bufferline.lua @@ -0,0 +1,37 @@ +local status, bufferline = pcall(require, "bufferline") +if not status then + vim.notify("没有找到 bufferline") + return +end + +-- bufferline 配置 +-- https://github.com/akinsho/bufferline.nvim#configuration +bufferline.setup({ + options = { + -- 关闭 Tab 的命令,这里使用 moll/vim-bbye 的 :Bdelete 命令 + close_command = "Bdelete! %d", + right_mouse_command = "Bdelete! %d", + -- 侧边栏配置 + -- 左侧让出 nvim-tree 的位置,显示文字 File Explorer + offsets = { + { + filetype = "NvimTree", + text = "File Explorer", + highlight = "Directory", + text_align = "left", + }, + }, + -- 使用 nvim 内置 LSP 后续课程会配置 + diagnostics = "nvim_lsp", + -- 可选,显示 LSP 报错图标 + ---@diagnostic disable-next-line: unused-local + diagnostics_indicator = function(count, level, diagnostics_dict, context) + local s = " " + for e, n in pairs(diagnostics_dict) do + local sym = e == "error" and " " or (e == "warning" and " " or "") + s = s .. n .. sym + end + return s + end, + }, +}) diff --git a/lua/plugin-config/dashboard.lua b/lua/plugin-config/dashboard.lua new file mode 100644 index 0000000..30cb2c5 --- /dev/null +++ b/lua/plugin-config/dashboard.lua @@ -0,0 +1,73 @@ +local status, db = pcall(require, "dashboard") +if not status then + vim.notify("没有找到 dashboard") + return +end + +db.custom_footer = { + "", + "", + "https://github.com/nshen/learn-neovim-lua", +} + +db.custom_center = { + { + icon = " ", + desc = "Projects ", + action = "Telescope projects", + }, + { + icon = " ", + desc = "Recently files ", + action = "Telescope oldfiles", + }, + { + icon = " ", + desc = "Edit keybindings ", + action = "edit ~/.config/nvim/lua/keybindings.lua", + }, + { + icon = " ", + desc = "Edit Projects ", + action = "edit ~/.local/share/nvim/project_nvim/project_history", + }, + -- { + -- icon = " ", + -- desc = "Edit .bashrc ", + -- action = "edit ~/.bashrc", + -- }, + -- { + -- icon = " ", + -- desc = "Change colorscheme ", + -- action = "ChangeColorScheme", + -- }, + -- { + -- icon = " ", + -- desc = "Edit init.lua ", + -- action = "edit ~/.config/nvim/init.lua", + -- }, + -- { + -- icon = " ", + -- desc = "Find file ", + -- action = "Telescope find_files", + -- }, + -- { + -- icon = " ", + -- desc = "Find text ", + -- action = "Telescopecope live_grep", + -- }, +} + + +db.custom_header = { + [[ ▀████▀▄▄ ▄█ ]], + [[ █▀ ▀▀▄▄▄▄▄ ▄▄▀▀█ ]], + [[ ▄ █ ▀▀▀▀▄ ▄▀ ]], + [[ ▄▀ ▀▄ ▀▄ ▀▄▀ ]], + [[ ▄▀ █ █▀ ▄█▀▄ ▄█ ]], + [[ ▀▄ ▀▄ █ ▀██▀ ██▄█ ]], + [[ ▀▄ ▄▀ █ ▄██▄ ▄ ▄ ▀▀ █ ]], + [[ █ ▄▀ █ ▀██▀ ▀▀ ▀▀ ▄▀ ]], + [[ █ █ █ ▄▄ ▄▀ ]], +} + diff --git a/lua/plugin-config/lualine.lua b/lua/plugin-config/lualine.lua new file mode 100644 index 0000000..32bc94a --- /dev/null +++ b/lua/plugin-config/lualine.lua @@ -0,0 +1,43 @@ +-- 如果找不到lualine 组件,就不继续执行 +local status, lualine = pcall(require, "lualine") +if not status then + vim.notify("没有找到 lualine") + return +end + +lualine.setup({ + options = { + theme = "tokyonight", + component_separators = { left = "|", right = "|" }, + -- https://github.com/ryanoasis/powerline-extra-symbols + section_separators = { left = " ", right = "" }, + }, + extensions = { "nvim-tree", "toggleterm" }, + sections = { + lualine_c = { + "filename", + { + "lsp_progress", + spinner_symbols = { " ", " ", " ", " ", " ", " " }, + }, + }, + lualine_x = { + "filesize", + { + "fileformat", + -- symbols = { + -- unix = '', -- e712 + -- dos = '', -- e70f + -- mac = '', -- e711 + -- }, + symbols = { + unix = "LF", + dos = "CRLF", + mac = "CR", + }, + }, + "encoding", + "filetype", + }, + }, +}) diff --git a/lua/plugin-config/nvim-tree.lua b/lua/plugin-config/nvim-tree.lua index f6a01cc..7f2fe34 100644 --- a/lua/plugin-config/nvim-tree.lua +++ b/lua/plugin-config/nvim-tree.lua @@ -1,7 +1,67 @@ -require'nvim-tree'.setup { +local status, nvim_tree = pcall(require, "nvim-tree") +if not status then + vim.notify("没有找到 nvim-tree") + return +end + +-- 列表操作快捷键 +local list_keys = require('keybindings').nvimTreeList +nvim_tree.setup({ -- 不显示 git 状态图标 git = { - enable = false - } -} + enable = false, + }, + -- project plugin 需要这样设置 + update_cwd = true, + update_focused_file = { + enable = true, + update_cwd = true, + }, + -- 隐藏 .文件 和 node_modules 文件夹 + filters = { + dotfiles = true, + custom = { 'node_modules' }, + }, + view = { + -- 宽度 + width = 40, + -- 也可以 'right' + side = 'left', + -- 隐藏根目录 + hide_root_folder = false, + -- 自定义列表中快捷键 + mappings = { + custom_only = false, + list = list_keys, + }, + -- 不显示行数 + number = false, + relativenumber = false, + -- 显示图标 + signcolumn = 'yes', + }, + actions = { + open_file = { + -- 首次打开大小适配 + resize_window = true, + -- 打开文件时关闭 + quit_on_open = true, + }, + }, + -- wsl install -g wsl-open + -- https://github.com/4U6U57/wsl-open/ + system_open = { + cmd = 'wsl-open', -- mac 直接设置为 open + }, + -- project plugin 需要这样设置 + update_cwd = true, + update_focused_file = { + enable = true, + update_cwd = true, + }, +}) +-- 自动关闭 +vim.cmd([[ + autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif +]]) diff --git a/lua/plugin-config/nvim-treesitter.lua b/lua/plugin-config/nvim-treesitter.lua index edd9ad4..635d73f 100644 --- a/lua/plugin-config/nvim-treesitter.lua +++ b/lua/plugin-config/nvim-treesitter.lua @@ -1,30 +1,16 @@ -require'nvim-treesitter.configs'.setup { +local status, treesitter = pcall(require, "nvim-treesitter.configs") +if not status then + vim.notify("没有找到 nvim-treesitter") + return +end + +treesitter.setup({ -- 安装 language parser -- :TSInstallInfo 命令查看支持的语言 - ensure_installed = {"html", "css", "lua", "javascript", "typescript", "tsx", "cpp", "c"}, - -- 启用代码高亮功能 + ensure_installed = { "cpp", "c", "json", "html", "css", "vim", "lua", "javascript", "typescript", "tsx" }, + -- 启用代码高亮模块 highlight = { enable = true, - additional_vim_regex_highlighting = false + additional_vim_regex_highlighting = false, }, - -- 启用增量选择 - incremental_selection = { - enable = true, - keymaps = { - init_selection = '', - node_incremental = '', - node_decremental = '', - scope_incremental = '', - } - }, - -- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature. - indent = { - enable = true - } -} --- 开启 Folding -vim.wo.foldmethod = 'expr' -vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' --- 默认不要折叠 --- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file -vim.wo.foldlevel = 99 +}) diff --git a/lua/plugin-config/project.lua b/lua/plugin-config/project.lua new file mode 100644 index 0000000..8315380 --- /dev/null +++ b/lua/plugin-config/project.lua @@ -0,0 +1,20 @@ +local status, project = pcall(require, "project_nvim") +if not status then + vim.notify("没有找到 project_nvim") + return +end + +-- nvim-tree 支持 +vim.g.nvim_tree_respect_buf_cwd = 1 + +project.setup({ + detection_methods = { "pattern" }, + patterns = { ".git", "_darcs", ".hg", ".bzr", ".svn", "Makefile", "package.json", ".sln" }, +}) + +local status, telescope = pcall(require, "telescope") +if not status then + vim.notify("没有找到 telescope") + return +end +pcall(telescope.load_extension, "projects") diff --git a/lua/plugin-config/telescope.lua b/lua/plugin-config/telescope.lua new file mode 100644 index 0000000..eb34b66 --- /dev/null +++ b/lua/plugin-config/telescope.lua @@ -0,0 +1,24 @@ +local status, telescope = pcall(require, "telescope") +if not status then + vim.notify("没有找到 telescope") + return +end + +telescope.setup({ + defaults = { + -- 打开弹窗后进入的初始模式,默认为 insert,也可以是 normal + initial_mode = "insert", + -- 窗口内快捷键 + mappings = require("keybindings").telescopeList, + }, + pickers = { + -- 内置 pickers 配置 + find_files = { + -- 查找文件换皮肤,支持的参数有: dropdown, cursor, ivy + -- theme = "dropdown", + } + }, + extensions = { + -- 扩展插件配置 + }, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index 151b80d..6306ef9 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -1,32 +1,69 @@ -return require('packer').startup(function() - -- Packer can manage itself +local packer = require("packer") +packer.startup({ + function(use) + -- Packer 可以管理自己本身 use 'wbthomason/packer.nvim' - -- gruvbox theme - use { - "ellisonleao/gruvbox.nvim", - requires = {"rktjmp/lush.nvim"} - } - use 'shaunsingh/nord.nvim' - use 'glepnir/zephyr-nvim' + -- 你的插件列表... + -- nvim-tree (新增) - use { - 'kyazdani42/nvim-tree.lua', - requires = 'kyazdani42/nvim-web-devicons' - } - -- treesitter - use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } - -- lspconfig - use {'neovim/nvim-lspconfig', 'williamboman/nvim-lsp-installer'} - -- nvim-cmp - use 'hrsh7th/cmp-nvim-lsp' -- { name = nvim_lsp } - use 'hrsh7th/cmp-buffer' -- { name = 'buffer' }, - use 'hrsh7th/cmp-path' -- { name = 'path' } - use 'hrsh7th/cmp-cmdline' -- { name = 'cmdline' } - use 'hrsh7th/nvim-cmp' - -- vsnip - use 'hrsh7th/cmp-vsnip' -- { name = 'vsnip' } - use 'hrsh7th/vim-vsnip' - use 'rafamadriz/friendly-snippets' - -- lspkind - use 'onsails/lspkind-nvim' -end) + use({ "kyazdani42/nvim-tree.lua", requires = "kyazdani42/nvim-web-devicons" }) + -- bufferline (新增) + use({ "akinsho/bufferline.nvim", requires = { "kyazdani42/nvim-web-devicons", "moll/vim-bbye" } }) + + -- lualine (新增) + use({ "nvim-lualine/lualine.nvim", requires = { "kyazdani42/nvim-web-devicons" } }) + use("arkav/lualine-lsp-progress") + + -- telescope (新增) + use { 'nvim-telescope/telescope.nvim', requires = { "nvim-lua/plenary.nvim" } } + + -- dashboard-nvim (新增) + use("glepnir/dashboard-nvim") + + -- project + use("ahmedkhalf/project.nvim") + + -- treesitter (新增) + use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" }) + + --------------------- LSP -------------------- + use("williamboman/nvim-lsp-installer") + -- Lspconfig + use({ "neovim/nvim-lspconfig" }) + + --------------------- colorschemes -------------------- + -- tokyonight + use("folke/tokyonight.nvim") + -- OceanicNext + use("mhartington/oceanic-next") + -- gruvbox + use({ "ellisonleao/gruvbox.nvim", requires = { "rktjmp/lush.nvim" } }) + -- zephyr 暂时不推荐,详见上边解释 + -- use("glepnir/zephyr-nvim") + -- nord + use("shaunsingh/nord.nvim") + -- onedark + use("ful1e5/onedark.nvim") + -- nightfox + use("EdenEast/nightfox.nvim") + ------------------------------------------------------- + end, + config = { + display = { + open_fn = function() + return require("packer.util").float({ border = "single" }) + end, + }, + } +}) + +-- 每次保存 plugins.lua 自动安装插件 +pcall( + vim.cmd, + [[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end + ]] +) diff --git a/plugin/packer_compiled.lua b/plugin/packer_compiled.lua index 56c3250..aaf5534 100644 --- a/plugin/packer_compiled.lua +++ b/plugin/packer_compiled.lua @@ -49,8 +49,8 @@ local function save_profiles(threshold) end time([[Luarocks path setup]], true) -local package_path_str = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" -local install_cpath_pattern = "/Users/yuhangq/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" +local package_path_str = "/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/share/lua/5.1/?/init.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?.lua;/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/luarocks/rocks-5.1/?/init.lua" +local install_cpath_pattern = "/Users/zxd/.cache/nvim/packer_hererocks/2.1.0-beta3/lib/lua/5.1/?.so" if not string.find(package.path, package_path_str, 1, true) then package.path = package.path .. ';' .. package_path_str end @@ -74,100 +74,110 @@ end time([[try_loadstring definition]], false) time([[Defining packer_plugins]], true) _G.packer_plugins = { - ["cmp-buffer"] = { + ["bufferline.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-buffer", - url = "https://github.com/hrsh7th/cmp-buffer" + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/bufferline.nvim", + url = "https://github.com/akinsho/bufferline.nvim" }, - ["cmp-cmdline"] = { + ["dashboard-nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-cmdline", - url = "https://github.com/hrsh7th/cmp-cmdline" - }, - ["cmp-nvim-lsp"] = { - loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-nvim-lsp", - url = "https://github.com/hrsh7th/cmp-nvim-lsp" - }, - ["cmp-path"] = { - loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-path", - url = "https://github.com/hrsh7th/cmp-path" - }, - ["cmp-vsnip"] = { - loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/cmp-vsnip", - url = "https://github.com/hrsh7th/cmp-vsnip" - }, - ["friendly-snippets"] = { - loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/friendly-snippets", - url = "https://github.com/rafamadriz/friendly-snippets" + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/dashboard-nvim", + url = "https://github.com/glepnir/dashboard-nvim" }, ["gruvbox.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/gruvbox.nvim", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/gruvbox.nvim", url = "https://github.com/ellisonleao/gruvbox.nvim" }, - ["lspkind-nvim"] = { + ["lualine-lsp-progress"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lspkind-nvim", - url = "https://github.com/onsails/lspkind-nvim" + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lualine-lsp-progress", + url = "https://github.com/arkav/lualine-lsp-progress" + }, + ["lualine.nvim"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lualine.nvim", + url = "https://github.com/nvim-lualine/lualine.nvim" }, ["lush.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/lush.nvim", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/lush.nvim", url = "https://github.com/rktjmp/lush.nvim" }, + ["nightfox.nvim"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nightfox.nvim", + url = "https://github.com/EdenEast/nightfox.nvim" + }, ["nord.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nord.nvim", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nord.nvim", url = "https://github.com/shaunsingh/nord.nvim" }, - ["nvim-cmp"] = { - loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-cmp", - url = "https://github.com/hrsh7th/nvim-cmp" - }, ["nvim-lsp-installer"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-lsp-installer", url = "https://github.com/williamboman/nvim-lsp-installer" }, ["nvim-lspconfig"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-lspconfig", url = "https://github.com/neovim/nvim-lspconfig" }, ["nvim-tree.lua"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-tree.lua", url = "https://github.com/kyazdani42/nvim-tree.lua" }, ["nvim-treesitter"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-treesitter", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-treesitter", url = "https://github.com/nvim-treesitter/nvim-treesitter" }, ["nvim-web-devicons"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/nvim-web-devicons", url = "https://github.com/kyazdani42/nvim-web-devicons" }, + ["oceanic-next"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/oceanic-next", + url = "https://github.com/mhartington/oceanic-next" + }, + ["onedark.nvim"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/onedark.nvim", + url = "https://github.com/ful1e5/onedark.nvim" + }, ["packer.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/packer.nvim", + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/packer.nvim", url = "https://github.com/wbthomason/packer.nvim" }, - ["vim-vsnip"] = { + ["plenary.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/vim-vsnip", - url = "https://github.com/hrsh7th/vim-vsnip" + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/plenary.nvim", + url = "https://github.com/nvim-lua/plenary.nvim" }, - ["zephyr-nvim"] = { + ["project.nvim"] = { loaded = true, - path = "/Users/yuhangq/.local/share/nvim/site/pack/packer/start/zephyr-nvim", - url = "https://github.com/glepnir/zephyr-nvim" + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/project.nvim", + url = "https://github.com/ahmedkhalf/project.nvim" + }, + ["telescope.nvim"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/telescope.nvim", + url = "https://github.com/nvim-telescope/telescope.nvim" + }, + ["tokyonight.nvim"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/tokyonight.nvim", + url = "https://github.com/folke/tokyonight.nvim" + }, + ["vim-bbye"] = { + loaded = true, + path = "/Users/zxd/.local/share/nvim/site/pack/packer/start/vim-bbye", + url = "https://github.com/moll/vim-bbye" } } diff --git a/test.cpp b/test.cpp deleted file mode 100644 index 1cc9a08..0000000 --- a/test.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -using namespace std; -int main() { - printf("Hello World!"); - for(int i=0; i<=10; i++) { - : - } -}