From 2e06e0d6013ec58e6a8f5dd93e2f3d8350af5647 Mon Sep 17 00:00:00 2001 From: gameloader Date: Wed, 20 Sep 2023 23:55:31 +0800 Subject: [PATCH] add latex config using vimtex and change neotree to auto chdir work dir --- init.lua | 1 + lua/autocmd.lua | 8 +++++++- lua/keybindings.lua | 26 +++++++++++++++++++++++++- lua/lsp/cmp.lua | 1 + lua/lsp/config/texlab.lua | 1 + lua/lsp/init.lua | 7 ++++--- lua/lsp/null-ls.lua | 4 ++-- lua/plugin-config/neotree.lua | 4 +++- lua/plugin-config/treesitter.lua | 17 ++++++++++------- lua/plugin-config/vimtex.lua | 17 +++++++++++++++++ lua/plugins.lua | 4 ++++ 11 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 lua/lsp/config/texlab.lua create mode 100644 lua/plugin-config/vimtex.lua diff --git a/init.lua b/init.lua index 39d6af2..ddf4d70 100644 --- a/init.lua +++ b/init.lua @@ -10,6 +10,7 @@ require("plugin-config/treesitter") require("plugin-config/telescope") require("plugin-config/whichkey") require("plugin-config/comment") +require("plugin-config/vimtex") require("plugin-config/mason") require("plugin-config/lua_line") require("plugin-config/notify") diff --git a/lua/autocmd.lua b/lua/autocmd.lua index 6da9e2d..53778e5 100644 --- a/lua/autocmd.lua +++ b/lua/autocmd.lua @@ -27,6 +27,12 @@ function set_colorscheme() end end +function auto_chdir() + local filename = vim.fn.expand("%:p") + local directory = vim.fn.fnamemodify(filename, ":h") + vim.cmd("cd " .. directory) +end + local autoCommands = { -- other autocommands open_folds = { @@ -36,7 +42,7 @@ local autoCommands = { { "VimEnter", "*", "lua set_colorscheme()" }, }, auto_change_directory = { - { "BufEnter", "*", "lcd %:p:h" }, + { "BufEnter", "*", "lua auto_chdir()" }, }, } diff --git a/lua/keybindings.lua b/lua/keybindings.lua index e55f06b..8696e51 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -100,6 +100,25 @@ wk.register({ }, }) +-- 定义开关quickfix窗口的函数 + +local function toggle_quickfix() + -- 获取所有窗口的信息 + local wininfo = vim.fn.getwininfo() + -- 遍历所有窗口 + for _, win in pairs(wininfo) do + -- 如果这个窗口是 quickfix 窗口 + if win.quickfix == 1 then + -- 关闭 quickfix 窗口 + vim.cmd("cclose") + -- 返回,不再继续查找 + return + end + end + -- 如果没有找到 quickfix 窗口,就打开一个 + vim.cmd("copen") +end + -- Bufferline and buffer related wk.register({ ["b"] = { @@ -110,7 +129,12 @@ wk.register({ n = { ":ls", "Buffer numbers" }, c = { ":noh", "Cancel highlight" }, C = { ":call setqflist([], 'r')", "Clear quickfix" }, - q = { ":copen", "Open quickfix" }, + q = { + function() + toggle_quickfix() + end, + "Toggle quickfix", + }, s = { ":Telescope current_buffer_fuzzy_find", "Searching in buffer" }, }, }) diff --git a/lua/lsp/cmp.lua b/lua/lsp/cmp.lua index b1485df..325094b 100644 --- a/lua/lsp/cmp.lua +++ b/lua/lsp/cmp.lua @@ -21,6 +21,7 @@ cmp.setup({ sources = cmp.config.sources({ { name = "orgmode" }, { name = "nvim_lsp" }, + { name = "omni" }, -- For vsnip users. -- { name = "vsnip" }, -- For luasnip users. diff --git a/lua/lsp/config/texlab.lua b/lua/lsp/config/texlab.lua new file mode 100644 index 0000000..723c978 --- /dev/null +++ b/lua/lsp/config/texlab.lua @@ -0,0 +1 @@ +return require("lsp.config.basic_config") diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 46eade5..7572d46 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -8,7 +8,7 @@ local servers = { lua_ls = require("lsp.config.lua"), -- lua/lsp/config/lua.lua clangd = require("lsp.config.clangd"), gopls = require("lsp.config.gopls"), - eslint = require("lsp.config.eslint"), + -- eslint = require("lsp.config.eslint"), -- r_language_server = require("lsp.config.r"), -- csharp_ls = require("lsp.config.csharp"), omnisharp = require("lsp.config.csharp"), @@ -16,12 +16,13 @@ local servers = { pyright = require("lsp.config.pyright"), marksman = require("lsp.config.marksman"), pylsp = require("lsp.config.pylsp"), - volar = require("lsp.config.vue"), + -- texlab = require("lsp.config.texlab"), + -- volar = require("lsp.config.vue"), -- html = require("lsp.config.html"), -- cssls = require("lsp.config.css"), -- emmet_ls = require("lsp.config.emmet"), -- jsonls = require("lsp.config.json"), - -- tsserver = require("lsp.config.ts"), + tsserver = require("lsp.config.ts"), -- rust_analyzer = require("lsp.config.rust"), -- yamlls = require("lsp.config.yamlls"), -- remark_ls = require("lsp.config.markdown"), diff --git a/lua/lsp/null-ls.lua b/lua/lsp/null-ls.lua index 9e10ed5..43446ce 100644 --- a/lua/lsp/null-ls.lua +++ b/lua/lsp/null-ls.lua @@ -15,12 +15,12 @@ require("null-ls").setup({ require("null-ls").builtins.formatting.stylua, require("null-ls").builtins.formatting.styler, require("null-ls").builtins.formatting.clang_format.with({ - disabled_filetypes = { "cs" }, + disabled_filetypes = { "cs", "js" }, }), require("null-ls").builtins.formatting.csharpier, require("null-ls").builtins.formatting.gofmt, require("null-ls").builtins.formatting.black, - require("null-ls").builtins.formatting.eslint_d, + require("null-ls").builtins.formatting.prettier, require("null-ls").builtins.formatting.jq, }, -- you can reuse a shared lspconfig on_attach callback here diff --git a/lua/plugin-config/neotree.lua b/lua/plugin-config/neotree.lua index b90ddd4..d17f6c0 100644 --- a/lua/plugin-config/neotree.lua +++ b/lua/plugin-config/neotree.lua @@ -2,5 +2,7 @@ require("neo-tree").setup({ window = { width = "25%", -- Width of the Neo-tree window }, - update_cwd = true, + filesystem = { + bind_to_cwd = true, + }, }) diff --git a/lua/plugin-config/treesitter.lua b/lua/plugin-config/treesitter.lua index bb3c3b3..07a45b2 100644 --- a/lua/plugin-config/treesitter.lua +++ b/lua/plugin-config/treesitter.lua @@ -24,13 +24,16 @@ require("nvim-treesitter.configs").setup({ -- 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, + disable = { + "latex", + 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). diff --git a/lua/plugin-config/vimtex.lua b/lua/plugin-config/vimtex.lua new file mode 100644 index 0000000..22fda1e --- /dev/null +++ b/lua/plugin-config/vimtex.lua @@ -0,0 +1,17 @@ +-- This is necessary for VimTeX to load properly. The "indent" is optional. +-- Note that most plugin managers will do this automatically. +vim.cmd("filetype plugin indent on") +-- This enables Vim's and Neovim's syntax-related features. Without this, some +-- VimTeX features will not work (see ":help vimtex-requirements" for more info). +vim.cmd("syntax enable") + +-- Viewer options: One may configure the viewer either by specifying a built-in +-- viewer method: +vim.g.vimtex_view_method = "skim" +-- vim.g.vimtex_view_general_options = "--unique file:@pdf\\#src:@line@tex" + +vim.g.vimtex_complete_close_braces = 1 +vim.g.vimtex_syntax_enabled = 1 +vim.g.vimtex_compiler_latexmk_engines = { + ["_"] = "-xelatex", +} diff --git a/lua/plugins.lua b/lua/plugins.lua index 1d7ef1d..9bf9cb2 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -60,6 +60,9 @@ return require("packer").startup(function() }, }) + ----------------latex------------------ + use("lervag/vimtex") + -- vim dashboard -- vim 开始界面 use({ @@ -186,6 +189,7 @@ return require("packer").startup(function() use("hrsh7th/cmp-nvim-lsp") -- { name = nvim_lsp } use("hrsh7th/cmp-buffer") -- { name = 'buffer' }, use("hrsh7th/cmp-path") -- { name = 'path' } + use("hrsh7th/cmp-omni") -- { name = 'omni' } use("hrsh7th/cmp-cmdline") -- { name = 'cmdline' } use("hrsh7th/cmp-nvim-lsp-signature-help") -- { name = 'nvim_lsp_signature_help' } -- 常见编程语言代码段