From 41130c69bc1b2866fae0fd7b93d12d34c329bf81 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sun, 29 Sep 2024 18:26:25 +0200 Subject: [PATCH] init --- init.lua | 26 +++ lazy-lock.json | 31 +++ lua/mappings.lua | 72 +++++++ lua/minifiles-config.lua | 52 +++++ lua/plugins/plugins.lua | 112 ++++++++++ lua/plugins/rust-tools.lua | 122 +++++++++++ lua/plugins/telescope.lua | 34 +++ lua/settings.lua | 48 +++++ lua/setup.lua | 430 +++++++++++++++++++++++++++++++++++++ lua/telescope-config.lua | 23 ++ lua/utils.lua | 27 +++ 11 files changed, 977 insertions(+) create mode 100644 init.lua create mode 100644 lazy-lock.json create mode 100644 lua/mappings.lua create mode 100644 lua/minifiles-config.lua create mode 100644 lua/plugins/plugins.lua create mode 100644 lua/plugins/rust-tools.lua create mode 100644 lua/plugins/telescope.lua create mode 100644 lua/settings.lua create mode 100644 lua/setup.lua create mode 100644 lua/telescope-config.lua create mode 100644 lua/utils.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..0790b23 --- /dev/null +++ b/init.lua @@ -0,0 +1,26 @@ +vim.g.mapleader = " " + +local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' +if not vim.loop.fs_stat(lazypath) then + vim.fn.system { + 'git', + 'clone', + '--filter=blob:none', + 'https://github.com/folke/lazy.nvim.git', + '--branch=stable', -- latest stable release + lazypath, + } +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup("plugins", { + dev = { + -- directory where you store your local plugin projects + path = "~/lua/nvim-plugins", + fallback = true, -- Fallback to git when local plugin doesn't exist + }, +}) + +require("settings") +require("mappings") +require("setup") diff --git a/lazy-lock.json b/lazy-lock.json new file mode 100644 index 0000000..4d096ba --- /dev/null +++ b/lazy-lock.json @@ -0,0 +1,31 @@ +{ + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-cmdline": { "branch": "main", "commit": "d250c63aa13ead745e3a40f61fdd3470efde3923" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "gitsigns.nvim": { "branch": "main", "commit": "899e993850084ea33d001ec229d237bc020c19ae" }, + "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, + "indent-blankline.nvim": { "branch": "master", "commit": "db926997af951da38e5004ec7b9fbdc480b48f5d" }, + "lazy.nvim": { "branch": "main", "commit": "48b52b5cfcf8f88ed0aff8fde573a5cc20b1306d" }, + "linediff.vim": { "branch": "main", "commit": "ddae71ef5f94775d101c1c70032ebe8799f32745" }, + "mason-lspconfig.nvim": { "branch": "main", "commit": "482350b050bd413931c2cdd4857443c3da7d57cb" }, + "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, + "mini.files": { "branch": "main", "commit": "58e1acfadc93f56d4c2c2a8e8d93021f4d7ff411" }, + "neogen": { "branch": "main", "commit": "e932ba918b56723436b77aa3efb844a11b2851ab" }, + "nvim-autopairs": { "branch": "master", "commit": "19606af7c039271d5aa96bceff101e7523af3136" }, + "nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" }, + "nvim-lspconfig": { "branch": "master", "commit": "3ad562700d0615818bf358268ac8914f6ce2b079" }, + "nvim-treesitter": { "branch": "master", "commit": "64cc1ef764a0b137a642d05cacdfe1126124fb35" }, + "nvim-ts-rainbow": { "branch": "master", "commit": "ef95c15a935f97c65a80e48e12fe72d49aacf9b9" }, + "onedark.nvim": { "branch": "master", "commit": "fae34f7c635797f4bf62fb00e7d0516efa8abe37" }, + "plenary.nvim": { "branch": "master", "commit": "ec289423a1693aeae6cd0d503bac2856af74edaa" }, + "rust-tools.nvim": { "branch": "master", "commit": "676187908a1ce35ffcd727c654ed68d851299d3e" }, + "telescope-file-browser.nvim": { "branch": "master", "commit": "a46780830b576049c675680650f773bedfa8677a" }, + "telescope-fzf-native.nvim": { "branch": "main", "commit": "cf48d4dfce44e0b9a2e19a008d6ec6ea6f01a83b" }, + "telescope-live-grep-args.nvim": { "branch": "master", "commit": "8ad632f793fd437865f99af5684f78300dac93fb" }, + "telescope.nvim": { "branch": "0.1.x", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, + "vim-commentary": { "branch": "master", "commit": "c4b8f52cbb7142ec239494e5a2c4a512f92c4d07" }, + "vim-fugitive": { "branch": "master", "commit": "0444df68cd1cdabc7453d6bd84099458327e5513" }, + "vim-rhubarb": { "branch": "master", "commit": "ee69335de176d9325267b0fd2597a22901d927b1" }, + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" } +} diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..80ce29a --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,72 @@ +local u = require("utils") + +vim.keymap.set("n", "pv", vim.cmd.Ex) +vim.keymap.set("n", "h", ":noh") + +--move line shortcut +vim.keymap.set("n", "", ":m +1==", {noremap = true}) +vim.keymap.set("n", "", ":m -2==", {noremap = true}) + +vim.keymap.set("v", "", ":m '>+1gv=gv", {noremap = true}) +vim.keymap.set("v", "", ":m '<-2gv=gv", {noremap = true}) + +vim.keymap.set("n", "", "zz", {noremap = true}) +vim.keymap.set("n", "", "zz", {noremap = true}) + +vim.keymap.set("x", "p", "\"_dP") + +--tab buffer +vim.keymap.set("n", "fn", ":bnext", {noremap = true}) +vim.keymap.set("n", "fp", ":bprev", {noremap = true}) + +-- wrap toggle +vim.keymap.set("n", "w", function() vim.o.wrap = not vim.o.wrap end, {noremap = true}) + +vim.o.clipboard = 'unnamedplus' + +-- Diff mappings put/get then move to next change +-- u.nmap("dg", "diffget]c") +-- u.nmap("dp", "diffput]c") +-- +-- u.nmap("dp", "diffput]c") +-- +-- -- Remap movement to move by column layout +-- u.nvmap("j", "gj") +-- u.nvmap("k", "gk") +-- +-- u.nvmap(";", ":") + +-- Window splitting remap" +u.nmap("", "h") +u.nmap("", "k") +u.nmap("", "l") +u.nmap("", "j") +-- u.nmap("z", ":cclose") +-- +-- -- Exit terminal insert mode +-- u.tmap("", "") +-- +-- -- Delete buffer without closing the window +-- u.nmap("q", ":bpspbnbd") +-- +-- Fugitive +-- u.nmap("gw", ":Gwrite") +-- u.nmap("gr", ":Gread") +-- u.nmap("gc", ":Git commit -v") +-- u.nmap("gC", ":Git commit -v --amend") +-- u.nmap("gs", ":Git") +-- u.nmap("gd", ":Gdiff") +u.nmap("gb", ":Git blame") + +u.nmap("", "zz") +u.nmap("", "zz") + +u.nmap("ri", ":lua vim.lsp.inlay_hint(0)") +u.nmap("rl", ":RustFmt") + +-- vim.keymap.set("n", "ri", function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({0}), {0}) end) +u.nmap("d", ":lua vim.lsp.buf.hover()") + + +require("telescope-config") +require("minifiles-config") diff --git a/lua/minifiles-config.lua b/lua/minifiles-config.lua new file mode 100644 index 0000000..76ec814 --- /dev/null +++ b/lua/minifiles-config.lua @@ -0,0 +1,52 @@ +require('mini.files').setup({ + -- Customization of shown content + content = { + -- Predicate for which file system entries to show + filter = nil, + -- What prefix to show to the left of file system entry + prefix = nil, + -- In which order to show file system entries + sort = nil, + }, + + -- Module mappings created only inside explorer. + -- Use `''` (empty string) to not create one. + mappings = { + close = 'q', + go_in = 'l', + go_in_plus = 'L', + go_out = 'h', + go_out_plus = 'H', + reset = '', + reveal_cwd = '@', + show_help = 'g?', + synchronize = '=', + trim_left = '<', + trim_right = '>', + }, + + -- General options + options = { + -- Whether to delete permanently or move into module-specific trash + permanent_delete = true, + -- Whether to use for editing directories + use_as_default_explorer = true, + }, + + -- Customization of explorer windows + windows = { + -- Maximum number of windows to show side by side + max_number = math.huge, + -- Whether to show preview of file/directory under cursor + preview = false, + -- Width of focused window + width_focus = 50, + -- Width of non-focused window + width_nofocus = 15, + -- Width of preview window + width_preview = 25, + }, +}) + +vim.keymap.set("n", "-", 'lua MiniFiles.open(vim.api.nvim_buf_get_name(0)); MiniFiles.reveal_cwd()', { desc = 'Open MiniFiles' }) +vim.keymap.set("n", "", 'lua MiniFiles.close()', { desc = 'Close MiniFiles' }) diff --git a/lua/plugins/plugins.lua b/lua/plugins/plugins.lua new file mode 100644 index 0000000..776a21d --- /dev/null +++ b/lua/plugins/plugins.lua @@ -0,0 +1,112 @@ +return { + -- Theme + { + -- Theme inspired by Atom + 'navarasu/onedark.nvim', + priority = 1000, + lazy = false, + config = function() + require('onedark').setup { + -- Set a style preset. 'dark' is default. + style = 'dark', -- dark, darker, cool, deep, warm, warmer, light + } + require('onedark').load() + end, + }, + + -- Vim plugins + "windwp/nvim-autopairs", + + -- Git + "tpope/vim-fugitive", + "tpope/vim-rhubarb", + + "tpope/vim-commentary", + "tpope/vim-surround", + -- "christoomey/vim-tmux-navigator", + "AndrewRadev/linediff.vim", + { "echasnovski/mini.files", version = false }, + + + -- Nvim plugins + "nvim-treesitter/nvim-treesitter", -- {'do': ':TSUpdate'} + 'danymat/neogen', + "p00f/nvim-ts-rainbow", + "lukas-reineke/indent-blankline.nvim", + "hrsh7th/nvim-cmp", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-cmdline", + "hrsh7th/cmp-path", + "neovim/nvim-lspconfig", + "nvim-lua/plenary.nvim", + -- "jose-elias-alvarez/null-ls.nvim", + -- "jose-elias-alvarez/typescript.nvim", + -- "iamcco/markdown-preview.nvim", -- { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']} + -- { "olimorris/persisted.nvim", dev = true }, + -- "folke/tokyonight.nvim", -- { 'branch': 'main' } + "lewis6991/gitsigns.nvim", + "williamboman/mason.nvim", -- { 'do': ':MasonUpdate' } + "williamboman/mason-lspconfig.nvim", + { + 'ThePrimeagen/harpoon', + branch = 'harpoon2', + opts = { + menu = { + width = vim.api.nvim_win_get_width(0) - 4, + }, + }, + keys = { + { + 'q', + function() + require('harpoon'):list():add() + end, + desc = 'Harpoon File', + }, + { + '', + function() + local harpoon = require('harpoon') + harpoon.ui:toggle_quick_menu(harpoon:list()) + end, + desc = 'Harpoon Quick Menu', + }, + { + '', + function() + require('harpoon'):list():select(1) + end, + desc = 'Harpoon to File 1', + }, + { + '', + function() + require('harpoon'):list():select(2) + end, + desc = 'Harpoon to File 2', + }, + { + '', + function() + require('harpoon'):list():select(3) + end, + desc = 'Harpoon to File 3', + }, + { + '', + function() + require('harpoon'):list():select(4) + end, + desc = 'Harpoon to File 4', + }, + { + '', + function() + require('harpoon'):list():select(5) + end, + desc = 'Harpoon to File 5', + }, + }, + }, +} diff --git a/lua/plugins/rust-tools.lua b/lua/plugins/rust-tools.lua new file mode 100644 index 0000000..b56103f --- /dev/null +++ b/lua/plugins/rust-tools.lua @@ -0,0 +1,122 @@ +local opts = { + tools = { -- rust-tools options + + -- how to execute terminal commands + -- options right now: termopen / quickfix / toggleterm / vimux + -- executor = require("rust-tools.executors").termopen, + + -- callback to execute once rust-analyzer is done initializing the workspace + -- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error" + on_initialized = nil, + + -- automatically call RustReloadWorkspace when writing to a Cargo.toml file. + reload_workspace_from_cargo_toml = true, + + -- These apply to the default RustSetInlayHints command + inlay_hints = { + -- automatically set inlay hints (type hints) + -- default: true + auto = false, + + -- Only show inlay hints for the current line + only_current_line = false, + + -- whether to show parameter hints with the inlay hints or not + -- default: true + show_parameter_hints = true, + + -- prefix for parameter hints + -- default: "<-" + parameter_hints_prefix = "<- ", + + -- prefix for all the other hints (type, chaining) + -- default: "=>" + other_hints_prefix = "=> ", + + -- whether to align to the length of the longest line in the file + max_len_align = false, + + -- padding from the left if max_len_align is true + max_len_align_padding = 1, + + -- whether to align to the extreme right or not + right_align = false, + + -- padding from the right if right_align is true + right_align_padding = 7, + + -- The color of the hints + highlight = "Comment", + }, + + -- options same as lsp hover / vim.lsp.util.open_floating_preview() + hover_actions = { + + -- the border that is used for the hover window + -- see vim.api.nvim_open_win() + border = { + { "╭", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╮", "FloatBorder" }, + { "│", "FloatBorder" }, + { "╯", "FloatBorder" }, + { "─", "FloatBorder" }, + { "╰", "FloatBorder" }, + { "│", "FloatBorder" }, + }, + + -- Maximal width of the hover window. Nil means no max. + max_width = nil, + + -- Maximal height of the hover window. Nil means no max. + max_height = nil, + + -- whether the hover action window gets automatically focused + -- default: false + auto_focus = false, + }, + }, + + -- all the opts to send to nvim-lspconfig + -- these override the defaults set by rust-tools.nvim + -- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer + server = { + settings = { + ["rust-analyzer"] = { + -- cargo = { + -- features = "all", + -- check = { + -- overrideCommand = { + -- "cargo check --quiet --message-format=json --all-targets", + -- }, + -- }, + -- buildScripts = { + -- overideCommand = { + -- "cargo check --quiet --message-format=json --all-targets", + -- }, + -- }, + -- }, + }, + }, + + on_attach = function(client, bufnr) + if client.server_capabilities.inlayHintProvider then + vim.lsp.inlay_hint(bufnr, true) + -- vim.api.nvim_set_keymap("n", "ri", "lua vim.lsp.inlay_hint(0)", { noremap = true }) + end + end, + }, -- rust-analyzer options + + -- debugging stuff + -- dap = { + -- adapter = { + -- type = "executable", + -- command = "lldb-vscode", + -- name = "rt_lldb", + -- }, + -- }, +} + +return { + { "simrat39/rust-tools.nvim" }, +} diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua new file mode 100644 index 0000000..e2e55d2 --- /dev/null +++ b/lua/plugins/telescope.lua @@ -0,0 +1,34 @@ +return { + { + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + dependencies = { + "nvim-lua/plenary.nvim", + { + + "nvim-telescope/telescope-live-grep-args.nvim" , + -- This will not install any breaking changes. + -- For major updates, this must be adjusted manually. + version = "^1.0.0", + }, + }, + }, + { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, + { + "nvim-telescope/telescope-file-browser.nvim", + dependencies = { "nvim-telescope/telescope.nvim", "nvim-lua/plenary.nvim" }, + }, + config = function() + local telescope = require("telescope") + + -- first setup telescope + telescope.setup({ + -- your config + }) + + -- then load the extension + telescope.load_extension("live_grep_args") + end + -- "debugloop/telescope-undo.nvim", + -- "nvim-telescope/telescope-ui-select.nvim", +} diff --git a/lua/settings.lua b/lua/settings.lua new file mode 100644 index 0000000..7d4167d --- /dev/null +++ b/lua/settings.lua @@ -0,0 +1,48 @@ +local opt = vim.o-- global options + +vim.lsp.set_log_level("off") + +-- Theme +-- Options +opt.relativenumber = true +opt.colorcolumn = "80" +opt.number = true +opt.tabstop = 2 +opt.softtabstop = 2 +opt.shiftwidth = 2 +opt.expandtab = true +opt.smartindent = true + +-- Make line numbers default +vim.wo.number = true + +-- Enable mouse mode +opt.mouse = 'a' + +-- Sync clipboard between OS and Neovim. +opt.clipboard = 'unnamedplus' + +-- Enable break indent +opt.breakindent = true + +-- Save undo history +opt.undofile = true + +-- Keep signcolumn on by default +vim.wo.signcolumn = 'yes' + +-- Decrease update time +opt.updatetime = 250 +opt.timeoutlen = 300 + +-- Set completeopt to have a better completion experience +opt.completeopt = 'menuone,noselect' + +--ignore case if pattern doesn't contain upper case +opt.ignorecase = true +opt.smartcase = true + +--number of line to show around the cursor +opt.scrolloff = 8 + +-- vim.g.rustfmt_autosave = 1 diff --git a/lua/setup.lua b/lua/setup.lua new file mode 100644 index 0000000..8acbe38 --- /dev/null +++ b/lua/setup.lua @@ -0,0 +1,430 @@ +-- debug lsp +vim.lsp.set_log_level("debug") +require("vim.lsp.log").set_format_func(vim.inspect) + +-- nvim-autopairs +require("nvim-autopairs").setup() + +-- web-devicons +-- require("nvim-web-devicons").setup() + +-- gitsigns +require("gitsigns").setup() + +-- -- TODO: Clean this up +-- vim.api.nvim_create_autocmd({ "InsertEnter" }, { +-- callback = function() +-- vim.lsp.inlay_hint(0, true) +-- end, +-- }) +-- vim.api.nvim_create_autocmd({ "InsertLeave" }, { +-- callback = function() +-- vim.lsp.inlay_hint(0, true) +-- end, +-- }) + +-- lsp +require("mason").setup() +require("mason-lspconfig").setup() +require("mason-lspconfig").setup_handlers({ + -- The first entry (without a key) will be the default handler + -- and will be called for each installed server that doesn't have + -- a dedicated handler. + function(server_name) -- default handler (optional) + require("lspconfig")[server_name].setup({}) + end, + -- Next, you can provide a dedicated handler for specific servers. + -- For example, a handler override for the `rust_analyzer`: + -- ["rust_analyzer"] = function() + -- end, + -- lua_ls + -- ["lua_ls"] = function() + -- require("lspconfig").lua_ls.setup({ + -- settings = { + -- Lua = { + -- runtime = { + -- -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) + -- version = "LuaJIT", + -- }, + -- 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, + -- }, + -- }, + -- }, + -- }) + -- end, +}) + +-- typescript +-- require("typescript").setup({ +-- disable_commands = false, -- prevent the plugin from creating Vim commands +-- debug = false, -- enable debug logging for commands +-- go_to_source_definition = { +-- fallback = true, -- fall back to standard LSP definition on failure +-- }, +-- server = { +-- -- pass options to lspconfig's setup method +-- on_attach = function(client, bufnr) +-- vim.keymap.set("n", "rf", ":TypescriptRenameFile", { silent = true, buffer = bufnr }) +-- vim.keymap.set("n", "i", ":TypescriptAddMissingImports", { silent = true, buffer = bufnr }) +-- vim.keymap.set("n", "u", ":TypescriptRemoveUnused", { silent = true, buffer = bufnr }) +-- end, +-- }, +-- }) + +-- eslint +-- require("lspconfig").eslint.setup({ +-- on_attach = function(client, bufnr) +-- vim.keymap.set("n", "t", ":EslintFixAll", { silent = true, buffer = bufnr }) +-- end, +-- }) + +-- nullls +-- local null_ls = require("null-ls") +-- local lSsources = { +-- null_ls.builtins.formatting.prettier.with({ +-- filetypes = { +-- "javascript", +-- "typescript", +-- "css", +-- "scss", +-- "html", +-- "json", +-- "yaml", +-- "markdown", +-- "graphql", +-- "md", +-- "txt", +-- }, +-- only_local = "node_modules/.bin", +-- }), +-- null_ls.builtins.formatting.rustfmt, +-- null_ls.builtins.formatting.stylua, +-- } + +-- require("null-ls").setup({ +-- sources = lSsources, +-- on_attach = function(client, bufnr) +-- local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) +-- if client.supports_method("textDocument/formatting") then +-- vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) +-- vim.api.nvim_create_autocmd("BufWritePre", { +-- group = augroup, +-- buffer = bufnr, +-- callback = function() +-- vim.lsp.buf.format({ +-- bufnr = bufnr, +-- filter = function(client) +-- return client.name == "null-ls" +-- end, +-- }) +-- end, +-- }) +-- end +-- end, +-- }) + +-- nvim-cmp +vim.o.completeopt = "menu,menuone,noselect" +local cmp = require("cmp") + +-- local cmp_kinds = { +-- Text = " ", +-- Method = " ", +-- Function = " ", +-- Constructor = " ", +-- Field = " ", +-- Variable = " ", +-- Class = " ", +-- Interface = " ", +-- Module = " ", +-- Property = " ", +-- Unit = " ", +-- Value = " ", +-- Enum = " ", +-- Keyword = " ", +-- Snippet = " ", +-- Color = " ", +-- File = " ", +-- Reference = " ", +-- Folder = " ", +-- EnumMember = " ", +-- Constant = " ", +-- Struct = " ", +-- Event = " ", +-- Operator = " ", +-- TypeParameter = " ", +-- } + +cmp.setup({ + snippet = { + -- REQUIRED - you must specify a snippet engine + expand = function(args) + vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. + end, + }, + mapping = cmp.mapping.preset.insert({ + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({ + config = { + sources = { + { name = "nvim_lsp" }, + }, + }, + }), + -- [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ select = true }), + }), + sources = cmp.config.sources({ + { name = "nvim_lsp" }, + { name = "buffer", keyword_length = 3 }, + }), + -- formatting = { + -- format = function(_, vim_item) + -- vim_item.kind = (cmp_kinds[vim_item.kind] or "") .. vim_item.kind + -- return vim_item + -- end, + -- }, + preselect = "none", + completion = { + completeopt = "menu,menuone,noinsert,noselect", + }, +}) + +-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline("/", { + mapping = cmp.mapping.preset.cmdline(), + sources = { + { name = "buffer" }, + }, +}) + +-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). +cmp.setup.cmdline(":", { + mapping = cmp.mapping.preset.cmdline(), + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) + +-- Tree sitter +require("nvim-treesitter.configs").setup({ + ensure_installed = { "c", "cpp", "go", "lua", "markdown", "python", "rust", "tsx", "typescript", "vim" }, + highlight = { + enable = true, -- false will disable the whole extension + }, + indent = { + enable = true, + }, + rainbow = { + enable = true, + }, +}) + +-- Indent +-- vim.opt.list = true + +-- require("indent_blankline").setup({ +-- show_current_context = true, +-- }) + +-- Lualine +-- require("lualine").setup({ +-- options = { +-- section_separators = { left = "", right = "" }, +-- component_separators = { left = "", right = "" }, +-- }, +-- sections = { +-- lualine_c = { +-- { +-- "filename", +-- path = 1, +-- }, +-- }, +-- lualine_x = { +-- { +-- "filetype", +-- icon_only = true, +-- }, +-- }, +-- }, +-- inactive_sections = { +-- lualine_c = { +-- { +-- "filename", +-- path = 1, +-- }, +-- }, +-- }, +-- extensions = { "quickfix" }, +-- }) + +-- mini +-- require('mini.sessions').setup() +-- require('mini.starter').setup() +-- require("persisted").setup({ +-- save_dir = vim.fn.expand(vim.fn.stdpath("data") .. "/sessions/"), -- directory where session files are saved +-- silent = false, -- silent nvim message when sourcing session file +-- use_git_branch = true, -- create session files based on the branch of the git enabled repository +-- autosave = true, -- automatically save session files when exiting Neovim +-- should_autosave = nil, -- function to determine if a session should be autosaved +-- autoload = true, -- automatically load the session for the cwd on Neovim startup +-- on_autoload_no_session = nil, -- function to run when `autoload = true` but there is no session to load +-- follow_cwd = true, -- change session file name to match current working directory if it changes +-- allowed_dirs = nil, -- table of dirs that the plugin will auto-save and auto-load from +-- ignored_dirs = nil, -- table of dirs that are ignored when auto-saving and auto-loading +-- telescope = { -- options for the telescope extension +-- reset_prompt_after_deletion = true, -- whether to reset prompt after session deleted +-- }, +-- }) + +-- Telescope +local actions = require("telescope.actions") +local previewers = require("telescope.previewers") +local builtin = require("telescope.builtin") +require("telescope").setup({ + defaults = { + vimgrep_arguments = { + "rg", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + -- layout_config = { + -- horizontal = { + -- mirror = false, + -- }, + -- vertical = { + -- mirror = false, + -- }, + -- -- prompt_position = "top", + -- }, + -- file_sorter = require("telescope.sorters").get_fzy_sorter, + -- prompt_prefix = " 🔍 ", + -- color_devicons = true, + -- path_display = { "truncate" }, + + -- sorting_strategy = "ascending", + + -- file_previewer = require("telescope.previewers").vim_buffer_cat.new, + -- grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + -- qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + + -- mappings = { + -- i = { + -- [""] = false, + -- [""] = actions.move_selection_next, + -- [""] = actions.move_selection_previous, + -- [""] = actions.smart_send_to_qflist, + -- [""] = actions.cycle_previewers_next, + -- [""] = actions.cycle_previewers_prev, + -- [""] = actions.close, + -- }, + -- n = { + -- [""] = actions.cycle_previewers_next, + -- [""] = actions.cycle_previewers_prev, + -- }, + -- }, + -- }, + -- pickers = { + -- buffers = { + -- -- sort_mru = true, + -- ignore_current_buffer = true, + -- }, + -- git_files = { + -- git_command = { "git", "ls-files", "--exclude-standard", "--cached", "--others", "--deduplicate" }, + -- }, + -- }, + -- extensions = { + -- fzf = { + -- override_generic_sorter = false, + -- override_file_sorter = true, + -- case_mode = "smart_case", + -- }, + -- undo = { + -- side_by_side = true, + -- layout_config = { + -- preview_height = 0.8, + -- sorting_strategy = "descending", + -- }, + -- }, + }, +}) + +require("telescope").load_extension("fzf") +-- require("telescope").load_extension("ui-select") +-- require("telescope").load_extension("undo") +-- require("telescope").load_extension("file_browser") + +-- Disable underline +vim.diagnostic.config({ + virtual_text = true, + underline = false, +}) + +require('neogen').setup {} +vim.keymap.set('n', 'ne', ':lua require("neogen").generate()', { desc = '[G]enerate [D]ocumentation' }) + + + +-- Key bindings + +-- common lsp +vim.api.nvim_set_keymap("n", "gD", "lua vim.lsp.buf.declaration()", { silent = true }) +vim.api.nvim_set_keymap("n", "gd", "lua vim.lsp.buf.definition()", { silent = true }) +vim.api.nvim_set_keymap("n", "K", "lua vim.lsp.buf.hover()", { silent = true }) +vim.api.nvim_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", { silent = true }) +vim.api.nvim_set_keymap("n", "k", "lua vim.lsp.buf.signature_help()", { silent = true }) +vim.api.nvim_set_keymap("n", "wa", "lua vim.lsp.buf.add_workspace_folder()", { silent = true }) +vim.api.nvim_set_keymap("n", "wr", "lua vim.lsp.buf.remove_workspace_folder()", { silent = true }) +vim.api.nvim_set_keymap("n", "t", "lua vim.lsp.buf.format()", { silent = true }) +vim.api.nvim_set_keymap( + "n", + "wl", + "lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))", + { silent = true } +) +vim.api.nvim_set_keymap("n", "D", "lua vim.lsp.buf.type_definition()", { silent = true }) +vim.api.nvim_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", { silent = true }) +vim.api.nvim_set_keymap("n", "ca", "lua vim.lsp.buf.code_action()", { silent = true }) +vim.api.nvim_set_keymap("n", "e", "lua vim.diagnostic.open_float()", { silent = true }) +vim.api.nvim_set_keymap("n", "[d", "lua vim.diagnostic.goto_prev()", { silent = true }) +vim.api.nvim_set_keymap("n", "]d", "lua vim.diagnostic.goto_next()", { silent = true }) +vim.api.nvim_set_keymap("n", "", "Lspsaga peek_definition", { silent = true }) + +-- nvim tree +-- vim.api.nvim_set_keymap("n", "f", "NvimTreeToggle", { noremap = true, silent = true }) + +-- Telescope +-- vim.api.nvim_set_keymap("n", "fF", "Telescope file_browser", { noremap = true, silent = true }) +-- vim.api.nvim_set_keymap( +-- "n", +-- "ff", +-- "Telescope file_browser path=%:p:h select_buffer=true", +-- { noremap = true } +-- ) +-- vim.api.nvim_set_keymap("n", "fg", "lua require'telescope-config'.project_files()", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope find_files", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope buffers", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope live_grep", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope grep_string", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope git_bcommits", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope lsp_references", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "Telescope resume", { noremap = true }) +-- vim.api.nvim_set_keymap("n", "", "lua vim.lsp.buf.code_action()", { noremap = true }) diff --git a/lua/telescope-config.lua b/lua/telescope-config.lua new file mode 100644 index 0000000..3777928 --- /dev/null +++ b/lua/telescope-config.lua @@ -0,0 +1,23 @@ +local telescope = require('telescope') +local lga_actions = require("telescope-live-grep-args.actions") +local builtin = require('telescope.builtin') +local live_grep_args_shortcuts = require("telescope-live-grep-args.shortcuts") + +telescope.setup { + defaults = { + mappings = { + i = { + [''] = false, + [''] = false, + [""] = lga_actions.quote_prompt(), + }, + }, + }, +} +telescope.load_extension("live_grep_args") + +vim.keymap.set('n', 'pf', builtin.find_files, {noremap = true}) +vim.keymap.set("n", "pg", telescope.extensions.live_grep_args.live_grep_args) +vim.keymap.set('n', 'lg', builtin.live_grep, {noremap = true}) + +vim.keymap.set("n", "pw", live_grep_args_shortcuts.grep_word_under_cursor) diff --git a/lua/utils.lua b/lua/utils.lua new file mode 100644 index 0000000..e30511c --- /dev/null +++ b/lua/utils.lua @@ -0,0 +1,27 @@ +local M = {} + +M.map = function(mode, shortcut, command) + vim.keymap.set(mode, shortcut, command, { noremap = true, silent = true }) +end + +M.nmap = function(shortcut, command) + M.map("n", shortcut, command) +end + +M.imap = function(shortcut, command) + M.map("i", shortcut, command) +end + +M.vmap = function(shortcut, command) + M.vap("t", shortcut, command) +end + +M.nvmap = function(shortcut, command) + M.map({ "n", "v" }, shortcut, command) +end + +M.tmap = function(shortcut, command) + M.map("t", shortcut, command) +end + +return M