diff --git a/.gitignore b/.gitignore index 8cb205e..6a57896 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ plugin + +.DS_Store +snippets/go.json \ No newline at end of file diff --git a/ftplugin/markdown.lua b/ftplugin/markdown.lua index 1ab7de4..28e7cdb 100644 --- a/ftplugin/markdown.lua +++ b/ftplugin/markdown.lua @@ -1 +1 @@ -vim.cmd("TableModeEnable") +-- vim.cmd("TableModeEnable") diff --git a/init.lua b/init.lua index 0a2520e..dd9e664 100644 --- a/init.lua +++ b/init.lua @@ -14,7 +14,9 @@ require("plugin-config/mason") require("plugin-config/lua_line") require("plugin-config/notify") require("plugin-config/nvim-autopairs") +require("plugin-config/lua_snip") require("plugin-config/table-mode") +require("plugin-config/mkdnflow") require("plugin-config/orgmode") require("plugin-config/project") require("plugin-config/dashboard") @@ -28,6 +30,7 @@ require("plugin-config/coderunner") require("plugin-config/lazygit") -- require("plugin-config/neogit") +require("autocmd") require("lsp") require("lsp.cmp") require("lsp.null-ls") diff --git a/lua/autocmd.lua b/lua/autocmd.lua new file mode 100644 index 0000000..8a3fb5b --- /dev/null +++ b/lua/autocmd.lua @@ -0,0 +1,26 @@ +local vim = vim +local api = vim.api +local M = {} +-- function to create a list of commands and convert them to autocommands +-------- This function is taken from https://github.com/norcalli/nvim_utils +function M.nvim_create_augroups(definitions) + for group_name, definition in pairs(definitions) do + api.nvim_command("augroup " .. group_name) + api.nvim_command("autocmd!") + for _, def in ipairs(definition) do + local command = table.concat(vim.tbl_flatten({ "autocmd", def }), " ") + api.nvim_command(command) + end + api.nvim_command("augroup END") + end +end + +local autoCommands = { + -- other autocommands + open_folds = { + { "BufEnter", "*", "normal zx" }, + { "BufEnter", "*", "normal zR" }, + }, +} + +M.nvim_create_augroups(autoCommands) diff --git a/lua/basic.lua b/lua/basic.lua index af4ed3d..0958179 100644 --- a/lua/basic.lua +++ b/lua/basic.lua @@ -8,8 +8,6 @@ M.load_default_options = function() completeopt = { "menuone", "noselect" }, conceallevel = 0, -- so that `` is visible in markdown files fileencoding = "utf-8", -- the encoding written to a file - foldmethod = "manual", -- folding, set to "expr" for treesitter based folding - foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding guifont = "FiraCode Nerd Font:h20", -- the font used in graphical neovim applications background = "light", -- set the background to light or dark hidden = true, -- required to keep multiple buffers and open multiple buffers @@ -27,6 +25,10 @@ M.load_default_options = function() autochdir = true, -- auto change working directory termguicolors = true, -- set term gui colors (most terminals support this) timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) + -- foldmethod = "manual", -- folding, set to "expr" for treesitter based folding + -- foldexpr = "", -- set to "nvim_treesitter#foldexpr()" for treesitter based folding + foldmethod = "expr", + foldexpr = "nvim_treesitter#foldexpr()", 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 @@ -39,6 +41,7 @@ M.load_default_options = function() cursorline = true, -- highlight the current line number = true, -- set numbered lines numberwidth = 4, -- set number column width to 2 {default 4} + relativenumber = true, -- set relative numbered lines signcolumn = "yes", -- always show the sign column, otherwise it would shift the text each time wrap = true, -- display lines as one long line -- shadafile = join_paths(get_cache_dir(), "lvim.shada"), diff --git a/lua/keybindings.lua b/lua/keybindings.lua index cccec41..fa7b386 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -9,7 +9,7 @@ local wk = require("which-key") -- basic operation for write and quit -- 文件写入退出基本操作 wk.register({ - ["s"] = { ":w", "Save File" }, + ["s"] = { ":w!", "Save File" }, ["q"] = { ":qa", "Quit All" }, ["S"] = { ":wa", "Save All" }, }) @@ -25,6 +25,8 @@ pluginKeys.maplsp = function(mapbuf) -- diagnostic mapbuf("n", "]p", "lua vim.diagnostic.goto_prev()", opt) mapbuf("n", "]n", "lua vim.diagnostic.goto_next()", opt) + mapbuf("n", "]a", "lua vim.lsp.buf.code_action()", opt) + mapbuf("n", "]h", "lua vim.lsp.buf.hover()", opt) end -- code related @@ -37,14 +39,6 @@ wk.register({ ["m"] = { ":MarkdownPreview", "Markdown preview" }, }) --- markdown table --- markdown 表格 -wk.register({ - ["t"] = { - name = "", - }, -}) - -- git related -- git 相关 wk.register({ @@ -61,9 +55,10 @@ wk.register({ name = "+File", p = { ":Telescope projects", "Open project" }, r = { ":Telescope oldfiles", "Recent files" }, - f = { ":Telescope file_browser", "File browser" }, + b = { ":Telescope file_browser", "File browser" }, n = { ":AdvancedNewFile", "New file" }, s = { ":Telescope live_grep", "Search in project" }, + f = { ":Telescope find_files", "Search file" }, }, }) @@ -123,7 +118,11 @@ wk.register({ s = { ":Telescope current_buffer_fuzzy_find", "Searching in buffer" }, }, }) +wk.register({ + ["j"] = { ":HopLineStart", "Quick jump line" }, +}) +map("n", "", "za", opt) -- insert 模式下ctrl a e跳转开头结尾 map("i", "", "I", opt) map("i", "", "A", opt) @@ -142,15 +141,14 @@ wk.register({ i = { ":LspInstall", "Install lsp" }, I = { ":MasonInstall ", "Install any" }, r = { ":LspRestart", "Lsp restart" }, - l = { ":Mason", "Mason info" }, + m = { ":Mason", "Mason info" }, u = { ":MasonUninstall", "Uninstall lsp" }, U = { ":MasonUninstallAll", "Unistall all" }, + l = { ":LspInfo", "Lsp infos" }, + R = { vim.lsp.buf.rename, "Buffer var rename" }, }, }) --- Telescope -map("n", "f", ":Telescope find_files", opt) - -- cmpeletion keys -- 补全快捷键 pluginKeys.cmp = function(cmp) diff --git a/lua/lsp/cmp.lua b/lua/lsp/cmp.lua index d1720e9..b1485df 100644 --- a/lua/lsp/cmp.lua +++ b/lua/lsp/cmp.lua @@ -81,3 +81,4 @@ cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({ map_char = { tex = -- use friendly snippet require("luasnip.loaders.from_vscode").lazy_load() +require("luasnip.loaders.from_vscode").lazy_load({ paths = "~/.config/nvim/snippets" }) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 14ef78e..6482be7 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -11,6 +11,7 @@ local servers = { eslint = require("lsp.config.eslint"), -- bashls = require("lsp.config.bash"), pyright = require("lsp.config.pyright"), + -- jedi_language_server = require("lsp.config.jedi"), vuels = require("lsp.config.vue"), -- html = require("lsp.config.html"), -- cssls = require("lsp.config.css"), diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 28c675b..451f24b 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -15,6 +15,7 @@ require("null-ls").setup({ require("null-ls").builtins.formatting.stylua, require("null-ls").builtins.formatting.clang_format, require("null-ls").builtins.formatting.gofmt, + require("null-ls").builtins.formatting.black, }, -- you can reuse a shared lspconfig on_attach callback here on_attach = function(client, bufnr) diff --git a/lua/plugin-config/dashboard.lua b/lua/plugin-config/dashboard.lua index 5209709..b6c2c03 100644 --- a/lua/plugin-config/dashboard.lua +++ b/lua/plugin-config/dashboard.lua @@ -15,7 +15,7 @@ db.custom_center = { icon = " ", desc = "Find File ", action = "Telescope find_files find_command=rg,--hidden,--files", - shortcut = " f", + shortcut = "SPC f f", }, { icon = " ", @@ -33,6 +33,6 @@ db.custom_center = { icon = " ", desc = "File Browser ", action = "Telescope file_browser", - shortcut = "SPC f f", + shortcut = "SPC f b", }, } diff --git a/lua/plugin-config/hop.lua b/lua/plugin-config/hop.lua index 5c6c03c..cdf99fc 100644 --- a/lua/plugin-config/hop.lua +++ b/lua/plugin-config/hop.lua @@ -2,9 +2,10 @@ 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_patterns({ direction = directions.AFTER_CURSOR, current_line_only = true }, "\\u") +end, { remap = true }) + vim.keymap.set("", "F", function() hop.hint_char1({ direction = directions.BEFORE_CURSOR, current_line_only = true }) end, { remap = true }) diff --git a/lua/plugin-config/lua_snip.lua b/lua/plugin-config/lua_snip.lua new file mode 100644 index 0000000..c7e3cb8 --- /dev/null +++ b/lua/plugin-config/lua_snip.lua @@ -0,0 +1,60 @@ +local ls = require("luasnip") +local s = ls.snippet +local sn = ls.snippet_node +local isn = ls.indent_snippet_node +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local c = ls.choice_node +local d = ls.dynamic_node +local r = ls.restore_node +local events = require("luasnip.util.events") +local ai = require("luasnip.nodes.absolute_indexer") +local extras = require("luasnip.extras") +local l = extras.lambda +local rep = extras.rep +local p = extras.partial +local m = extras.match +local n = extras.nonempty +local dl = extras.dynamic_lambda +local fmt = require("luasnip.extras.fmt").fmt +local fmta = require("luasnip.extras.fmt").fmta +local conds = require("luasnip.extras.expand_conditions") +local postfix = require("luasnip.extras.postfix").postfix +local types = require("luasnip.util.types") +local parse = require("luasnip.util.parser").parse_snippet + +local date = function() + return { os.date("%Y-%m-%d") } +end + +ls.add_snippets("all", { + s({ + trig = "date", + name = "Date", + dscr = "Date in the form of YYYY-MM-DD", + }, { + f(date, {}), + }), +}) + +ls.add_snippets("markdown", { + s({ trig = "meta", name = "Metadata", dscr = "Yaml metadata format for markdown" }, { + t({ "---", "title: " }), + i(1, "note_title"), + t({ "", "author: " }), + i(2, "Logic"), + t({ "", "date: " }), + f(date, {}), + t({ "", 'categories: ["' }), + i(3, ""), + t({ '"]', "tags: [" }), + i(4), + t({ "]", "draft: " }), + i(5, "false"), + t({ "", "", "---", "" }), + i(0), + }), +}) + +require("luasnip.loaders.from_lua").lazy_load({ include = { "all", "markdown" } }) diff --git a/lua/plugin-config/mkdnflow.lua b/lua/plugin-config/mkdnflow.lua new file mode 100644 index 0000000..d63145d --- /dev/null +++ b/lua/plugin-config/mkdnflow.lua @@ -0,0 +1 @@ +require("mkdnflow").setup({}) diff --git a/lua/plugin-config/table-mode.lua b/lua/plugin-config/table-mode.lua index de51054..87fa829 100644 --- a/lua/plugin-config/table-mode.lua +++ b/lua/plugin-config/table-mode.lua @@ -1,5 +1,5 @@ -local let_table_settings = {} +-- local let_table_settings = {} -for k, v in pairs(let_table_settings) do - vim.g[k] = v -end +-- for k, v in pairs(let_table_settings) do +-- vim.g[k] = v +-- end diff --git a/lua/plugin-config/treesitter.lua b/lua/plugin-config/treesitter.lua index 1ec3073..bb3c3b3 100644 --- a/lua/plugin-config/treesitter.lua +++ b/lua/plugin-config/treesitter.lua @@ -1,55 +1,55 @@ -require'nvim-treesitter.configs'.setup { - -- A list of parser names, or "all" - ensure_installed = {}, +require("nvim-treesitter.configs").setup({ + -- A list of parser names, or "all" + ensure_installed = {}, - -- Install parsers synchronously (only applied to `ensure_installed`) - sync_install = false, + -- Install parsers synchronously (only applied to `ensure_installed`) + sync_install = false, - -- Automatically install missing parsers when entering buffer - auto_install = true, + -- Automatically install missing parsers when entering buffer + auto_install = true, - -- List of parsers to ignore installing (for "all") - -- ignore_install = { }, + -- List of parsers to ignore installing (for "all") + -- ignore_install = { }, - ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) - -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! + ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) + -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! - highlight = { - -- `false` will disable the whole extension - enable = true, + highlight = { + -- `false` will disable the whole extension + enable = true, - -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to - -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is - -- the name of the parser) - -- list of language that will be disabled - disable = { "c", "rust" }, - -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files - disable = function(lang, buf) - local max_filesize = 100 * 1024 -- 100 KB - local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) - if ok and stats and stats.size > max_filesize then - return true - end - end, + -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to + -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is + -- the name of the parser) + -- list of language that will be disabled + -- disable = { "c", "rust" }, + -- Or use a function for more flexibility, e.g. to disable slow treesitter highlight for large files + disable = function(lang, buf) + local max_filesize = 100 * 1024 -- 100 KB + local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf)) + if ok and stats and stats.size > max_filesize then + return true + end + end, - -- Setting this to true will run `:h syntax` and tree-sitter at the same time. - -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). - -- Using this option may slow down your editor, and you may see some duplicate highlights. - -- Instead of true it can also be a list of languages - additional_vim_regex_highlighting = false, - }, - context_commentstring = { - enable = true, - enable_autocmd = false, - config = { - -- Languages that have a single comment style - typescript = "// %s", - css = "/* %s */", - scss = "/* %s */", - html = "", - svelte = "", - vue = "", - json = "", - }, - }, -} + -- Setting this to true will run `:h syntax` and tree-sitter at the same time. + -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). + -- Using this option may slow down your editor, and you may see some duplicate highlights. + -- Instead of true it can also be a list of languages + additional_vim_regex_highlighting = false, + }, + context_commentstring = { + enable = true, + enable_autocmd = false, + config = { + -- Languages that have a single comment style + typescript = "// %s", + css = "/* %s */", + scss = "/* %s */", + html = "", + svelte = "", + vue = "", + json = "", + }, + }, +}) diff --git a/lua/plugins.lua b/lua/plugins.lua index d82db94..79d9cf1 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -47,11 +47,15 @@ return require("packer").startup(function() -- markdown table -- 优化markdown添加表格 - use("dhruvasagar/vim-table-mode") + -- use("dhruvasagar/vim-table-mode") -- nvim-markdown -- markdown 增强 - use("ixru/nvim-markdown") + -- use("ixru/nvim-markdown") + + -- markdown flow and enhance + -- markdown 流程和增强 + use({ "jakewvincent/mkdnflow.nvim" }) -- orgmode support -- orgmode 支持 @@ -127,6 +131,7 @@ return require("packer").startup(function() "phaazon/hop.nvim", branch = "v2", -- optional but strongly recommended }) + -- lualine for bottom stausline -- 底部状态栏 use({ diff --git a/readme.md b/readme.md index a9bde2d..003e74c 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,7 @@ | \s | 保存当前文件 | | \S | 保存所有文件 | | \ | 切换回上一个buffer,用于两buffer间来回切换 | +| \j | 快速进行行跳转 | | , | 运行当前文件代码,需要自行配置各种语言 | | Ctrl-\\ | 打开终端 | @@ -133,3 +134,5 @@ + + diff --git a/snippets/package.json b/snippets/package.json new file mode 100644 index 0000000..d62a287 --- /dev/null +++ b/snippets/package.json @@ -0,0 +1,19 @@ +{ + "name":"my-snippets", + "contributes":{ + "snippets":[ + { + "language":[ + "go" + ], + "path":"./go.json" + }, + { + "language":[ + "markdown" + ], + "path":"./markdown.json" + } + ] + } +}