Repository: tjdevries/advent-of-nvim Branch: master Commit: 13d4ec68a2a8 Files: 27 Total size: 22.9 KB Directory structure: gitextract_ro4vkjfw/ ├── 01 - Introduction/ │ └── 01 - Introduction.md ├── 02 - Tutor and Modal Editing/ │ └── 02 - Tutor and Modal Editing.md ├── 03 - Lua Crash Course/ │ ├── 03 - Lua Crash Course.md │ └── init.lua ├── 04 - Package Manager/ │ ├── Package Manager.md │ └── init.lua ├── Makefile ├── README.md ├── XX - oil/ │ ├── Oil.md │ └── config/ │ ├── init.lua │ ├── lazy-lock.json │ └── lua/ │ └── config/ │ ├── lazy.lua │ └── plugins/ │ ├── mini.lua │ └── oil.lua └── nvim/ ├── after/ │ └── ftplugin/ │ └── lua.lua ├── init.lua ├── lazy-lock.json ├── lua/ │ └── config/ │ ├── lazy.lua │ ├── plugins/ │ │ ├── completion.lua │ │ ├── lsp.lua │ │ ├── mini.lua │ │ ├── oil.lua │ │ ├── telescope.lua │ │ └── treesitter.lua │ └── telescope/ │ └── multigrep.lua └── plugin/ ├── floaterminal.lua └── menu.lua ================================================ FILE CONTENTS ================================================ ================================================ FILE: 01 - Introduction/01 - Introduction.md ================================================ # Introduction to Neovim ## Why Do I Use Neovim? ## Why Do I Use Neovim? - I find it very satisfying to make things just the way I like - It makes my day more fun - both hacking on it and eliminating frustrations - I like modal editing - it clicks with my brain. ## How to Use Neovim? - Download and/or Package Manager: - https://neovim.io/doc/ - Build From Source: - https://github.com/neovim/neovim/blob/master/BUILD.md ## First Configuration: - Open `$HOME/.config/nvim/init.lua` - `print("Hello World")` in `init.lua` - Re-open Neovim, check `:messages` ## Reload Configuration: - `:source %` - `:lua ...` or `:'<,'>lua` ================================================ FILE: 02 - Tutor and Modal Editing/02 - Tutor and Modal Editing.md ================================================ # Vim Tutor: Explained ## First - You have to actually practice - Don't just listen to me ## How to practice? Open Neovim. `:Tutor` ## How to practice? > But it's confusing?! Ok, I will do it with you :) ================================================ FILE: 03 - Lua Crash Course/03 - Lua Crash Course.md ================================================ # Lua Crash Course ## Table of Contents - Comments - Variables - Control Flow - Modules - Functions - Metatables - Bonus :) ## Background Info Lua is elegant - Lua uses "Mechanisms over Policies" - Lua is designed to be embedded - Lua is cool ## Comments ```lua -- This is a comment. It starts with two dashes --[[ This is also a comment. But it spans multiple lines! --]] ``` ## Variables: Simple Literals ```lua local number = 5 local string = "hello, world" local single = 'also works' local crazy = [[ This is multi line and literal ]] local truth, lies = true, false local nothing = nil ``` ## Variables: Functions ```lua local function hello(name) print("Hello!", name) end local greet = function(name) -- .. is string concatenation print("Greetings, " .. name .. "!") end ``` ## Variables: Functions ```lua local higher_order = function(value) return function(another) return value + another end end local add_one = higher_order(1) print("add_one(2) -> ", add_one(2)) ``` ## Variables: Tables Effectively, Lua's only data structure. - Same structure is used for maps & lists ## Variables: Tables As a list... ```lua local list = { "first", 2, false, function() print("Fourth!") end } print("Yup, 1-indexed:", list[1]) print("Fourth is 4...:", list[4]()) ``` ## Variables: Tables As a map... ```lua local t = { literal_key = "a string", ["an expression"] = "also works", [function() end] = true } print("literal_key : ", t.literal_key) print("an expression : ", t["an expression"]) print("function() end: ", t[function() end]) ``` ## Variables: Not Covered - Thread - Userdata ## Control Flow: `for` ```lua local favorite_accounts = { "teej_dv", "ThePrimeagen", "terminaldotshop" } for index = 1, #favorite_accounts do print(index, favorite_accounts[index]) end for index, value in ipairs(favorite_accounts) do print(index, value) end ``` ## Control Flow: `for` ```lua local reading_scores = { teej_dv = 10, ThePrimeagen = "N/A" } for index = 1, #reading_scores do print(reading_scores[index]) end ``` Doesn't Print Anything - the "length" of the array is 0. We aren't using it as an array, we're using it as a map! ## Control Flow: `for` ```lua local reading_scores = { teej_dv = 9.5, ThePrimeagen = "N/A" } for key, value in pairs(reading_scores) do print(key, value) end ``` ## Control Flow: `if` ```lua local function action(loves_coffee) if loves_coffee then print("Check out `ssh terminal.shop` - it's cool!") else print("Check out `ssh terminal.shop` - it's still cool!") end end -- "falsey": nil, false action() -- Same as: action(nil) action(false) -- Everything else is "truthy" action(true) action(0) action({}) ``` ## Modules There isn't anything special about modules. Modules are just files! ```lua -- foo.lua local M = {} M.cool_function = function() end return M ``` ```lua -- bar.lua local foo = require('foo') foo.cool_function() ``` ## Functions: Multiple Returns ```lua local returns_four_values = function() return 1, 2, 3, 4 end first, second, last = returns_four_values() print("first: ", first) print("second:", second) print("last: ", last) -- the `4` is discarded :'( ``` ## Functions: Multiple Returns ```lua local variable_arguments = function(...) local arguments = { ... } for i, v in ipairs({...}) do print(i, v) end return unpack(arguments) end print("===================") print("1:", variable_arguments("hello", "world", "!")) print("===================") print("2:", variable_arguments("hello", "world", "!"), "") ``` ## Functions: Calling String Shorthand ```lua local single_string = function(s) return s .. " - WOW!" end local x = single_string("hi") local y = single_string "hi" print(x, y) ``` ## Functions: Calling Table Shorthand ```lua local setup = function(opts) if opts.default == nil then opts.default = 17 end print(opts.default, opts.other) end setup { default = 12, other = false} setup { other = true} ``` ## Functions: Colon Functions ```lua local MyTable = {} function MyTable.something(self, ...) end function MyTable:something(...) end ``` ## Metatables ```lua local vector_mt = {} vector_mt.__add = function(left, right) return setmetatable({ left[1] + right[1], left[2] + right[2], left[3] + right[3], }, vector_mt) end local v1 = setmetatable({ 3, 1, 5 }, vector_mt) local v2 = setmetatable({ -3, 2, 2 }, vector_mt) local v3 = v1 + v2 vim.print(v3[1], v3[2], v3[3]) vim.print(v3 + v3) ``` ## Metatables ```lua local fib_mt = { __index = function(self, key) if key < 2 then return 1 end -- Update the table, to save the intermediate results self[key] = self[key - 2] + self[key - 1] -- Return the result return self[key] end } local fib = setmetatable({}, fib_mt) print(fib[5]) print(fib[1000]) ``` ## Metatables Other notable fields: - `__newindex(self, key, value)` - `__call(self, ...)` ## Quick Neovim Goodies ```lua vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") ``` ## Quick Neovim Goodies ```lua -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), callback = function() vim.highlight.on_yank() end, }) ``` ================================================ FILE: 03 - Lua Crash Course/init.lua ================================================ -- Day 3 print("advent of neovim") vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking (copying) text", group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }), callback = function() vim.highlight.on_yank() end, }) ================================================ FILE: 04 - Package Manager/Package Manager.md ================================================ # Package Manager ## Package Manager Going to use `lazy.nvim` - https://lazy.folke.io/installation NOTE: which is different from LazyVim ## Install (follow instructions) `:checkhealth lazy` ## Install a colorscheme - Tokyo Night Color Scheme - https://github.com/folke/tokyonight.nvim ```lua { "folke/tokyonight.nvim", config = function() vim.cmd.colorscheme "tokyonight" end } ``` ## Install `mini` - Mini.nvim - https://github.com/echasnovski/mini.nvim - Setup statusline ```lua -- lua/custom/plugins/mini.lua return { { 'echasnovski/mini.nvim', config = function() local statusline = require 'mini.statusline' statusline.setup { use_icons = true } end } } ``` ================================================ FILE: 04 - Package Manager/init.lua ================================================ print("advent of neovim") print("advent of neovim") vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), callback = function() vim.highlight.on_yank() end, }) ================================================ FILE: Makefile ================================================ update: rm -rf ./nvim mkdir nvim cp -rf ~/.config/nvimexample/* ./nvim/ ================================================ FILE: README.md ================================================ # Advent of `nvim` Check the config in: `./nvim/` - This should be versioned roughly by day, so you can go back and check how each day was made. - You likely could copy this into `~/.config/` to get the same config as in the video, but I make no guarantees about that. 25 Mini Lessons to get started with Neovim. - We'll build a working configuration that resembles kickstart.nvim, but we'll do it completely from scratch. - [x] Install Neovim and Open (with some reasons why) - [x] Tutor / Modal Editing - [x] Lua Configuration (Options / Keymaps) - [x] Plugin Manager - [x] Filetype configuration - `tree-sitter` - [x] LSP (Keymaps and Settings) - [x] Autoformat - [x] Telescope - [x] Advanced Telescope: multi-ripgrep - [x] Window Navigation - [x] Quickfix: `:cdo` and others - [x] Terminal (Escape, Floating, Usages) - [x] Autocomplete - [x] Oil.nvim - Longer video: https://youtu.be/218PFRsvu2o?si=l8UFf2Z7YdUKU0KJ - [x] Mouse Menu LOL - LSP Installation / Management - Snippets - text-objects: `mini.*` - Tree-sitter: text-objects - Language Configuration - Clipboard ================================================ FILE: XX - oil/Oil.md ================================================ ================================================ FILE: XX - oil/config/init.lua ================================================ print("advent of neovim") require("config.lazy") vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd('TextYankPost', { desc = 'Highlight when yanking (copying) text', group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), callback = function() vim.highlight.on_yank() end, }) ================================================ FILE: XX - oil/config/lazy-lock.json ================================================ { "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, "mini.nvim": { "branch": "main", "commit": "690a3b4c78c4956f7ecf770124b522d32084b872" }, "tokyonight.nvim": { "branch": "main", "commit": "15d83cda572d7498b43bbdaa223bc75bf341183e" } } ================================================ FILE: XX - oil/config/lua/config/lazy.lua ================================================ -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, { out, "WarningMsg" }, { "\nPress any key to exit..." }, }, true, {}) vim.fn.getchar() os.exit(1) end end -- Hey! Put lazy into the runtimepath for neovim! vim.opt.runtimepath:prepend(lazypath) -- Make sure to setup `mapleader` and `maplocalleader` before -- loading lazy.nvim so that mappings are correct. -- This is also a good place to setup other settings (vim.opt) vim.g.mapleader = " " vim.g.maplocalleader = "\\" -- Setup lazy.nvim require("lazy").setup({ spec = { { "folke/tokyonight.nvim", config = function() vim.cmd.colorscheme "tokyonight" end }, { import = "config.plugins" }, }, }) ================================================ FILE: XX - oil/config/lua/config/plugins/mini.lua ================================================ -- lua/custom/plugins/mini.lua return { { 'echasnovski/mini.nvim', enabled = true, config = function() local statusline = require 'mini.statusline' statusline.setup { use_icons = true } end }, } ================================================ FILE: XX - oil/config/lua/config/plugins/oil.lua ================================================ return { { "stevearc/oil.nvim", dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() require("oil").setup({ columns = { "icon" }, keymaps = { [""] = false, [""] = false, [""] = false, [""] = false, [""] = "actions.select_split", }, view_options = { show_hidden = true }, }) -- Open parent directory in current window vim.keymap.set("n", "-", "Oil", { desc = "Open parent directory" }) end, }, } ================================================ FILE: nvim/after/ftplugin/lua.lua ================================================ local set = vim.opt_local set.shiftwidth = 2 set.number = true set.relativenumber = true ================================================ FILE: nvim/init.lua ================================================ print("advent of neovim") require("config.lazy") vim.opt.shiftwidth = 4 vim.opt.clipboard = "unnamedplus" vim.opt.number = true vim.opt.relativenumber = true vim.keymap.set("n", "x", "source %") vim.keymap.set("n", "x", ":.lua") vim.keymap.set("v", "x", ":lua") vim.keymap.set("n", "", "cnext") vim.keymap.set("n", "", "cprev") -- Highlight when yanking (copying) text -- Try it with `yap` in normal mode -- See `:help vim.highlight.on_yank()` vim.api.nvim_create_autocmd("TextYankPost", { desc = "Highlight when yanking (copying) text", group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { clear = true }), callback = function() vim.highlight.on_yank() end, }) vim.api.nvim_create_autocmd("TermOpen", { group = vim.api.nvim_create_augroup("custom-term-open", { clear = true }), callback = function() vim.opt.number = false vim.opt.relativenumber = false end, }) local job_id = 0 vim.keymap.set("n", "to", function() vim.cmd.vnew() vim.cmd.term() vim.cmd.wincmd("J") vim.api.nvim_win_set_height(0, 5) job_id = vim.bo.channel end) local current_command = "" vim.keymap.set("n", "te", function() current_command = vim.fn.input("Command: ") end) vim.keymap.set("n", "tr", function() if current_command == "" then current_command = vim.fn.input("Command: ") end vim.fn.chansend(job_id, { current_command .. "\r\n" }) end) vim.keymap.set("n", "-", "Oil") ================================================ FILE: nvim/lazy-lock.json ================================================ { "blink.cmp": { "branch": "main", "commit": "ae5a4ce8f7e519e49de7ae6fcadd74547f820a52" }, "friendly-snippets": { "branch": "main", "commit": "efff286dd74c22f731cdec26a70b46e5b203c619" }, "lazy.nvim": { "branch": "main", "commit": "7e6c863bc7563efbdd757a310d17ebc95166cef3" }, "lazydev.nvim": { "branch": "main", "commit": "f59bd14a852ca43db38e3662395354cb2a9b13e0" }, "mini.icons": { "branch": "main", "commit": "44c0160526f7ae17ca8e8eab9ab235d047fcf7a6" }, "mini.nvim": { "branch": "main", "commit": "7ebfab26d77a4b9b05aaae565907e7fa4b2ee154" }, "nvim-lspconfig": { "branch": "master", "commit": "9f2c279cf9abe584f03bfeb37c6658d68e3ff49d" }, "nvim-treesitter": { "branch": "master", "commit": "981ca7e353da6ea69eaafe4348fda5e800f9e1d8" }, "oil.nvim": { "branch": "master", "commit": "dba037598843973b8c54bc5ce0318db4a0da439d" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "dae2eac9d91464448b584c7949a31df8faefec56" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "tokyonight.nvim": { "branch": "main", "commit": "45d22cf0e1b93476d3b6d362d720412b3d34465c" } } ================================================ FILE: nvim/lua/config/lazy.lua ================================================ -- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = "https://github.com/folke/lazy.nvim.git" local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) if vim.v.shell_error ~= 0 then vim.api.nvim_echo({ { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, { out, "WarningMsg" }, { "\nPress any key to exit..." }, }, true, {}) vim.fn.getchar() os.exit(1) end end -- Hey! Put lazy into the runtimepath for neovim! vim.opt.runtimepath:prepend(lazypath) -- Make sure to setup `mapleader` and `maplocalleader` before -- loading lazy.nvim so that mappings are correct. -- This is also a good place to setup other settings (vim.opt) vim.g.mapleader = " " vim.g.maplocalleader = "\\" -- Setup lazy.nvim require("lazy").setup({ spec = { { "folke/tokyonight.nvim", config = function() vim.cmd.colorscheme "tokyonight" end }, { import = "config.plugins" }, }, change_detection = { -- automatically check for config file changes and reload the ui enabled = false, notify = false, -- get a notification when changes are found }, }) ================================================ FILE: nvim/lua/config/plugins/completion.lua ================================================ return { { 'saghen/blink.cmp', dependencies = 'rafamadriz/friendly-snippets', version = 'v0.*', opts = { keymap = { preset = 'default' }, appearance = { use_nvim_cmp_as_default = true, nerd_font_variant = 'mono' }, signature = { enabled = true } }, }, } ================================================ FILE: nvim/lua/config/plugins/lsp.lua ================================================ return { { "neovim/nvim-lspconfig", dependencies = { 'saghen/blink.cmp', { "folke/lazydev.nvim", opts = { library = { { path = "${3rd}/luv/library", words = { "vim%.uv" } }, }, }, }, }, config = function() local capabilities = require('blink.cmp').get_lsp_capabilities() require("lspconfig").lua_ls.setup { capabilites = capabilities } vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local c = vim.lsp.get_client_by_id(args.data.client_id) if not c then return end if vim.bo.filetype == "lua" then -- Format the current buffer on save vim.api.nvim_create_autocmd('BufWritePre', { buffer = args.buf, callback = function() vim.lsp.buf.format({ bufnr = args.buf, id = c.id }) end, }) end end, }) end, } } ================================================ FILE: nvim/lua/config/plugins/mini.lua ================================================ -- lua/custom/plugins/mini.lua return { { 'echasnovski/mini.nvim', enabled = true, config = function() local statusline = require 'mini.statusline' statusline.setup { use_icons = true } end }, } ================================================ FILE: nvim/lua/config/plugins/oil.lua ================================================ return { { 'stevearc/oil.nvim', ---@module 'oil' ---@type oil.SetupOpts opts = {}, -- Optional dependencies dependencies = { { "echasnovski/mini.icons", opts = {} } }, -- dependencies = { "nvim-tree/nvim-web-devicons" }, -- use if prefer nvim-web-devicons } } ================================================ FILE: nvim/lua/config/plugins/telescope.lua ================================================ return { { 'nvim-telescope/telescope.nvim', tag = '0.1.8', dependencies = { 'nvim-lua/plenary.nvim', { 'nvim-telescope/telescope-fzf-native.nvim', build = 'make' } }, config = function() require('telescope').setup { pickers = { find_files = { theme = "ivy" } }, extensions = { fzf = {} } } require('telescope').load_extension('fzf') vim.keymap.set("n", "fh", require('telescope.builtin').help_tags) vim.keymap.set("n", "fd", require('telescope.builtin').find_files) vim.keymap.set("n", "en", function() require('telescope.builtin').find_files { cwd = vim.fn.stdpath("config") } end) vim.keymap.set("n", "ep", function() require('telescope.builtin').find_files { cwd = vim.fs.joinpath(vim.fn.stdpath("data"), "lazy") } end) require "config.telescope.multigrep".setup() end } } ================================================ FILE: nvim/lua/config/plugins/treesitter.lua ================================================ return { { "nvim-treesitter/nvim-treesitter", build = ":TSUpdate", config = function() require'nvim-treesitter.configs'.setup { ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline" }, auto_install = false, highlight = { enable = true, 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, additional_vim_regex_highlighting = false, }, } end, } } ================================================ FILE: nvim/lua/config/telescope/multigrep.lua ================================================ local pickers = require "telescope.pickers" local finders = require "telescope.finders" local make_entry = require "telescope.make_entry" local conf = require "telescope.config".values local M = {} local live_multigrep = function(opts) opts = opts or {} opts.cwd = opts.cwd or vim.uv.cwd() local finder = finders.new_async_job { command_generator = function(prompt) if not prompt or prompt == "" then return nil end local pieces = vim.split(prompt, " ") local args = { "rg" } if pieces[1] then table.insert(args, "-e") table.insert(args, pieces[1]) end if pieces[2] then table.insert(args, "-g") table.insert(args, pieces[2]) end ---@diagnostic disable-next-line: deprecated return vim.tbl_flatten { args, { "--color=never", "--no-heading", "--with-filename", "--line-number", "--column", "--smart-case" }, } end, entry_maker = make_entry.gen_from_vimgrep(opts), cwd = opts.cwd, } pickers.new(opts, { debounce = 100, prompt_title = "Multi Grep", finder = finder, previewer = conf.grep_previewer(opts), sorter = require("telescope.sorters").empty(), }):find() end M.setup = function() vim.keymap.set("n", "fg", live_multigrep) end return M ================================================ FILE: nvim/plugin/floaterminal.lua ================================================ vim.keymap.set("t", "", "") local state = { floating = { buf = -1, win = -1, } } local function create_floating_window(opts) opts = opts or {} local width = opts.width or math.floor(vim.o.columns * 0.8) local height = opts.height or math.floor(vim.o.lines * 0.8) -- Calculate the position to center the window local col = math.floor((vim.o.columns - width) / 2) local row = math.floor((vim.o.lines - height) / 2) -- Create a buffer local buf = nil if vim.api.nvim_buf_is_valid(opts.buf) then buf = opts.buf else buf = vim.api.nvim_create_buf(false, true) -- No file, scratch buffer end -- Define window configuration local win_config = { relative = "editor", width = width, height = height, col = col, row = row, style = "minimal", -- No borders or extra UI elements border = "rounded", } -- Create the floating window local win = vim.api.nvim_open_win(buf, true, win_config) return { buf = buf, win = win } end local toggle_terminal = function() if not vim.api.nvim_win_is_valid(state.floating.win) then state.floating = create_floating_window { buf = state.floating.buf } if vim.bo[state.floating.buf].buftype ~= "terminal" then vim.cmd.terminal() end else vim.api.nvim_win_hide(state.floating.win) end end -- Example usage: -- Create a floating window with default dimensions vim.api.nvim_create_user_command("Floaterminal", toggle_terminal, {}) ================================================ FILE: nvim/plugin/menu.lua ================================================ vim.cmd [[ aunmenu PopUp anoremenu PopUp.Inspect Inspect amenu PopUp.-1- anoremenu PopUp.Definition lua vim.lsp.buf.definition() anoremenu PopUp.References Telescope lsp_references nnoremenu PopUp.Back amenu PopUp.-2- amenu PopUp.URL gx ]] local group = vim.api.nvim_create_augroup("nvim_popupmenu", { clear = true }) vim.api.nvim_create_autocmd("MenuPopup", { pattern = "*", group = group, desc = "Custom PopUp Setup", callback = function() vim.cmd [[ amenu disable PopUp.Definition amenu disable PopUp.References amenu disable PopUp.URL ]] if vim.lsp.get_clients({ bufnr = 0 })[1] then vim.cmd [[ amenu enable PopUp.Definition amenu enable PopUp.References ]] end local urls = require("vim.ui")._get_urls() if vim.startswith(urls[1], "http") then vim.cmd [[amenu enable PopUp.URL]] end end, }) -- TODO: Add autocoommand