From 7641232bdc9b65e3079e43fe3a615c94222bdf90 Mon Sep 17 00:00:00 2001 From: "david@david-m2" <3200210+davidjenni@users.noreply.github.com> Date: Sun, 28 Jan 2024 20:55:09 -0800 Subject: [PATCH] feat: add nvim-tree and oil for better file system interaction --- nvim/init.lua | 1 + nvim/lazy-lock.json | 7 ++++++ nvim/lua/autocmds.lua | 9 ++++++++ nvim/lua/keymaps.lua | 18 +++++++++++++++ nvim/lua/lazy-nvim.lua | 5 +---- nvim/lua/options.lua | 6 ++++- nvim/lua/plugins/lsp.lua | 20 +++++++++-------- nvim/lua/plugins/nvim-tree.lua | 41 ++++++++++++++++++++++++++++++++++ nvim/lua/plugins/oil.lua | 9 ++++++++ 9 files changed, 102 insertions(+), 14 deletions(-) create mode 100644 nvim/lua/autocmds.lua create mode 100644 nvim/lua/plugins/nvim-tree.lua create mode 100644 nvim/lua/plugins/oil.lua diff --git a/nvim/init.lua b/nvim/init.lua index 5170269..2adae84 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -6,6 +6,7 @@ require('options') require('keymaps') +require('autocmds') require('lazy-nvim') vim.cmd[[ colorscheme tokyonight]] diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index d08ffc2..b6591b0 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,15 +1,22 @@ { "catppuccin": { "branch": "main", "commit": "048c18fc531703815f5e10765ea46ce9b2c75ae4" }, + "fidget.nvim": { "branch": "main", "commit": "3a93300c076109d86c7ce35ec67a8034ae6ba9db" }, + "gitsigns.nvim": { "branch": "main", "commit": "0a2a93f687ec051292943a4d139366332ac93688" }, "lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" }, "lualine.nvim": { "branch": "master", "commit": "566b7036f717f3d676362742630518a47f132fff" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "3ba1b92b771f33256b4969d696b82c8ae7075364" }, "mason.nvim": { "branch": "main", "commit": "9c9416817c9f4e6f333c749327a1ed5355cfab61" }, + "neodev.nvim": { "branch": "main", "commit": "64b2a51b02c6f2ae177c745e4d8bc801a339fe09" }, "nordtheme": { "branch": "main", "commit": "f13f5dfbb784deddbc1d8195f34dfd9ec73e2295" }, "nvim-lspconfig": { "branch": "master", "commit": "8917d2c830e04bf944a699b8c41f097621283828" }, "nvim-treesitter": { "branch": "master", "commit": "cd4e0909948eb33d3959e133c16f837e4db122c6" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "19a91a38b02c1c28c14e0ba468d20ae1423c39b2" }, + "nvim-web-devicons": { "branch": "master", "commit": "b427ac5f9dff494f839e81441fb3f04a58cbcfbc" }, + "oil.nvim": { "branch": "master", "commit": "bf753c3e3f8736939ad5597f92329dfe7b1df4f5" }, "plenary.nvim": { "branch": "master", "commit": "663246936325062427597964d81d30eaa42ab1e4" }, "telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" }, "telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" }, + "toggleterm.nvim": { "branch": "main", "commit": "cbd041d91b90cd3c02df03fe6133208888f8e008" }, "tokyonight.nvim": { "branch": "main", "commit": "67c6050e1ca41260c919236a098ba278472c7520" }, "vim-commentary": { "branch": "master", "commit": "f67e3e67ea516755005e6cccb178bc8439c6d402" }, "vim-fugitive": { "branch": "master", "commit": "854a8df0d06b8d3fcb30fa7f2b08c62b553eee3b" }, diff --git a/nvim/lua/autocmds.lua b/nvim/lua/autocmds.lua new file mode 100644 index 0000000..dd18a5f --- /dev/null +++ b/nvim/lua/autocmds.lua @@ -0,0 +1,9 @@ +local api = vim.api + +api.nvim_create_augroup("custom_buffer", { clear = true }) +api.nvim_create_autocmd("TextYankPost", { + group = "custom_buffer", + pattern = "*", + callback = function() vim.highlight.on_yank { timeout = 200 } end +}) + diff --git a/nvim/lua/keymaps.lua b/nvim/lua/keymaps.lua index 15b6b47..c2a7f62 100644 --- a/nvim/lua/keymaps.lua +++ b/nvim/lua/keymaps.lua @@ -11,3 +11,21 @@ k.set('n', '', ':wincmd l', { desc = 'Move to window right' }) -- plugins set their own keymaps in ~/.config/nvim/lua/plugins/*.lua -- +-- +k.set("n", "-", "Oil", { desc = "Open parent directory" }) + +k.set("n", "fp", "echo expand('%:p')", { desc = "Show full path of current buffer"}) + +local nvimTreeFocusOrToggle = function () + local nvimTree=require("nvim-tree.api") + local currentBuf = vim.api.nvim_get_current_buf() + local currentBufFt = vim.api.nvim_get_option_value("filetype", { buf = currentBuf }) + if currentBufFt == "NvimTree" then + nvimTree.tree.toggle() + else + nvimTree.tree.focus() + end +end + + +vim.keymap.set("n", "e", nvimTreeFocusOrToggle, { desc = "Toggle tree explorer"}) diff --git a/nvim/lua/lazy-nvim.lua b/nvim/lua/lazy-nvim.lua index f6f34d6..b1f9223 100644 --- a/nvim/lua/lazy-nvim.lua +++ b/nvim/lua/lazy-nvim.lua @@ -16,11 +16,8 @@ end vim.opt.rtp:prepend(lazypath) local opts = { - -- defaults = { - -- lazy = true, - -- }, install = { - colorscheme = { "catppuccin" }, + colorscheme = { "tokyonight" }, }, } diff --git a/nvim/lua/options.lua b/nvim/lua/options.lua index 9ff5606..f61b098 100644 --- a/nvim/lua/options.lua +++ b/nvim/lua/options.lua @@ -3,6 +3,10 @@ local g, opt = vim.g, vim.opt +-- nvim-tree: disable netrw at the very start of your init.lua +g.loaded_netrw = 1 +g.loaded_netrwPlugin = 1 + g.mapleader = ' ' g.maplocalleader = ' ' @@ -46,7 +50,7 @@ opt.virtualedit = 'onemore' opt.joinspaces = false opt.formatoptions = 'crqnj' -opt.completeopt = 'menuone,noselect,preview' +opt.completeopt = 'menuone,preview' opt.incsearch = true opt.ignorecase = true diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua index 0fc0424..c2bce22 100644 --- a/nvim/lua/plugins/lsp.lua +++ b/nvim/lua/plugins/lsp.lua @@ -1,4 +1,14 @@ + return { + { + "folke/neodev.nvim", + -- neodev needs to start before nvim-lspconfig + priority = 1000, + config = function() + require("neodev").setup({}) + end, + }, + { "williamboman/mason.nvim", config = function() @@ -15,21 +25,13 @@ return { end }, - { - -- neodev needs to start before nvim-lspconfig - "folke/neodev.nvim", - config = function() - require("neodev").setup({}) - end, - }, - { "neovim/nvim-lspconfig", dependencies = { + "folke/neodev.nvim", "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim", "j-hui/fidget.nvim", - "folke/neodev.nvim", }, config = function() local lspconfig = require('lspconfig') diff --git a/nvim/lua/plugins/nvim-tree.lua b/nvim/lua/plugins/nvim-tree.lua new file mode 100644 index 0000000..b4c3fb1 --- /dev/null +++ b/nvim/lua/plugins/nvim-tree.lua @@ -0,0 +1,41 @@ +return { + "nvim-tree/nvim-tree.lua", + version = "*", + lazy = "false", + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + config = function() + local HEIGHT_RATIO = 0.8 -- You can change this + local WIDTH_RATIO = 0.5 + require("nvim-tree").setup({ + view = { + float = { + enable = true, + open_win_config = function() + local screen_w = vim.opt.columns:get() + local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get() + local window_w = screen_w * WIDTH_RATIO + local window_h = screen_h * HEIGHT_RATIO + local window_w_int = math.floor(window_w) + local window_h_int = math.floor(window_h) + local center_x = (screen_w - window_w) / 2 + local center_y = ((vim.opt.lines:get() - window_h) / 2) + - vim.opt.cmdheight:get() + return { + border = 'rounded', + relative = 'editor', + row = center_y, + col = center_x, + width = window_w_int, + height = window_h_int, + } + end, + }, + width = function() + return math.floor(vim.opt.columns:get() * WIDTH_RATIO) + end, + }, + }) + end +} diff --git a/nvim/lua/plugins/oil.lua b/nvim/lua/plugins/oil.lua new file mode 100644 index 0000000..4099c3d --- /dev/null +++ b/nvim/lua/plugins/oil.lua @@ -0,0 +1,9 @@ +return { + 'stevearc/oil.nvim', + opts = {}, + -- Optional dependencies + dependencies = { "nvim-tree/nvim-web-devicons" }, + config = function() + require("oil").setup() + end, +}