From cbd87b0b114c91fcc7290f1174cc1a91df683324 Mon Sep 17 00:00:00 2001 From: rattatwinko Date: Thu, 12 Jun 2025 10:53:18 +0200 Subject: [PATCH] fixed autocompletion and added some shit --- README.md | 142 +++++++++++++++++++++++++------------------- init.lua | 174 +++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 201 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 313030f..0f86581 100644 --- a/README.md +++ b/README.md @@ -1,67 +1,89 @@ -🚀 GENERAL KEYBINDS: - e - Show diagnostic float - [d / ]d - Navigate diagnostics - n - Toggle file explorer (Neo-tree) - ff - Find files (Telescope) - fg - Live grep (Telescope) - gs - Git status (Fugitive) - gg - Open LazyGit +# 🚀 General Keybinds -📝 EDITING: - gd - Go to definition - gr - Find references - K - Hover documentation - rn - Rename symbol - - Next completion item - - Previous completion item - - Confirm completion - - Trigger completion - ( - Auto-complete parentheses +- `e` - Show diagnostic float +- `[d` / `]d` - Navigate diagnostics +- `n` - Toggle file explorer (Neo-tree) +- `ff` - Find files (Telescope) +- `fg` - Live grep (Telescope) +- `gs` - Git status (Fugitive) +- `gg` - Open LazyGit -🌲 NEO-TREE: - o / - Open file - t - Open in new tab - v - Open in vertical split - s - Open in horizontal split - r - Rename - d - Delete - a - Add file - A - Add directory - R - Refresh - . - Toggle hidden files +--- -🔭 TELESCOPE: - / - Next/previous item - / - Move selection - - Open in new tab - - Open in vertical split - - Open in horizontal split - - Clear prompt - - Close telescope +# 📝 Editing -💻 LSP: - d - Show diagnostics - ca - Code actions - f - Format file - wa - Add workspace folder - wr - Remove workspace folder - wl - List workspace folders +- `gd` - Go to definition +- `gr` - Find references +- `K` - Hover documentation +- `rn` - Rename symbol +- `` - Next completion item +- `` - Previous completion item +- `` - Confirm completion +- `` - Trigger completion +- `(` - Auto-complete parentheses -💾 BUFFER MANAGEMENT: - bd - Delete buffer - bn - Next buffer - bp - Previous buffer - bl - List buffers +--- -🐱 GIT: - gc - Git commit - gp - Git push - gl - Git log - gd - Git diff - gb - Git blame +# 🌲 Neo-tree -🔄 TERMINAL: - - Toggle terminal - - Exit terminal mode - tt - New terminal - tf - New floating terminal +- `o` / `` - Open file +- `t` - Open in new tab +- `v` - Open in vertical split +- `s` - Open in horizontal split +- `r` - Rename +- `d` - Delete +- `a` - Add file +- `A` - Add directory +- `R` - Refresh +- `.` - Toggle hidden files + +--- + +# 🔭 Telescope + +- `` / `` - Next/previous item +- `` / `` - Move selection +- `` - Open in new tab +- `` - Open in vertical split +- `` - Open in horizontal split +- `` - Clear prompt +- `` - Close telescope + +--- + +# 💻 LSP + +- `d` - Show diagnostics +- `ca` - Code actions +- `f` - Format file +- `wa` - Add workspace folder +- `wr` - Remove workspace folder +- `wl` - List workspace folders + +--- + +# 💾 Buffer Management + +- `bd` - Delete buffer +- `bn` - Next buffer +- `bp` - Previous buffer +- `bl` - List buffers + +--- + +# 🐱 Git + +- `gc` - Git commit +- `gp` - Git push +- `gl` - Git log +- `gd` - Git diff +- `gb` - Git blame + +--- + +# 🔄 Terminal + +- `` - Toggle terminal +- `` - Exit terminal mode +- `tt` - New terminal +- `tf` - New floating terminal diff --git a/init.lua b/init.lua index 5144298..d871488 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,5 @@ -- ~/.config/nvim/init.lua --- Complete VSCode-like Neovim Config with Enhanced Tab Completion +-- Complete VSCode-like Neovim Config with All Requested Keybindings -- ====================== -- 1. Basic Configuration @@ -7,7 +7,7 @@ vim.g.mapleader = " " vim.g.maplocalleader = " " --- Optimized Editor Settings +-- Editor Settings (unchanged from previous) vim.opt.number = true vim.opt.relativenumber = true vim.opt.mouse = "a" @@ -58,7 +58,7 @@ vim.opt.rtp:prepend(lazypath) -- 3. Plugin Specifications -- ====================== local plugins = { - -- Theme + -- Theme (unchanged) { "drewtempelmeyer/palenight.vim", priority = 1000, @@ -76,7 +76,7 @@ local plugins = { }, -- Fuzzy Finder - { "nvim-telescope/telescope.nvim", branch = "0.1.x", dependencies = { "nvim-lua/plenary.nvim" } }, + { "nvim-telescope/telescope.nvim", dependencies = { "nvim-lua/plenary.nvim" } }, -- LSP Configuration { @@ -104,6 +104,35 @@ local plugins = { }, }, + -- Auto Pairs + { + "windwp/nvim-autopairs", + event = "InsertEnter", + config = function() + require("nvim-autopairs").setup({ + check_ts = true, + ts_config = { + lua = { "string", "source" }, + javascript = { "string", "template_string" }, + typescript = { "string", "template_string" }, + }, + disable_filetype = { "TelescopePrompt", "spectre_panel" }, + fast_wrap = { + map = "", + chars = { "{", "[", "(", '"', "'", "<" }, + pattern = [=[[%'%"%)%>%]%)%}%,]]=], + end_key = "$", + highlight = "Search", + highlight_grey = "Comment", + }, + }) + + local cmp_autopairs = require("nvim-autopairs.completion.cmp") + local cmp = require("cmp") + cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done()) + end, + }, + -- Git Integration { "lewis6991/gitsigns.nvim", opts = {} }, { "tpope/vim-fugitive" }, @@ -117,11 +146,10 @@ local plugins = { -- Syntax & Editing { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate" }, - { "windwp/nvim-autopairs", event = "InsertEnter" }, { "numToStr/Comment.nvim", opts = {} }, -- Productivity - { "akinsho/toggleterm.nvim", version = "*" }, + { "akinsho/toggleterm.nvim", version = "*", config = true }, { "folke/which-key.nvim", event = "VimEnter" }, { "stevearc/conform.nvim" }, { "mfussenegger/nvim-lint", event = { "BufReadPre", "BufNewFile" } }, @@ -150,7 +178,7 @@ require("lazy").setup(plugins, { }, }) --- Neo-tree Configuration +-- Neo-tree Configuration with Keymaps require("neo-tree").setup({ close_if_last_window = false, popup_border_style = "rounded", @@ -159,48 +187,57 @@ require("neo-tree").setup({ filesystem = { follow_current_file = { enabled = true }, hijack_netrw_behavior = "open_current", + use_libuv_file_watcher = true, }, window = { - position = "left", + position = "right", width = 30, - mappings = { [""] = "none" }, + mappings = { + [""] = "none", -- disable space as it's our leader key + ["o"] = "open", + [""] = "open", + ["t"] = "open_tabnew", + ["v"] = "open_vsplit", + ["s"] = "open_split", + ["r"] = "rename", + ["d"] = "delete", + ["a"] = "add", + ["A"] = "add_directory", + ["R"] = "refresh", + ["."] = "toggle_hidden", + }, }, }) --- Telescope Configuration +-- Telescope Configuration with Keymaps require("telescope").setup({ defaults = { mappings = { i = { - [""] = false, - [""] = false, + [""] = "move_selection_next", + [""] = "move_selection_previous", + [""] = "move_selection_next", + [""] = "move_selection_previous", + [""] = "select_tab", + [""] = "select_vertical", + [""] = "select_horizontal", + [""] = "clear_prompt", + [""] = "close", }, }, }, }) --- LSP Setup with Enhanced Completion +-- LSP Setup local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) capabilities.textDocument.completion.completionItem.snippetSupport = true -capabilities.textDocument.completion.completionItem.resolveSupport = { - properties = { "documentation", "detail", "additionalTextEdits" }, -} require("mason").setup() require("mason-lspconfig").setup({ ensure_installed = { - "lua_ls", - "pyright", - "ruff", - "ts_ls", - "html", - "cssls", - "tailwindcss", - "bashls", - "jsonls", - "yamlls", - "dockerls", + "lua_ls", "pyright", "ruff", "tsserver", "html", "cssls", + "tailwindcss", "bashls", "jsonls", "yamlls", "dockerls" }, }) @@ -210,19 +247,20 @@ lspconfig.lua_ls.setup({ settings = { Lua = { completion = { callSnippet = "Replace" }, + diagnostics = { globals = { "vim" } }, + workspace = { checkThirdParty = false }, + telemetry = { enable = false }, }, }, }) --- Configure other LSP servers similarly -for _, server in ipairs({ "pyright", "ts_ls", "html", "cssls" }) do +for _, server in ipairs({ "pyright", "tsserver", "html", "cssls", "bashls", "jsonls" }) do lspconfig[server].setup({ capabilities = capabilities }) end --- Advanced Completion Setup +-- Completion Setup local cmp = require("cmp") local luasnip = require("luasnip") - require("luasnip.loaders.from_vscode").lazy_load() local has_words_before = function() @@ -260,7 +298,10 @@ cmp.setup({ end end, { "i", "s" }), - [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping.confirm({ + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }), [""] = cmp.mapping.complete(), }), sources = cmp.config.sources({ @@ -269,41 +310,54 @@ cmp.setup({ { name = "path" }, { name = "buffer" }, }), - formatting = { - format = function(entry, item) - item.menu = ({ - nvim_lsp = "[LSP]", - luasnip = "[Snippet]", - buffer = "[Buffer]", - path = "[Path]", - })[entry.source.name] - return item - end, - }, }) -- ====================== -- 5. Key Mappings -- ====================== --- Navigation + +-- 🚀 General Keybinds vim.keymap.set("n", "e", vim.diagnostic.open_float) vim.keymap.set("n", "[d", vim.diagnostic.goto_prev) vim.keymap.set("n", "]d", vim.diagnostic.goto_next) - --- File Management vim.keymap.set("n", "n", ":Neotree toggle") vim.keymap.set("n", "ff", ":Telescope find_files") vim.keymap.set("n", "fg", ":Telescope live_grep") +vim.keymap.set("n", "gs", ":Git") +vim.keymap.set("n", "gg", ":LazyGit") --- LSP +-- 📝 Editing vim.keymap.set("n", "gd", vim.lsp.buf.definition) vim.keymap.set("n", "gr", vim.lsp.buf.references) vim.keymap.set("n", "K", vim.lsp.buf.hover) vim.keymap.set("n", "rn", vim.lsp.buf.rename) --- Git -vim.keymap.set("n", "gs", ":Git") -vim.keymap.set("n", "gg", ":LazyGit") +-- 💻 LSP +vim.keymap.set("n", "d", vim.diagnostic.setloclist) +vim.keymap.set("n", "ca", vim.lsp.buf.code_action) +vim.keymap.set("n", "f", function() vim.lsp.buf.format({ async = true }) end) +vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder) +vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder) +vim.keymap.set("n", "wl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end) + +-- 💾 Buffer Management +vim.keymap.set("n", "bd", ":bdelete") +vim.keymap.set("n", "bn", ":bnext") +vim.keymap.set("n", "bp", ":bprevious") +vim.keymap.set("n", "bl", ":Telescope buffers") + +-- 🐱 Git +vim.keymap.set("n", "gc", ":Git commit") +vim.keymap.set("n", "gp", ":Git push") +vim.keymap.set("n", "gl", ":Telescope git_commits") +vim.keymap.set("n", "gd", ":Gdiff") +vim.keymap.set("n", "gb", ":Git blame") + +-- 🔄 Terminal +vim.keymap.set("t", "", "") -- Escape terminal mode +vim.keymap.set("t", "", "") -- Alternative escape +vim.keymap.set("n", "tt", ":ToggleTerm") +vim.keymap.set("n", "tf", ":ToggleTerm direction=float") -- ====================== -- 6. Autocommands @@ -322,8 +376,18 @@ vim.api.nvim_create_autocmd("BufWritePre", { end, }) -print("🚀 Neovim configuration fully loaded with:") -print(" - VSCode-like tab completion") -print(" - Enhanced LSP support") -print(" - Git integration") -print(" - Beautiful UI components") +-- Enable treesitter +require("nvim-treesitter.configs").setup({ + ensure_installed = { "lua", "python", "javascript", "typescript", "html", "css", "bash", "json", "yaml" }, + highlight = { enable = true }, + indent = { enable = true }, +}) + +-- ====================== +-- 7. Final Setup +-- ====================== +print("🚀 Neovim configuration fully loaded with all keybindings:") +print(" - General navigation and file management") +print(" - Advanced editing and LSP features") +print(" - Complete Git integration") +print(" - Terminal and buffer management")