diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 5ea152a..fa66972 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -3,7 +3,10 @@ "auto-session": { "branch": "main", "commit": "00334ee24b9a05001ad50221c8daffbeedaa0842" }, "autoclose.nvim": { "branch": "main", "commit": "b2077aa2c83df7ebc19b2a20a3a0654b24ae9c8f" }, "blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" }, + "diffview.nvim": { "branch": "main", "commit": "4516612fe98ff56ae0415a259ff6361a89419b0a" }, + "dressing.nvim": { "branch": "master", "commit": "2d7c2db2507fa3c4956142ee607431ddb2828639" }, "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, + "flutter-tools.nvim": { "branch": "main", "commit": "8fa438f36fa6cb747a93557d67ec30ef63715c20" }, "gitsigns.nvim": { "branch": "main", "commit": "ee7e50dfbdf49e3acfa416fd3ad3abbdb658582c" }, "harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" }, "image.nvim": { "branch": "master", "commit": "c40215d7d7d1d8c823ee9a77be1a894d5c8df41b" }, diff --git a/.config/nvim/lua/config/keymaps.lua b/.config/nvim/lua/config/keymaps.lua index 871a053..4ec2b47 100644 --- a/.config/nvim/lua/config/keymaps.lua +++ b/.config/nvim/lua/config/keymaps.lua @@ -1,5 +1,3 @@ -local util = require('config.util') - -- NOTE: General -- -- hjkl to ijkl remap @@ -26,32 +24,27 @@ vim.keymap.set({ 'n', 'v', 'o' }, '#', '_', { desc = '# start of line' }) vim.keymap.set('n', '', ':w', { desc = 'ctrl-s save' }) vim.keymap.set('n', '', ':bd', { desc = 'save and close', nowait = true }) --- tabs --- TODO: redo with telescope and ctrl tab - --- 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 +-- NOTE: ctrl m +vim.keymap.set('n', '', 'Floaterminal', { desc = 'open terminal', nowait = true }) +vim.keymap.set('t', '', 'q', { desc = 'close terminal window' }) -vim.keymap.set('n', '', function() - util.open_in_right_dock('term://') -end, { desc = 'open terminal' }) +vim.keymap.set('t', '', 'Floaterminal 1', { desc = 'terminal 1' }) +vim.keymap.set('t', '', 'Floaterminal 2', { desc = 'terminal 2' }) +vim.keymap.set('t', '', 'Floaterminal 3', { desc = 'terminal 3' }) +vim.keymap.set('t', '', 'Floaterminal 4', { desc = 'terminal 4' }) -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' }) - -vim.keymap.set('n', '', function() - util.open_in_right_dock('oil://') -end, { desc = 'open oil' }) +vim.keymap.set('n', '', 'Floateroil', { desc = 'open oil' }) -- NOTE: Windows @@ -164,7 +157,7 @@ vim.api.nvim_create_autocmd('LspAttach', { -- -- This may be unwanted, since they displace some of your code if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then - map('th', function() + map('ih', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) end, '[T]oggle Inlay [H]ints') end @@ -180,5 +173,9 @@ 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", "mc", ":MoltenReevaluateCell", + { silent = false, desc = "reevaluate cell" }) +vim.keymap.set("n", "me", ":noautocmd MoltenEnterOutput", + { silent = true, desc = "show/enter output" }) 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 e077d79..60f52b6 100644 --- a/.config/nvim/lua/config/options.lua +++ b/.config/nvim/lua/config/options.lua @@ -44,7 +44,8 @@ vim.opt.tabstop = 4 vim.opt.shiftwidth = 4 vim.opt.hlsearch = false +vim.opt.wrap = false --- Example for configuring Neovim to load user-installed installed Lua rocks: +-- Example for configring 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/plugins/autosession.lua b/.config/nvim/lua/config/plugins/autosession.lua index ed1dbd7..1b824f2 100644 --- a/.config/nvim/lua/config/plugins/autosession.lua +++ b/.config/nvim/lua/config/plugins/autosession.lua @@ -7,6 +7,16 @@ return { ---@type AutoSession.Config opts = { suppressed_dirs = { '~/', '~/Downloads', '/' }, + pre_save_cmds = { + function() + local bufs = vim.api.nvim_list_bufs() + for _, buf in ipairs(bufs) do + if vim.bo[buf].buftype == 'terminal' then + vim.api.nvim_buf_delete(buf, { force = true, unload = false }) + end + end + end + }, pre_restore_cmds = { -- might not be necessary, but save current harpoon data when we're about to restore a session function() require('harpoon'):sync() end, diff --git a/.config/nvim/lua/config/plugins/git.lua b/.config/nvim/lua/config/plugins/git.lua index 243b1e6..6fffaeb 100644 --- a/.config/nvim/lua/config/plugins/git.lua +++ b/.config/nvim/lua/config/plugins/git.lua @@ -39,69 +39,116 @@ return { }, { "sindrets/diffview.nvim", - }, - { - "NeogitOrg/neogit", - dependencies = { - "nvim-lua/plenary.nvim", - "nvim-telescope/telescope.nvim", - }, - config = function() - require('neogit').setup({ - - kind = 'floating', - graph_style = 'kitty', - disable_line_numbers = false, - disable_relative_line_numbers = false, - commit_editor = { - kind = 'floating', - }, - commit_select_view = { - kind = "floating", - }, - commit_view = { - kind = "floating", - verify_commit = vim.fn.executable("gpg") == 1, -- Can be set to true or false, otherwise we try to find the binary - }, - log_view = { - kind = "floating", - }, - rebase_editor = { - kind = "floating", - }, - reflog_view = { - kind = "floating", - }, - merge_editor = { - kind = "floating", - }, - description_editor = { - kind = "floating", - }, - tag_editor = { - kind = "floating", - }, - preview_buffer = { - kind = "floating", - }, - popup = { - kind = "floating", - }, - stash = { - kind = "floating", - }, - refs_view = { - kind = "floating", - }, - mappings = { - status = { - ['i'] = 'MoveUp', - ['k'] = 'MoveDown', + config = function () + local actions = require('diffview.config').actions + require('diffview').setup({ + keymaps = { + disable_defaults = true, + file_panel = { + ['i'] = '', + ['k'] = '', ['j'] = false, - }, + + [''] = function () actions.toggle_stage_entry() end + + } } }) - vim.keymap.set('n', 'gg', 'Neogit', { desc = 'open neogit '}) end - } + }, + -- { + -- "NeogitOrg/neogit", + -- dependencies = { + -- "nvim-lua/plenary.nvim", + -- "nvim-telescope/telescope.nvim", + -- }, + -- config = function() + -- require('neogit').setup({ + -- + -- kind = 'floating', + -- graph_style = 'kitty', + -- disable_line_numbers = false, + -- disable_relative_line_numbers = false, + -- commit_editor = { + -- kind = 'floating', + -- }, + -- commit_select_view = { + -- kind = "floating", + -- }, + -- commit_view = { + -- kind = "floating", + -- verify_commit = vim.fn.executable("gpg") == 1, -- Can be set to true or false, otherwise we try to find the binary + -- }, + -- log_view = { + -- kind = "floating", + -- }, + -- rebase_editor = { + -- kind = "floating", + -- }, + -- reflog_view = { + -- kind = "floating", + -- }, + -- merge_editor = { + -- kind = "floating", + -- }, + -- description_editor = { + -- kind = "floating", + -- }, + -- tag_editor = { + -- kind = "floating", + -- }, + -- preview_buffer = { + -- kind = "floating", + -- }, + -- popup = { + -- kind = "floating", + -- }, + -- stash = { + -- kind = "floating", + -- }, + -- refs_view = { + -- kind = "floating", + -- }, + -- mappings = { + -- status = { + -- ['i'] = 'MoveUp', + -- ['k'] = 'MoveDown', + -- ['j'] = false, + -- }, + -- } + -- }) + -- vim.keymap.set('n', 'gg', 'Neogit', { desc = 'open neogit '}) + -- end + -- } + -- { + -- 'tpope/vim-fugitive', + -- } + -- { + -- 'sindrets/diffview.nvim', + -- dependencies = { 'nvim-tree/nvim-web-devicons' }, + -- -- lazy, only load diffview by these commands + -- cmd = { + -- 'DiffviewFileHistory', 'DiffviewOpen', 'DiffviewToggleFiles', 'DiffviewFocusFiles', 'DiffviewRefresh' + -- } + -- }, + -- { + -- 'SuperBo/fugit2.nvim', + -- build = false, + -- opts = { + -- width = 100, + -- }, + -- dependencies = { + -- 'MunifTanjim/nui.nvim', + -- 'nvim-tree/nvim-web-devicons', + -- 'nvim-lua/plenary.nvim', + -- -- { + -- -- 'chrisgrieser/nvim-tinygit', -- optional: for Github PR view + -- -- dependencies = { 'stevearc/dressing.nvim' } + -- -- }, + -- }, + -- cmd = { 'Fugit2', 'Fugit2Diff', 'Fugit2Graph' }, + -- keys = { + -- { 'F', mode = 'n', 'Fugit2' } + -- } + -- }, } diff --git a/.config/nvim/lua/config/plugins/harpoon.lua b/.config/nvim/lua/config/plugins/harpoon.lua index 6b82ca9..459891e 100644 --- a/.config/nvim/lua/config/plugins/harpoon.lua +++ b/.config/nvim/lua/config/plugins/harpoon.lua @@ -16,10 +16,10 @@ return { 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) + 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) diff --git a/.config/nvim/lua/config/plugins/init.lua b/.config/nvim/lua/config/plugins/init.lua index 3bf5a1e..1e0a869 100644 --- a/.config/nvim/lua/config/plugins/init.lua +++ b/.config/nvim/lua/config/plugins/init.lua @@ -41,12 +41,13 @@ require('lazy').setup({ require('config.plugins.ui'), require('config.plugins.telescope'), require('config.plugins.blinkcmp'), - require('config.plugins.lsp'), - require('config.plugins.treesitter'), + require('config.plugins.languages.lsp'), + require('config.plugins.languages.treesitter'), require('config.plugins.harpoon'), require('config.plugins.autosession'), - require('config.plugins.molten'), + require('config.plugins.languages.molten'), + require('config.plugins.languages.flutter'), -- NOTE: maybe revisit this later diff --git a/.config/nvim/lua/config/plugins/languages/flutter.lua b/.config/nvim/lua/config/plugins/languages/flutter.lua new file mode 100644 index 0000000..0efe3b9 --- /dev/null +++ b/.config/nvim/lua/config/plugins/languages/flutter.lua @@ -0,0 +1,11 @@ +return { + 'nvim-flutter/flutter-tools.nvim', + lazy = false, + dependencies = { + 'nvim-lua/plenary.nvim', + 'stevearc/dressing.nvim', -- optional for vim.ui.select + }, + config = function() + require('flutter-tools').setup({}) + end, +} diff --git a/.config/nvim/lua/config/plugins/lsp.lua b/.config/nvim/lua/config/plugins/languages/lsp.lua similarity index 100% rename from .config/nvim/lua/config/plugins/lsp.lua rename to .config/nvim/lua/config/plugins/languages/lsp.lua diff --git a/.config/nvim/lua/config/plugins/molten.lua b/.config/nvim/lua/config/plugins/languages/molten.lua similarity index 92% rename from .config/nvim/lua/config/plugins/molten.lua rename to .config/nvim/lua/config/plugins/languages/molten.lua index 9836ea1..e44324f 100644 --- a/.config/nvim/lua/config/plugins/molten.lua +++ b/.config/nvim/lua/config/plugins/languages/molten.lua @@ -6,7 +6,7 @@ return { opts = { backend = 'kitty', -- whatever backend you would like to use max_width = 100, - max_height = 12, + max_height = 20, max_height_window_percentage = math.huge, max_width_window_percentage = math.huge, window_overlap_clear_enabled = true, -- toggles images when windows are overlapped @@ -22,7 +22,6 @@ return { init = function() -- these are examples, not defaults. Please see the readme vim.g.molten_image_provider = 'image.nvim' - vim.g.molten_output_win_max_height = 20 end, } } diff --git a/.config/nvim/lua/config/plugins/treesitter.lua b/.config/nvim/lua/config/plugins/languages/treesitter.lua similarity index 95% rename from .config/nvim/lua/config/plugins/treesitter.lua rename to .config/nvim/lua/config/plugins/languages/treesitter.lua index 3639771..a7b5607 100644 --- a/.config/nvim/lua/config/plugins/treesitter.lua +++ b/.config/nvim/lua/config/plugins/languages/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', 'r' }, + ensure_installed = { 'bash', 'c', 'diff', 'html', 'css', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'rust', 'python', 'htmldjango', 'r', 'dart' }, auto_install = false, highlight = { enable = true, diff --git a/.config/nvim/lua/config/plugins/telescope.lua b/.config/nvim/lua/config/plugins/telescope.lua index df328ef..c706234 100644 --- a/.config/nvim/lua/config/plugins/telescope.lua +++ b/.config/nvim/lua/config/plugins/telescope.lua @@ -41,8 +41,15 @@ return { vim.keymap.set('n', 'ss', builtin.lsp_document_symbols, { desc = 'document symbols' }) vim.keymap.set('n', 'sS', builtin.lsp_workspace_symbols, { desc = 'workspace symbols' }) + vim.keymap.set('n', 'st', 'TodoTelescope', { desc = 'search todos' }) vim.keymap.set('n', 'sp', 'SessionSearch', { desc = 'search sessions' }) + vim.keymap.set('n', 'sh', function () + builtin.help_tags({ + previewer = false + }) + end, { desc = 'help' }) + vim.keymap.set('n', '/', function() -- You can pass additional configuration to Telescope to change the theme, layout, etc. builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { diff --git a/.config/nvim/lua/config/util.lua b/.config/nvim/lua/config/util.lua deleted file mode 100644 index 3e713c8..0000000 --- a/.config/nvim/lua/config/util.lua +++ /dev/null @@ -1,104 +0,0 @@ -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 - 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 - if vim.api.nvim_buf_is_loaded(buf) then - local buf_name = vim.api.nvim_buf_get_name(buf) - if starts_with(buf_name, prefix) then - return buf - end - end - end - 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) - - -- set width accroding to terminal/oil - local width = prefix == 'term://' and 60 or 40 - - -- get dock window if exists - local dock_win = get_dock_win() - if dock_win ~= nil then - - local buf = vim.api.nvim_win_get_buf(dock_win) - local buf_name = vim.api.nvim_buf_get_name(buf) - vim.api.nvim_set_current_win(dock_win) - vim.api.nvim_win_set_width(dock_win, width) - - if starts_with(buf_name, prefix) then - if prefix == 'term://' then - vim.api.nvim_feedkeys('a', 'n', true) - end - else - if prefix == 'term://' then - vim.cmd.term() - vim.api.nvim_feedkeys('a', 'n', true) - else - vim.cmd('Oil') - end - end - return - end - - -- no dock window at this point so create new - vim.cmd.vsplit() - vim.api.nvim_win_set_width(0, width) - - -- get existing buf if exists - local dock_buf = get_dock_buf(prefix) - - if dock_buf ~= nil then - vim.api.nvim_set_current_buf(dock_buf) - if prefix == 'term://' then - vim.api.nvim_feedkeys('a', 'n', true) - end - return - end - - if prefix == 'term://' then - vim.cmd.term() - vim.api.nvim_feedkeys('a', 'n', true) - else - vim.cmd('Oil') - end - end, - -} diff --git a/.config/nvim/plugin/floater.lua b/.config/nvim/plugin/floater.lua new file mode 100644 index 0000000..0df354f --- /dev/null +++ b/.config/nvim/plugin/floater.lua @@ -0,0 +1,92 @@ +---Opens a floating windo +---@param buf? integer buffer-ID of buffer to put in thw window +---@param w_percent? decimal width of floating window will be this * full width +---@param h_percent? decimal height of floating window will be this * full height +---@param opts any options to pass to nvim_open_win +local function open_floating_win(buf, w_percent, h_percent, opts) + buf = buf or vim.api.nvim_create_buf(true, false) + w_percent = w_percent or 0.8 + h_percent = h_percent or 0.8 + local default_opts = { + relative = 'editor', + row = (vim.o.lines - vim.o.lines * h_percent)/2, + col = (vim.o.columns - vim.o.columns * w_percent)/2, + width = math.floor(vim.o.columns * w_percent), + height = math.floor(vim.o.lines * h_percent), + style = 'minimal', + border = 'rounded' + } + opts = vim.tbl_deep_extend('force', default_opts, opts or {}) + vim.api.nvim_open_win(buf, true, opts) +end + +local term_state = { + -1, + -1, + -1, + -1, + last_used = 1, + win = -1, +} + +vim.api.nvim_create_user_command('Floaterminal', function(table) + -- TODO: update last_used buffer if it gets deleted + + local is_new = false + if table.args ~= '' then + + local num = tonumber(table.args) + if num < 1 or num > 4 then + error('numbers from 1 to 4 allowed only') + end + if not vim.api.nvim_win_is_valid(term_state.win) then + error('only specify arguments after opening the floaterminal') + end + + if not vim.api.nvim_buf_is_valid(term_state[num]) then + term_state[num] = vim.api.nvim_create_buf(true, false) + is_new = true + end + + term_state.last_used = num + vim.api.nvim_set_current_buf(term_state[num]) + + else + + if not vim.api.nvim_buf_is_valid(term_state[term_state.last_used]) then + term_state[term_state.last_used] = vim.api.nvim_create_buf(true, false) + is_new = true + end + + open_floating_win(term_state[term_state.last_used]) + + term_state.win = vim.api.nvim_get_current_win() + + end + + if is_new then + vim.cmd.term() + end + if vim.api.nvim_get_mode().mode == 'nt' then + vim.api.nvim_feedkeys('a', 'n', true) + end + +end, { nargs = '?', desc = 'open the floaterminaaal' }) + + +local oil_buf = -1 + +vim.api.nvim_create_user_command('Floateroil', function() + local is_new = false + if not vim.api.nvim_buf_is_valid(oil_buf) then + oil_buf = vim.api.nvim_create_buf(true, false) + is_new = true + end + + open_floating_win(oil_buf) + if is_new then + vim.cmd('Oil') + end + +end, { desc = 'open the floateroil' }) +