From 06b955efa1459aef786f1c7a0fb07876fb48d184 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Thu, 29 Feb 2024 15:29:31 -0500 Subject: [PATCH 1/2] Add some additional configuration settings --- init.lua | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/init.lua b/init.lua index fa03e14..fdd9a9b 100644 --- a/init.lua +++ b/init.lua @@ -49,7 +49,15 @@ vim.opt.ts = 4 vim.opt.expandtab = true vim.opt.tw = 100 vim.opt.colorcolumn = "+1" - +vim.opt.pumheight = 5 + +-- Disable semantic tokens +vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local client = vim.lsp.get_client_by_id(args.data.client_id) + client.server_capabilities.semanticTokensProvider = nil + end, +}) -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -73,8 +81,26 @@ vim.keymap.set("n", "", "", { desc = "Move focus to the lower win vim.keymap.set("n", "", "", { desc = "Move focus to the upper window" }) -- [[ Basic Autocommands ]] --- See :help lua-guide-autocommands - +-- Go back to last edited line when reopening file +vim.api.nvim_create_autocmd("BufRead", { + callback = function(opts) + vim.api.nvim_create_autocmd("BufWinEnter", { + once = true, + buffer = opts.buf, + callback = function() + local ft = vim.bo[opts.buf].filetype + local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1] + if + not (ft:match("commit") and ft:match("rebase")) + and last_known_line > 1 + and last_known_line <= vim.api.nvim_buf_line_count(opts.buf) + then + vim.api.nvim_feedkeys([[g`"]], "nx", false) + end + end, + }) + end, +}) -- [[ Install `lazy.nvim` plugin manager ]] -- See `:help lazy.nvim.txt` or https://github.com/folke/lazy.nvim for more info local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" @@ -158,6 +184,7 @@ require("lazy").setup({ }, "kana/vim-textobj-user", "godlygeek/tabular", + "tpope/vim-sleuth", { "Vigemus/iron.nvim", config = function() @@ -375,7 +402,12 @@ require("lazy").setup({ -- - settings (table): Override the default settings passed when initializing the server. -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { - clangd = {}, + clangd = { + filetypes = { + "c", + "cpp", + }, + }, -- gopls = {}, jdtls = {}, pyright = {}, @@ -570,7 +602,7 @@ require("lazy").setup({ ensure_installed = { "bash", "c", "html", "lua", "markdown", "vim", "vimdoc" }, -- Autoinstall languages that are not installed auto_install = true, - highlight = { enable = true }, + highlight = { enable = false }, indent = { enable = true }, }) From 80526d30e54faa60a6851ed8e77ef655afd78175 Mon Sep 17 00:00:00 2001 From: Alex Selimov Date: Fri, 8 Mar 2024 08:19:12 -0500 Subject: [PATCH 2/2] Add word count to status line --- init.lua | 117 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 104 insertions(+), 13 deletions(-) diff --git a/init.lua b/init.lua index fdd9a9b..9f63798 100644 --- a/init.lua +++ b/init.lua @@ -58,6 +58,16 @@ vim.api.nvim_create_autocmd("LspAttach", { client.server_capabilities.semanticTokensProvider = nil end, }) + +-- Function to get work count in status line +local function getWords() + -- the third string here is the string for visual-block mode (^V) + if vim.fn.mode() == "v" or vim.fn.mode() == "V" or vim.fn.mode() == "" then + return vim.fn.wordcount().visual_words .. "" + else + return vim.fn.wordcount().words .. "" + end +end -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` @@ -79,7 +89,6 @@ vim.keymap.set("n", "", "", { desc = "Move focus to the left wind vim.keymap.set("n", "", "", { desc = "Move focus to the right window" }) vim.keymap.set("n", "", "", { desc = "Move focus to the lower window" }) vim.keymap.set("n", "", "", { desc = "Move focus to the upper window" }) - -- [[ Basic Autocommands ]] -- Go back to last edited line when reopening file vim.api.nvim_create_autocmd("BufRead", { @@ -91,7 +100,7 @@ vim.api.nvim_create_autocmd("BufRead", { local ft = vim.bo[opts.buf].filetype local last_known_line = vim.api.nvim_buf_get_mark(opts.buf, '"')[1] if - not (ft:match("commit") and ft:match("rebase")) + not (ft:match("gitcommit") and ft:match("gitrebase")) and last_known_line > 1 and last_known_line <= vim.api.nvim_buf_line_count(opts.buf) then @@ -182,7 +191,12 @@ require("lazy").setup({ npairs.remove_rule("`") end, }, - "kana/vim-textobj-user", + { + "GCBallesteros/vim-textobj-hydrogen", + dependencies = { + "kana/vim-textobj-user", + }, + }, "godlygeek/tabular", "tpope/vim-sleuth", { @@ -225,8 +239,6 @@ require("lazy").setup({ }, ignore_blank_lines = true, -- ignore blank lines when sending visual select lines }) - - -- iron also has a list of commands, see :h iron-commands for all available commands vim.keymap.set("n", ";rs", "IronRepl") vim.keymap.set("n", ";rr", "IronRestart") vim.keymap.set("n", ";rf", "IronFocus") @@ -236,7 +248,7 @@ require("lazy").setup({ end, }, "tpope/vim-markdown", - + "christoomey/vim-tmux-navigator", -- NOTE: Plugins can specify dependencies. -- -- The dependencies are proper plugin specifications as well - anything @@ -290,10 +302,21 @@ require("lazy").setup({ pcall(require("telescope").load_extension("live_grep_args")) local builtin = require("telescope.builtin") vim.keymap.set("n", "", require("telescope").extensions.live_grep_args.live_grep_args) - vim.keymap.set("n", "", require("telescope").extensions.live_grep_args.live_grep_args) + vim.keymap.set( + "x", + "", + "\"zy:lua require('telescope').extensions.live_grep_args.live_grep_args(require('telescope.themes').get_ivy({}))z" + ) vim.keymap.set("n", "", builtin.find_files) end, }, + { -- grammar checking + "rhysd/vim-grammarous", + ft = { "markdown", "latex" }, + config = function() + vim.g["grammarous#jar_url"] = "https://www.languagetool.org/download/LanguageTool-5.9.zip" + end, + }, { -- LSP Configuration & Plugins "neovim/nvim-lspconfig", dependencies = { @@ -330,7 +353,7 @@ require("lazy").setup({ -- Jump to the implementation of the word under your cursor. -- Useful when your language has ways of declaring types without an actual implementation. - map("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") + map("I", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") -- Jump to the type of the word under your cursor. -- Useful when you're not sure what type a variable is and you want to see @@ -517,6 +540,35 @@ require("lazy").setup({ end return "make install_jsregexp" end)(), + config = function() + require("luasnip.loaders.from_snipmate").lazy_load({ paths = "./snippets" }) + local ls = require("luasnip") + -- some shorthands... + local snip = ls.snippet + local node = ls.snippet_node + local text = ls.text_node + local insert = ls.insert_node + local func = ls.function_node + local choice = ls.choice_node + local dynamicn = ls.dynamic_node + + ls.add_snippets(nil, { + python = { + snip({ + trig = "imp", + namr = "Imports", + dscr = "Comments for imports", + }, { + text({ "# Core modules", "" }), + insert(1), + text({ "", "# Non-core modules", "" }), + insert(2), + text({ "", "# SEI modules", "" }), + insert(3), + }), + }, + }) + end, }, "saadparwaiz1/cmp_luasnip", "hrsh7th/cmp-nvim-lsp", @@ -550,10 +602,16 @@ require("lazy").setup({ -- This will expand snippets if the LSP sent a snippet. [""] = cmp.mapping.confirm({ select = true }), - -- Manually trigger a completion from nvim-cmp. - -- Generally you don't need this, because nvim-cmp will display - -- completions whenever it has completion options available. - [""] = cmp.mapping.complete({}), + ["j"] = cmp.mapping(function() + if luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + end + end, { "i", "s" }), + ["k"] = cmp.mapping(function() + if luasnip.locally_jumpable(-1) then + luasnip.jump(-1) + end + end, { "i", "s" }), }), sources = { { name = "nvim_lsp" }, @@ -562,6 +620,15 @@ require("lazy").setup({ }, }) end, + snippet = { + expand = function(args) + local luasnip = require("luasnip") + if not luasnip then + return + end + luasnip.lsp_expand(args.body) + end, + }, }, { -- You can easily change to a different colorscheme. @@ -587,7 +654,31 @@ require("lazy").setup({ -- and try some other statusline plugin "echasnovski/mini.nvim", config = function() - require("mini.statusline").setup() + require("mini.statusline").setup({ + content = { + active = function() + local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) + local git = MiniStatusline.section_git({ trunc_width = 75 }) + local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 }) + local filename = MiniStatusline.section_filename({ trunc_width = 140 }) + local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) + local location = MiniStatusline.section_location({ trunc_width = 75 }) + local search = MiniStatusline.section_searchcount({ trunc_width = 75 }) + local words = getWords() + return MiniStatusline.combine_groups({ + + { hl = mode_hl, strings = { mode } }, + { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics } }, + "%<", -- Mark general truncate point + { hl = "MiniStatuslineFilename", strings = { filename } }, + "%=", -- End left alignment + { hl = "MiniStatuslineFileinfo", strings = { fileinfo } }, + { hl = "MiniStatuslineFileinfo", strings = { words } }, + { hl = mode_hl, strings = { search, location } }, + }) + end, + }, + }) end, },