From 5e80781558f795c3fd4da8d1a839d5f4fe8c7016 Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Wed, 18 Dec 2024 14:30:20 -0800 Subject: [PATCH] Add floating terminal to nvim config --- dot_config/nvim/init.lua | 7 +- dot_config/nvim/lua/core/commands.lua | 16 +++++ dot_config/nvim/lua/core/config.lua | 57 ++++----------- dot_config/nvim/lua/core/keymaps.lua | 23 +++++++ .../nvim/lua/core/lib/find_git_root.lua | 25 +++++++ .../nvim/lua/core/lib/toggle_terminal.lua | 45 ++++++++++++ .../nvim/lua/plugins/autocompletion.lua | 32 ++++----- dot_config/nvim/lua/plugins/base.lua | 9 ++- dot_config/nvim/lua/plugins/go.lua | 15 ++-- dot_config/nvim/lua/plugins/lsp.lua.tmpl | 21 +++--- dot_config/nvim/lua/plugins/snippets.lua | 6 +- dot_config/nvim/lua/plugins/telescope.lua | 69 +++++++++---------- dot_config/nvim/lua/plugins/theme.lua | 20 +++--- dot_config/nvim/lua/plugins/tree.lua | 22 +++--- dot_config/nvim/lua/plugins/treesitter.lua | 55 ++++++++------- 15 files changed, 248 insertions(+), 174 deletions(-) create mode 100644 dot_config/nvim/lua/core/commands.lua create mode 100644 dot_config/nvim/lua/core/keymaps.lua create mode 100644 dot_config/nvim/lua/core/lib/find_git_root.lua create mode 100644 dot_config/nvim/lua/core/lib/toggle_terminal.lua diff --git a/dot_config/nvim/init.lua b/dot_config/nvim/init.lua index 0917d46..3375568 100644 --- a/dot_config/nvim/init.lua +++ b/dot_config/nvim/init.lua @@ -1,5 +1,6 @@ -require('core.config') -vim.opt.runtimepath:prepend(vim.fn.stdpath('data') .. '/lazy/lazy.nvim') -require('lazy').setup('plugins', { +require("core.config") +require("core.keymaps") +vim.opt.runtimepath:prepend(vim.fn.stdpath("data") .. "/lazy/lazy.nvim") +require("lazy").setup("plugins", { version = "*", }) diff --git a/dot_config/nvim/lua/core/commands.lua b/dot_config/nvim/lua/core/commands.lua new file mode 100644 index 0000000..4f6996c --- /dev/null +++ b/dot_config/nvim/lua/core/commands.lua @@ -0,0 +1,16 @@ +vim.api.nvim_create_user_command("W", "write", {}) +vim.api.nvim_create_user_command("Q", "qall!", {}) + +-- Create a floating terminal +vim.api.nvim_create_user_command("FloaTerm", require("core.lib.toggle_terminal"), { + desc = "Toggle a floating terminal", +}) + +-- highlight text on copy +vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking (copying) text", + callback = vim.highlight.on_yank, + group = vim.api.nvim_create_augroup("kickstart-highlight-yank", { + clear = true, + }), +}) diff --git a/dot_config/nvim/lua/core/config.lua b/dot_config/nvim/lua/core/config.lua index e0a6f4b..b946457 100644 --- a/dot_config/nvim/lua/core/config.lua +++ b/dot_config/nvim/lua/core/config.lua @@ -1,16 +1,15 @@ -vim.g.mapleader = ',' -vim.g.maplocalleader = ',' +vim.g.mapleader = "," +vim.g.maplocalleader = "," -vim.opt.fileformats = { 'unix', 'dos', 'mac' } +vim.opt.fileformats = { "unix", "dos", "mac" } -vim.opt.mouse = 'a' -vim.opt.clipboard = 'unnamedplus' +vim.opt.mouse = "a" +vim.opt.clipboard = "unnamedplus" vim.opt.breakindent = true vim.opt.undofile = true -vim.opt.signcolumn = 'yes' vim.opt.updatetime = 250 -vim.opt.timeoutlen = 300 +vim.opt.timeoutlen = 1000 vim.opt.splitright = true vim.opt.splitbelow = true @@ -29,8 +28,8 @@ vim.opt.number = true vim.opt.numberwidth = 4 vim.opt.relativenumber = true vim.opt.showmatch = true -vim.opt.spelllang = 'en_us' -vim.opt.wildmode = 'list:longest' +vim.opt.spelllang = "en_us" +vim.opt.wildmode = "list:longest" vim.opt.cursorline = true -- Indent @@ -42,41 +41,13 @@ vim.opt.shiftround = true -- Text Formatting/Layout vim.opt.ignorecase = true vim.opt.list = true -vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -vim.opt.inccommand = 'split' +vim.opt.listchars = { tab = "» ", trail = "·", nbsp = "␣" } +vim.opt.inccommand = "split" vim.opt.smartcase = true vim.opt.wrap = false vim.opt.whichwrap:append { - ['<'] = true, - ['>'] = true, - ['['] = true, - [']'] = true, + ["<"] = true, + [">"] = true, + ["["] = true, + ["]"] = true, } - -vim.api.nvim_create_user_command('W', 'write', {}) -vim.api.nvim_create_user_command('Q', 'qall!', {}) - -vim.keymap.set('n', 'l', ':nohlsearch', { desc = 'clear highlighted search' }) -vim.keymap.set('n', 'ts', [[:%s/\s\s*$//g]], { desc = '[T]rim trailing [S]pace' }) -vim.keymap.set('n', 'ss', ':setlocal spell!', { desc = '[S]et [S]pell' }) -vim.keymap.set('n', 'p', ':set paste!', { desc = '[P]aste' }) -vim.keymap.set('n', 'nn', ':set nonumber norelativenumber', { desc = '[N]o [N]umber removed number and relative number' }) -vim.keymap.set('n', 'rn', ':set number relativenumber', { desc = '[R]elative [N]umber - set relative number and absolute number' }) - -vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) -vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) -vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) -vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnopstic [Q]uickfix list' }) - --- Use to move between windows, no need for first -vim.keymap.set('n', '', '', { desc = 'Move focus up window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus down window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus left window' }) -vim.keymap.set('n', '', '', { desc = 'Move focus right window' }) - --- highlight text on copy -vim.api.nvim_create_autocmd('TextYankPost', { - desc = 'Highlight when yanking (copying) text', - group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }), - callback = vim.highlight.on_yank, -}) diff --git a/dot_config/nvim/lua/core/keymaps.lua b/dot_config/nvim/lua/core/keymaps.lua new file mode 100644 index 0000000..b956708 --- /dev/null +++ b/dot_config/nvim/lua/core/keymaps.lua @@ -0,0 +1,23 @@ +require("core.commands") +local toggle_terminal = require("core.lib.toggle_terminal") + +vim.keymap.set("n", "l", ":nohlsearch", { desc = "clear highlighted search" }) +vim.keymap.set("n", "ts", [[:%s/\s\s*$//g]], { desc = "[T]rim trailing [S]pace" }) +vim.keymap.set("n", "ss", ":setlocal spell!", { desc = "[S]et [S]pell" }) +vim.keymap.set("n", "p", ":set paste!", { desc = "[P]aste" }) +vim.keymap.set("n", "nn", ":set nonumber norelativenumber", { desc = "[N]o [N]umber removed number and relative number" }) +vim.keymap.set("n", "rn", ":set number relativenumber", { desc = "[R]elative [N]umber - set relative number and absolute number" }) + +vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { desc = "Go to previous [D]iagnostic message" }) +vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { desc = "Go to next [D]iagnostic message" }) +vim.keymap.set("n", "e", vim.diagnostic.open_float, { desc = "Show diagnostic [E]rror messages" }) +vim.keymap.set("n", "q", vim.diagnostic.setloclist, { desc = "Open diagnopstic [Q]uickfix list" }) + +-- Use to move between windows, no need for first +vim.keymap.set("n", "", "", { desc = "Move focus up window" }) +vim.keymap.set("n", "", "", { desc = "Move focus down window" }) +vim.keymap.set("n", "", "", { desc = "Move focus left window" }) +vim.keymap.set("n", "", "", { desc = "Move focus right window" }) + +vim.keymap.set({ "n", "t" }, "tt", toggle_terminal) +vim.keymap.set("t", "", "") diff --git a/dot_config/nvim/lua/core/lib/find_git_root.lua b/dot_config/nvim/lua/core/lib/find_git_root.lua new file mode 100644 index 0000000..6c16139 --- /dev/null +++ b/dot_config/nvim/lua/core/lib/find_git_root.lua @@ -0,0 +1,25 @@ +-- Telescope live_grep in git root +-- Function to find the git root directory based on the current buffer's path +local function find_git_root() + -- Use the current buffer's path as the starting point for the git search + local current_file = vim.api.nvim_buf_get_name(0) + local current_dir + local cwd = vim.fn.getcwd() + -- If the buffer is not associated with a file, return nil + if current_file == '' then + current_dir = cwd + else + -- Extract the directory from the current file's path + current_dir = vim.fn.fnamemodify(current_file, ':h') + end + + -- Find the Git root directory from the current file's path + local git_root = vim.fn.systemlist('git -C ' .. vim.fn.escape(current_dir, ' ') .. ' rev-parse --show-toplevel')[1] + if vim.v.shell_error ~= 0 then + print('Not a git repository. Searching on current working directory') + return cwd + end + return git_root +end + +return find_git_root diff --git a/dot_config/nvim/lua/core/lib/toggle_terminal.lua b/dot_config/nvim/lua/core/lib/toggle_terminal.lua new file mode 100644 index 0000000..8ef2dfa --- /dev/null +++ b/dot_config/nvim/lua/core/lib/toggle_terminal.lua @@ -0,0 +1,45 @@ +local state = { + floating = { + buf = -1, + win = -1, + } +} + +local function create_floating_window(ops) + ops = ops or {} + local width = ops.width or math.floor(vim.o.columns * 0.8) + local height = ops.height or math.floor(vim.o.lines * 0.8) + + local buf + if vim.api.nvim_buf_is_valid(state.floating.buf) then + buf = state.floating.buf + vim.cmd("startinsert") + else + buf = vim.api.nvim_create_buf(false, true) + end + + local win = vim.api.nvim_open_win(buf, true, { + relative = "editor", + style = "minimal", + border = "rounded", + width = width, + height = height, + col = math.floor((vim.o.columns - width) / 2), + row = math.floor((vim.o.lines - height) / 2), + }) + return { buf = buf, win = win } +end + +local function toggle_terminal() + if vim.api.nvim_win_is_valid(state.floating.win) then + vim.api.nvim_win_hide(state.floating.win) + else + state.floating = create_floating_window { buf = state.floating.buf } + if vim.bo[state.floating.buf].buftype ~= "terminal" then + vim.cmd.terminal() + vim.cmd("startinsert") + end + end +end + +return toggle_terminal diff --git a/dot_config/nvim/lua/plugins/autocompletion.lua b/dot_config/nvim/lua/plugins/autocompletion.lua index 2174711..1975864 100644 --- a/dot_config/nvim/lua/plugins/autocompletion.lua +++ b/dot_config/nvim/lua/plugins/autocompletion.lua @@ -1,14 +1,14 @@ -local M = { 'hrsh7th/nvim-cmp' } +local M = { "hrsh7th/nvim-cmp" } -M.name = 'cmp' +M.name = "cmp" M.dependencies = { - 'saadparwaiz1/cmp_luasnip', - 'hrsh7th/cmp-nvim-lsp', + "saadparwaiz1/cmp_luasnip", + "hrsh7th/cmp-nvim-lsp", } function M.config() - local cmp = require 'cmp' - local luasnip = require 'luasnip' + local cmp = require "cmp" + local luasnip = require "luasnip" local function expand(args) luasnip.lsp_expand(args.body) @@ -39,19 +39,19 @@ function M.config() snippet = { expand = expand }, sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, + { name = "nvim_lsp" }, + { name = "luasnip" }, }, mapping = cmp.mapping.preset.insert { - [''] = cmp.mapping.select_next_item(), - [''] = cmp.mapping.select_prev_item(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - [''] = cmp.mapping.complete({}), - [''] = cmp.mapping(tab_mapping, { 'i', 's' }), - [''] = cmp.mapping(back_tab_mapping, { 'i', 's' }), - [''] = cmp.mapping.confirm { + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({}), + [""] = cmp.mapping(tab_mapping, { "i", "s" }), + [""] = cmp.mapping(back_tab_mapping, { "i", "s" }), + [""] = cmp.mapping.confirm { behavior = cmp.ConfirmBehavior.Replace, select = true, }, diff --git a/dot_config/nvim/lua/plugins/base.lua b/dot_config/nvim/lua/plugins/base.lua index 0e8051f..8ad8614 100644 --- a/dot_config/nvim/lua/plugins/base.lua +++ b/dot_config/nvim/lua/plugins/base.lua @@ -1,18 +1,17 @@ -- https://github.com/tpope/vim-surround -- surround.vim: Delete/change/add parentheses/quotes/XML-tags/much more with ease -local M = { 'tpope/vim-surround' } +local M = { "tpope/vim-surround" } -M.tag = 'v2.2' +M.tag = "v2.2" M.dependencies = { -- https://github.com/tpope/vim-sleuth -- sleuth.vim: Heuristically set buffer options - { 'tpope/vim-sleuth', tag = 'v2.0' }, + { "tpope/vim-sleuth", tag = "v2.0" }, -- https://github.com/numToStr/Comment.nvim -- 🧠 💪 // Smart and powerful comment plugin for neovim. -- Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more - { 'numToStr/Comment.nvim', opts = {}, lazy = false }, + { "numToStr/Comment.nvim", opts = {}, lazy = false }, } - return M diff --git a/dot_config/nvim/lua/plugins/go.lua b/dot_config/nvim/lua/plugins/go.lua index da23491..414e207 100644 --- a/dot_config/nvim/lua/plugins/go.lua +++ b/dot_config/nvim/lua/plugins/go.lua @@ -1,17 +1,16 @@ -- https://github.com/ray-x/go.nvim -- A modern go neovim plugin based on treesitter, nvim-lsp and dap debugger. -local M = { 'ray-x/go.nvim' } +local M = { "ray-x/go.nvim" } -M.name = 'go' -M.event = { 'CmdlineEnter' } -M.ft = { 'go', 'gomod' } +M.name = "go" +M.event = { "CmdlineEnter" } +M.ft = { "go", "gomod" } M.dependencies = { -- https://github.com/ray-x/guihua.lua -- Guihua: A Lua Gui and util library for nvim plugins - 'ray-x/guihua.lua', - - 'lspconfig', - 'treesitter', + "ray-x/guihua.lua", + "lspconfig", + "treesitter", } function M.config() diff --git a/dot_config/nvim/lua/plugins/lsp.lua.tmpl b/dot_config/nvim/lua/plugins/lsp.lua.tmpl index 4e650b0..a872330 100644 --- a/dot_config/nvim/lua/plugins/lsp.lua.tmpl +++ b/dot_config/nvim/lua/plugins/lsp.lua.tmpl @@ -1,32 +1,31 @@ # chezmoi:template:left-delimiter=--{{ --{{- /* vim: set filetype=lua: */ -}} -local M = { 'neovim/nvim-lspconfig' } +local M = { "neovim/nvim-lspconfig" } -M.name = 'lspconfig' -M.tag = 'v1.0.0' +M.name = "lspconfig" +M.tag = "v1.0.0" M.dependencies = { - { 'j-hui/fidget.nvim', tag = 'legacy', opts = {} }, - { 'folke/trouble.nvim', tag = 'v3.6.0' }, - { 'folke/lazydev.nvim', tag = 'v1.9.0', ft = "lua", opts = {} }, + { "j-hui/fidget.nvim", tag = "legacy", opts = {} }, + { "folke/trouble.nvim", tag = "v3.6.0" }, + { "folke/lazydev.nvim", tag = "v1.9.0", ft = "lua", opts = {} }, } - local function format_buffer(_) vim.lsp.buf.format() end local function on_attach(_, buffer) -- Create a command `:Format` local to the LSP buffer - vim.api.nvim_buf_create_user_command(buffer, 'Format', format_buffer, { - desc = 'Format current buffer with LSP', + vim.api.nvim_buf_create_user_command(buffer, "Format", format_buffer, { + desc = "Format current buffer with LSP", }) end function M.config() - local lspconfig = require('lspconfig') + local lspconfig = require("lspconfig") - local capabilities = require('cmp_nvim_lsp').default_capabilities( + local capabilities = require("cmp_nvim_lsp").default_capabilities( vim.lsp.protocol.make_client_capabilities()) --{{ if lookPath "bash-language-server" -}} diff --git a/dot_config/nvim/lua/plugins/snippets.lua b/dot_config/nvim/lua/plugins/snippets.lua index bea33f4..ccfa8ee 100644 --- a/dot_config/nvim/lua/plugins/snippets.lua +++ b/dot_config/nvim/lua/plugins/snippets.lua @@ -1,12 +1,12 @@ -- https://github.com/L3MON4D3/LuaSnip -- Snippet Engine for Neovim written in Lua. -local M = { 'L3MON4D3/LuaSnip' } +local M = { "L3MON4D3/LuaSnip" } -M.tag = 'v2.3.0' +M.tag = "v2.3.0" M.dependencies = {} function M.config() - local luasnip = require 'luasnip' + local luasnip = require "luasnip" luasnip.setup() luasnip.config.setup({}) require("luasnip.loaders.from_snipmate").lazy_load() diff --git a/dot_config/nvim/lua/plugins/telescope.lua b/dot_config/nvim/lua/plugins/telescope.lua index b05c0e2..8b0b281 100644 --- a/dot_config/nvim/lua/plugins/telescope.lua +++ b/dot_config/nvim/lua/plugins/telescope.lua @@ -1,40 +1,37 @@ -local lib = require('core.lib') -local M = { 'nvim-telescope/telescope.nvim' } +local find_git_root = require("core.lib.find_git_root") +local M = { "nvim-telescope/telescope.nvim" } -M.branch = '0.1.x' -M.event = 'VimEnter' +M.branch = "0.1.x" +M.event = "VimEnter" M.dependencies = { - 'nvim-lua/plenary.nvim', - { - 'nvim-telescope/telescope-fzf-native.nvim', - build = 'make', - }, - 'nvim-telescope/telescope-ui-select.nvim', - 'nvim-tree/nvim-web-devicons', + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-ui-select.nvim", + "nvim-tree/nvim-web-devicons", + { "nvim-telescope/telescope-fzf-native.nvim", build = "make" }, } -- Custom live_grep function to search in git root local function live_grep_git_root() - local git_root = lib.find_git_root() + local git_root = find_git_root() if git_root then - require('telescope.builtin').live_grep({ + require("telescope.builtin").live_grep({ search_dirs = { git_root }, }) end end -vim.api.nvim_create_user_command('LiveGrepGitRoot', live_grep_git_root, {}) +vim.api.nvim_create_user_command("LiveGrepGitRoot", live_grep_git_root, {}) function M.config() -- See `:help telescope` and `:help telescope.setup()` - local telescope = require('telescope') - local builtin = require('telescope.builtin') - local themes = require('telescope.themes') + local telescope = require("telescope") + local builtin = require("telescope.builtin") + local themes = require("telescope.themes") telescope.setup({ -- pickers = {} extensions = { - ['ui-select'] = { + ["ui-select"] = { themes.get_dropdown(), }, }, @@ -42,17 +39,17 @@ function M.config() defaults = { mappings = { i = { - [''] = false, - [''] = false, - [''] = 'to_fuzzy_refine', + [""] = false, + [""] = false, + [""] = "to_fuzzy_refine", }, }, }, }) -- Enable telescope fzf native, if installed - pcall(telescope.load_extension, 'fzf') - pcall(telescope.load_extension, 'ui-select') + pcall(telescope.load_extension, "fzf") + pcall(telescope.load_extension, "ui-select") local function fuzzy_find() -- You can pass additional configuration to telescope to change theme, @@ -64,19 +61,19 @@ function M.config() end -- See `:help telescope.builtin` - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) - vim.keymap.set('n', 'sG', live_grep_git_root, { desc = '[S]earch by [G]rep on Git Root' }) - vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) - vim.keymap.set('n', '/', fuzzy_find, { desc = '[/] Fuzzily search in current buffer' }) - vim.keymap.set('n', 'gf', builtin.git_files, { desc = 'Search [G]it [F]iles' }) + vim.keymap.set("n", "sh", builtin.help_tags, { desc = "[S]earch [H]elp" }) + vim.keymap.set("n", "sk", builtin.keymaps, { desc = "[S]earch [K]eymaps" }) + vim.keymap.set("n", "sf", builtin.find_files, { desc = "[S]earch [F]iles" }) + vim.keymap.set("n", "ss", builtin.builtin, { desc = "[S]earch [S]elect Telescope" }) + vim.keymap.set("n", "sw", builtin.grep_string, { desc = "[S]earch current [W]ord" }) + vim.keymap.set("n", "sg", builtin.live_grep, { desc = "[S]earch by [G]rep" }) + vim.keymap.set("n", "sd", builtin.diagnostics, { desc = "[S]earch [D]iagnostics" }) + vim.keymap.set("n", "sr", builtin.resume, { desc = "[S]earch [R]esume" }) + vim.keymap.set("n", "s.", builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set("n", "sG", live_grep_git_root, { desc = "[S]earch by [G]rep on Git Root" }) + vim.keymap.set("n", "", builtin.buffers, { desc = "[ ] Find existing buffers" }) + vim.keymap.set("n", "/", fuzzy_find, { desc = "[/] Fuzzily search in current buffer" }) + vim.keymap.set("n", "gf", builtin.git_files, { desc = "Search [G]it [F]iles" }) end return M diff --git a/dot_config/nvim/lua/plugins/theme.lua b/dot_config/nvim/lua/plugins/theme.lua index e5be584..a11b9ad 100644 --- a/dot_config/nvim/lua/plugins/theme.lua +++ b/dot_config/nvim/lua/plugins/theme.lua @@ -1,27 +1,27 @@ -- https://github.com/morhetz/gruvbox -local M = { 'morhetz/gruvbox' } +local M = { "morhetz/gruvbox" } M.priority = 1000 M.dependencies = { -- https://github.com/nvim-lualine/lualine.nvim - 'nvim-lualine/lualine.nvim', + "nvim-lualine/lualine.nvim", opts = { options = { - theme = 'gruvbox', + theme = "gruvbox", }, sections = { - lualine_a = { 'mode' }, - lualine_b = { 'diagnostics' }, - lualine_c = { { 'filename', path = 3 } }, - lualine_x = { 'encoding', 'fileformat', 'filetype' }, - lualine_y = { 'progress' }, - lualine_z = { 'location' } + lualine_a = { "mode" }, + lualine_b = { "diagnostics" }, + lualine_c = { { "filename", path = 3 } }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" } }, }, } function M.config() - vim.cmd.colorscheme 'gruvbox' + vim.cmd.colorscheme("gruvbox") end return M diff --git a/dot_config/nvim/lua/plugins/tree.lua b/dot_config/nvim/lua/plugins/tree.lua index 7d98abf..6a5a603 100644 --- a/dot_config/nvim/lua/plugins/tree.lua +++ b/dot_config/nvim/lua/plugins/tree.lua @@ -2,25 +2,25 @@ vim.g.loaded_netrw = 1 vim.g.loaded_netrwPlugin = 1 vim.opt.termguicolors = true -local M = { 'nvim-tree/nvim-tree.lua' } +local M = { "nvim-tree/nvim-tree.lua" } -M.tag = 'nvim-tree-v1.9.0' +M.tag = "nvim-tree-v1.9.0" M.keys = { - { 'nt', ':NvimTreeToggle', desc = 'toggle nvim tree' } + { "nt", ":NvimTreeToggle", desc = "toggle nvim tree" } } M.dependencies = { -- https://github.com/nvim-tree/nvim-web-devicons - 'nvim-tree/nvim-web-devicons', opts = {} + "nvim-tree/nvim-web-devicons", opts = {} } function M.config() - require('nvim-tree').setup() - vim.api.nvim_create_autocmd('WinClosed', { + require("nvim-tree").setup() + vim.api.nvim_create_autocmd("WinClosed", { nested = true, callback = function() - M.handle_closed(tonumber(vim.fn.expand(''))) + M.handle_closed(tonumber(vim.fn.expand(""))) end, }) end @@ -37,9 +37,9 @@ function M.handle_closed(window) local windows = vim.tbl_filter(filter_window, vim.api.nvim_tabpage_list_wins(tab)) local buffers = vim.tbl_map(vim.api.nvim_win_get_buf, windows) - if info.name:match('.*NvimTree_%d*$') then + if info.name:match(".*NvimTree_%d*$") then if not vim.tbl_isempty(buffers) then - require('nvim-tree.api').tree.close() + require("nvim-tree.api").tree.close() end return end @@ -49,10 +49,10 @@ function M.handle_closed(window) end local last_info = vim.fn.getbufinfo(buffers[1])[1] - if last_info.name:match('.*NvimTree_%d*$') then + if last_info.name:match(".*NvimTree_%d*$") then vim.schedule(function() if #vim.api.nvim_list_wins() == 1 then - vim.cmd 'quit' + vim.cmd "quit" else vim.api.nvim_win_close(windows[1], true) end diff --git a/dot_config/nvim/lua/plugins/treesitter.lua b/dot_config/nvim/lua/plugins/treesitter.lua index 57cc682..f9c0274 100644 --- a/dot_config/nvim/lua/plugins/treesitter.lua +++ b/dot_config/nvim/lua/plugins/treesitter.lua @@ -1,9 +1,9 @@ -local M = {'nvim-treesitter/nvim-treesitter' } +local M = {"nvim-treesitter/nvim-treesitter" } -M.name = 'treesitter' -M.build = ':TSUpdate' +M.name = "treesitter" +M.build = ":TSUpdate" M.dependencies = { - 'nvim-treesitter/nvim-treesitter-textobjects' + "nvim-treesitter/nvim-treesitter-textobjects" } function M.config () @@ -11,15 +11,14 @@ function M.config () end function M.treesitter_configs() - require 'nvim-treesitter.configs' - .setup(M.treesitter_config_setup) + require("nvim-treesitter.configs").setup(M.treesitter_config_setup) end M.treesitter_config_setup = { -- Add languages to be installed here that you want installed for treesitter ensure_installed = { - 'bash', 'c', 'cpp', 'go', 'lua', 'python', 'rust', - 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', + "bash", "c", "cpp", "go", "lua", "python", "rust", + "tsx", "javascript", "typescript", "vimdoc", "vim", }, auto_install = true, @@ -34,10 +33,10 @@ M.treesitter_config_setup = { incremental_selection = { enable = true, keymaps = { - init_selection = '', - node_incremental = '', - scope_incremental = '', - node_decremental = '', + init_selection = "", + node_incremental = "", + scope_incremental = "", + node_decremental = "", }, }, @@ -48,22 +47,22 @@ M.treesitter_config_setup = { lookahead = true, keymaps = { -- You can use the capture groups defined in textobjects.scm - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['ac'] = '@class.outer', - ['ic'] = '@class.inner', + ["aa"] = "@parameter.outer", + ["ia"] = "@parameter.inner", + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", }, }, swap = { enable = true, swap_next = { - ['a'] = '@parameter.inner', + ["a"] = "@parameter.inner", }, swap_previous = { - ['A'] = '@parameter.inner', + ["A"] = "@parameter.inner", }, }, @@ -72,20 +71,20 @@ M.treesitter_config_setup = { -- whether to set jumps in the jumplist set_jumps = true, goto_next_start = { - [']m'] = '@function.outer', - [']]'] = '@class.outer', + ["]m"] = "@function.outer", + ["]]"] = "@class.outer", }, goto_next_end = { - [']M'] = '@function.outer', - [']['] = '@class.outer', + ["]M"] = "@function.outer", + ["]["] = "@class.outer", }, goto_previous_start = { - ['[m'] = '@function.outer', - ['[['] = '@class.outer', + ["[m"] = "@function.outer", + ["[["] = "@class.outer", }, goto_previous_end = { - ['[M'] = '@function.outer', - ['[]'] = '@class.outer', + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", }, }, },