diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index b6b2330..5ea152a 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,9 +1,11 @@ { "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, + "auto-session": { "branch": "main", "commit": "00334ee24b9a05001ad50221c8daffbeedaa0842" }, "autoclose.nvim": { "branch": "main", "commit": "b2077aa2c83df7ebc19b2a20a3a0654b24ae9c8f" }, "blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" }, "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "gitsigns.nvim": { "branch": "main", "commit": "ee7e50dfbdf49e3acfa416fd3ad3abbdb658582c" }, + "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, "image.nvim": { "branch": "master", "commit": "c40215d7d7d1d8c823ee9a77be1a894d5c8df41b" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, @@ -18,9 +20,9 @@ "oil.nvim": { "branch": "master", "commit": "685cdb4ffa74473d75a1b97451f8654ceeab0f4a" }, "onedark.nvim": { "branch": "master", "commit": "67a74c275d1116d575ab25485d1bfa6b2a9c38a6" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, - "tabby.nvim": { "branch": "main", "commit": "6362aa9595428cefbb6556c05390e8444d1bcd12" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope.nvim": { "branch": "master", "commit": "a4ed82509cecc56df1c7138920a1aeaf246c0ac5" }, "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, + "vim-be-good": { "branch": "master", "commit": "0ae3de14eb8efc6effe7704b5e46495e91931cc5" }, "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" } } diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua index f989677..871a053 100644 --- a/.config/nvim/lua/config/keymaps.lua +++ b/.config/nvim/lua/config/keymaps.lua @@ -1,3 +1,5 @@ +local util = require('config.util') + -- NOTE: General -- -- hjkl to ijkl remap @@ -15,6 +17,7 @@ vim.keymap.set({ 'v', 'o' }, '', '<', { desc = 'S-tab unindent ' }) -- scrolling vim.keymap.set({ 'n', 'v' }, '', 'zz', { desc = 'centered scroll' }) vim.keymap.set({ 'n', 'v' }, '', 'zz', { desc = 'centered scroll' }) +vim.keymap.set({ 'n', 'v' }, '', 'zz', { desc = 'centered jump back' }) -- start of line vim.keymap.set({ 'n', 'v', 'o' }, '#', '_', { desc = '# start of line' }) @@ -25,15 +28,15 @@ vim.keymap.set('n', '', ':bd', { desc = 'save and close', nowait = true -- tabs -- TODO: redo with telescope and ctrl tab -vim.keymap.set('n', '', ':tabnext', { desc = 'next buffer' }) -vim.keymap.set('n', '', ':tabprev', { desc = 'previous buffer', noremap = true }) + +-- vim.keymap.set('n', '', ':bnext', { desc = 'next buffer' }) +-- vim.keymap.set('n', '', ':bprev', { desc = 'previous buffer', noremap = true }) -- delete word in insert mode vim.keymap.set('i', '', '', { desc = 'delete word in insert mode' }) -- NOTE: Right Dock: Terminal & Oil -local util = require('config.util') vim.keymap.set('n', '', function() util.open_in_right_dock('term://') @@ -41,6 +44,7 @@ end, { desc = 'open terminal' }) vim.keymap.set('t', '', 'wincmd h', { desc = 'focus editor', silent = true }) vim.keymap.set('t', '', '', { desc = 'kill terminal' }) +vim.keymap.set('t', '', 'q', { desc = 'close terminal window' }) vim.keymap.set('t', '', '', { desc = 'normal mode in terminal' }) @@ -166,3 +170,15 @@ vim.api.nvim_create_autocmd('LspAttach', { end end, }) + +-- NOTE: Molten +vim.keymap.set("n", "mi", ":MoltenInit", + { silent = true, desc = "Initialize the plugin" }) +vim.keymap.set("n", "mo", ":MoltenEvaluateOperator", + { silent = true, desc = "run operator selection" }) +vim.keymap.set("n", "ml", ":MoltenEvaluateLine", + { silent = true, desc = "evaluate line" }) +vim.keymap.set("v", "mv", ":MoltenEvaluateVisualgv", + { silent = false, desc = "evaluate visual selection" }) +vim.keymap.set("n", "mh", ":MoltenHideOutput", + { silent = true, desc = "hide output" }) diff --git a/.config/nvim/lua/config/options.lua b/.config/nvim/lua/config/options.lua index 4b708e1..e077d79 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -31,7 +31,7 @@ vim.opt.splitbelow = true vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. -vim.opt.scrolloff = 20 +vim.opt.scrolloff = 10 -- if performing an operation that would fail due to unsaved changes in the buffer (like `:q`), -- instead raise a dialog asking if you wish to save the current file(s) @@ -43,6 +43,8 @@ vim.opt.fillchars:append({ eob = ' ' }) vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 +vim.opt.hlsearch = false + -- Example for configuring Neovim to load user-installed installed Lua rocks: package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?/init.lua;' package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?.lua;' diff --git a/.config/nvim/lua/config/pluginmaps.lua b/.config/nvim/lua/config/pluginmaps.lua deleted file mode 100644 index 38370a2..0000000 --- a/.config/nvim/lua/config/pluginmaps.lua +++ /dev/null @@ -1,45 +0,0 @@ --- NOTE: Revisit Later -return { - multicursor = function() - return { - {'i', 'k', mode = {'n'}}, - {'', 'MultipleCursorsAddUp', mode = {'n', 'x'}, desc = 'Add cursor and move up'}, - {'', 'MultipleCursorsAddDown', mode = {'n', 'x'}, desc = 'Add cursor and move down'}, - - {'', 'MultipleCursorsMouseAddDelete', mode = {'n', 'i'}, desc = 'Add or remove cursor'}, - - -- {'m', 'MultipleCursorsAddVisualArea', mode = {'x'}, desc = 'Add cursors to the lines of the visual area'}, - - {'a', 'MultipleCursorsAddMatches', mode = {'n', 'x'}, desc = 'Add cursors to cword'}, - {'A', 'MultipleCursorsAddMatchesV', mode = {'n', 'x'}, desc = 'Add cursors to cword in previous area'}, - - {'', 'MultipleCursorsAddJumpNextMatch', mode = {'n', 'x'}, desc = 'Add cursor and jump to next cword'}, - -- {'q', 'MultipleCursorsJumpNextMatch', mode = {'n', 'x'}, desc = 'Jump to next cword'}, - -- {'Q', 'MultipleCursorsJumpPrevMatch', mode = {'n', 'x'}, desc = 'Jump to next cword'}, - - -- {'l', 'MultipleCursorsLock', mode = {'n', 'x'}, desc = 'Lock virtual cursors'}, - } - end, - - multicursor_custom = function() - return { - {{'n', 'x' }, 'i', function() - local pos = vim.api.nvim_win_get_cursor(0) - vim.api.nvim_win_set_cursor(0, {math.max(pos[1] - 1, 1), pos[2]}) - end}, - {{'n', 'x' }, 'j', function() - local pos = vim.api.nvim_win_get_cursor(0) - vim.api.nvim_win_set_cursor(0, {pos[1], math.max(pos[2] - 1, 0)}) - end}, - {{'n', 'x' }, 'k', function() - local pos = vim.api.nvim_win_get_cursor(0) - local lines = vim.api.nvim_buf_line_count(0) - vim.api.nvim_win_set_cursor(0, {math.min(pos[1] + 1, lines), pos[2]}) - end}, - {{'n', 'x' }, 'h', function() - vim.cmd('startinsert') - end}, - } - end - -} diff --git a/.config/nvim/lua/config/plugins/autosession.lua b/.config/nvim/lua/config/plugins/autosession.lua new file mode 100644 index 0000000..5a694f5 --- /dev/null +++ b/.config/nvim/lua/config/plugins/autosession.lua @@ -0,0 +1,13 @@ +return { + 'rmagatti/auto-session', + lazy = false, + + ---enables autocomplete for opts + ---@module "auto-session" + ---@type AutoSession.Config + opts = { + suppressed_dirs = { '~/', '~/Downloads', '/' }, + } +} + + diff --git a/.config/nvim/lua/config/plugins/harpoon.lua b/.config/nvim/lua/config/plugins/harpoon.lua new file mode 100644 index 0000000..6b82ca9 --- /dev/null +++ b/.config/nvim/lua/config/plugins/harpoon.lua @@ -0,0 +1,29 @@ +return { + 'ThePrimeagen/harpoon', + branch = 'harpoon2', + dependencies = { 'nvim-lua/plenary.nvim' }, + config = function() + + local harpoon = require('harpoon') + harpoon:setup({ + settings = { + save_on_toggle = true, + sync_on_ui_close = true + } + }) + + + vim.keymap.set('n', 'a', function() harpoon:list():add() end) + vim.keymap.set('n', '', function() harpoon.ui:toggle_quick_menu(harpoon:list()) end) + + vim.keymap.set('n', '', function() harpoon:list():select(1) end) + vim.keymap.set('n', '', function() harpoon:list():select(2) end) + vim.keymap.set('n', '', function() harpoon:list():select(3) end) + vim.keymap.set('n', '', function() harpoon:list():select(4) end) + + -- -- Toggle previous & next buffers stored within Harpoon list + -- vim.keymap.set('n', '', function() harpoon:list():prev() end) + -- vim.keymap.set('n', '', function() harpoon:list():next() end) + + end +} diff --git a/.config/nvim/lua/config/plugins/init.lua b/.config/nvim/lua/config/plugins/init.lua index 9dbc55b..f2ab85c 100644 --- a/.config/nvim/lua/config/plugins/init.lua +++ b/.config/nvim/lua/config/plugins/init.lua @@ -34,6 +34,8 @@ require('lazy').setup({ opts = {}, }, + 'ThePrimeagen/vim-be-good', + require('config.plugins.oil'), require('config.plugins.git'), require('config.plugins.ui'), @@ -41,6 +43,8 @@ require('lazy').setup({ require('config.plugins.blinkcmp'), require('config.plugins.lsp'), require('config.plugins.treesitter'), + require('config.plugins.autosession'), + require('config.plugins.harpoon'), require('config.plugins.molten'), diff --git a/.config/nvim/lua/config/plugins/oil.lua b/.config/nvim/lua/config/plugins/oil.lua index fe3683e..a10d805 100644 --- a/.config/nvim/lua/config/plugins/oil.lua +++ b/.config/nvim/lua/config/plugins/oil.lua @@ -1,10 +1,13 @@ return { - 'stevearc/oil.nvim', - ---@module 'oil' - ---@type oil.SetupOpts - opts = { - use_default_keymaps = false, - keymaps = { + 'stevearc/oil.nvim', + ---@module 'oil' + ---@type oil.SetupOpts + opts = { + use_default_keymaps = false, + buf_options = { + buflisted = true + }, + keymaps = { [''] = { '', remap = true }, [''] = { callback = function() @@ -18,31 +21,31 @@ return { if cursor_entry.type == 'directory' then oil.select() else - - vim.cmd.wincmd('h') - local bufname = vim.api.nvim_buf_get_name(0) - local is_empty = bufname == '' and not vim.bo.modified - - if is_empty then - vim.cmd(':q') - oil.select({ vertical = true, split = 'topleft' }, function() - vim.cmd.wincmd('l') - vim.api.nvim_win_set_width(0, 40) - vim.cmd.wincmd('h') - end) - else - vim.cmd.wincmd('l') - oil.select({ tab = true }) - end + oil.select(nil, function() + vim.cmd.wincmd('h') + local buf_name = vim.api.nvim_buf_get_name(0) + local is_empty = buf_name == '' and not vim.bo.modified + if is_empty then + -- delete empty buffer + vim.cmd('bd') + else + -- close window of not empty buffer + vim.cmd('q') + end + end) end end, nowait = true }, -- shift space remapping [''] = 'actions.parent', - } - }, - -- dependencies = { { 'echasnovski/mini.icons', opts = {} } }, - dependencies = { 'nvim-tree/nvim-web-devicons' }, -- use if you prefer nvim-web-devicons - -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. - lazy = false, + + [''] = { callback = function() + vim.cmd('bd') + end, nowait = true } + } + }, + -- dependencies = { { 'echasnovski/mini.icons', opts = {} } }, + dependencies = { 'nvim-tree/nvim-web-devicons' }, -- use if you prefer nvim-web-devicons + -- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. + lazy = false, } diff --git a/.config/nvim/lua/config/plugins/telescope.lua b/.config/nvim/lua/config/plugins/telescope.lua index 2280267..3822a4e 100644 --- a/.config/nvim/lua/config/plugins/telescope.lua +++ b/.config/nvim/lua/config/plugins/telescope.lua @@ -13,7 +13,6 @@ return { }, config = function() local actions = require('telescope.actions') - local actions_state = require('telescope.actions.state') require('telescope').setup({ defaults = { mappings = { @@ -23,23 +22,10 @@ return { } }, pickers = { - find_files = { - mappings = { - i = { - [''] = function(prompt_bufnr) - local selection = actions_state.get_selected_entry() - actions.close(prompt_bufnr) - - local bufname = vim.api.nvim_buf_get_name(0) - local is_empty = bufname == '' and not vim.bo.modified - - if is_empty then - vim.cmd('edit' .. vim.fn.fnameescape(selection.path or selection.filename)) - else - vim.cmd('tabnew ' .. vim.fn.fnameescape(selection.path or selection.filename)) - end - end - } + mappings = { + i = { + [''] = actions.file_split, + [''] = actions.file_vsplit } } } @@ -50,7 +36,9 @@ return { local builtin = require('telescope.builtin') - vim.keymap.set('n', '', builtin.find_files, { desc = 'Telescope find files' }) + vim.keymap.set('n', 'sf', builtin.find_files, { desc = 'Telescope find files' }) + + vim.keymap.set('n', 'sp', 'SessionSearch', { desc = 'Search Sessions' }) vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. diff --git a/.config/nvim/lua/config/plugins/treesitter.lua b/.config/nvim/lua/config/plugins/treesitter.lua index 00e3f48..3639771 100644 --- a/.config/nvim/lua/config/plugins/treesitter.lua +++ b/.config/nvim/lua/config/plugins/treesitter.lua @@ -3,7 +3,7 @@ return { build = ':TSUpdate', main = 'nvim-treesitter.configs', -- Sets main module to use for opts opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'css', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'rust', 'python', 'htmldjango' }, + ensure_installed = { 'bash', 'c', 'diff', 'html', 'css', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'rust', 'python', 'htmldjango', 'r' }, auto_install = false, highlight = { enable = true, diff --git a/.config/nvim/lua/config/plugins/ui.lua b/.config/nvim/lua/config/plugins/ui.lua index 49cd0fe..896497b 100644 --- a/.config/nvim/lua/config/plugins/ui.lua +++ b/.config/nvim/lua/config/plugins/ui.lua @@ -1,65 +1,22 @@ return { - { - 'nanozuki/tabby.nvim', - dependencies = 'nvim-tree/nvim-web-devicons', - config = function() - local theme = { - -- this is carbonfox theme - fill = 'TabLineFill', - head = { fg = '#75beff', bg = '#1c1e26' }, - current_tab = { fg = '#1c1e26', bg = '#75beff' }, - tab = { fg = '#c5cdd9', bg = '#1c1e26' }, - win = { fg = '#1c1e26', bg = '#75beff' }, - tail = { fg = '#75beff', bg = '#1c1e26' }, - } - - require('tabby.tabline').set(function(line) - return { - { - { '  ', hl = theme.head }, - line.sep('', theme.head, theme.fill), - }, - line.tabs().foreach(function(tab) - - local hl = tab.is_current() and theme.current_tab or theme.tab - - -- remove count of wins in tab with [n+] included in tab.name() - local name = tab.name() - local index = string.find(name, '%[%d') - local tab_name = index and string.sub(name, 1, index - 1) or name - - -- indicate if any of buffers in tab have unsaved changes - local modified = false - local win_ids = require('tabby.module.api').get_tab_wins(tab.id) - for _, win_id in ipairs(win_ids) do - if pcall(vim.api.nvim_win_get_buf, win_id) then - local bufid = vim.api.nvim_win_get_buf(win_id) - if vim.api.nvim_buf_get_option(bufid, 'modified') then - modified = true - break - end - end - end - - return { - line.sep('', hl, theme.fill), - tab_name, - modified and '', - line.sep('', hl, theme.fill), - hl = hl, - margin = ' ', - } - end), - line.spacer(), - { - line.sep('', theme.tail, theme.fill), - { '  ', hl = theme.tail }, - }, - hl = theme.fill, - } - end) - end - }, + -- { + -- 'akinsho/bufferline.nvim', + -- version = "*", + -- dependencies = 'nvim-tree/nvim-web-devicons', + -- opts = { + -- options = { + -- custom_filter = function(buf, _) + -- local buf_name = vim.api.nvim_buf_get_name(buf) + -- if string.find(buf_name, '^term://') or string.find(buf_name, '^oil://') then + -- return false + -- end + -- return true + -- end, + -- show_buffer_close_icons = false, + -- -- style_preset = require('bufferline').style_preset.minimal + -- } + -- } + -- }, { 'nvim-lualine/lualine.nvim', dependencies = { 'nvim-tree/nvim-web-devicons' }, diff --git a/.config/nvim/lua/config/util.lua b/.config/nvim/lua/config/util.lua index 3a7c893..3e713c8 100644 --- a/.config/nvim/lua/config/util.lua +++ b/.config/nvim/lua/config/util.lua @@ -2,19 +2,22 @@ local function starts_with(str, prefix) return string.find(str, '^' .. prefix) ~= nil end +---get the window for the right dock +---@return integer | nil window window id if exists, nil otherwise local function get_dock_win() local windows = vim.api.nvim_list_wins() for _, win in ipairs(windows) do - if vim.api.nvim_win_get_tabpage(win) == vim.api.nvim_get_current_tabpage() then - local width = vim.api.nvim_win_get_width(win) - if width == 60 or width == 40 then - return win - end + local width = vim.api.nvim_win_get_width(win) + if width == 60 or width == 40 then + return win end end return nil end +---get the buffer which starts with prefix +---@param prefix string prefix of the name of buffer +---@return integer | nil buf buffer id if exists, nil otherwise local function get_dock_buf(prefix) local buffers = vim.api.nvim_list_bufs() for _, buf in ipairs(buffers) do @@ -28,6 +31,22 @@ local function get_dock_buf(prefix) return nil end +---get number of windows that are not docks i.e. right dock +---@param tabpage integer tabpage id of the tab to look in, 0 for current +---@return integer count count of non-dock windows +local function get_no_of_nondock_wins(tabpage) + local wins = vim.api.nvim_tabpage_list_wins(tabpage) + local count = 0 + for _, win in ipairs(wins) do + local buf = vim.api.nvim_win_get_buf(win) + local buf_name = vim.api.nvim_buf_get_name(buf) + if not(starts_with(buf_name, 'term://') or starts_with(buf_name, 'oil://')) then + count = count + 1 + end + end + return count +end + return { open_in_right_dock = function (prefix) @@ -60,7 +79,7 @@ return { end -- no dock window at this point so create new - vim.cmd.vnew() + vim.cmd.vsplit() vim.api.nvim_win_set_width(0, width) -- get existing buf if exists @@ -80,6 +99,6 @@ return { else vim.cmd('Oil') end + end, - end }