neovim conf part 4 i think

This commit is contained in:
RafayAhmad7548 2025-05-01 07:50:51 +05:00
parent ac7ba4097d
commit d6c19e2e92
12 changed files with 154 additions and 166 deletions

View file

@ -1,9 +1,11 @@
{ {
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" }, "LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"auto-session": { "branch": "main", "commit": "00334ee24b9a05001ad50221c8daffbeedaa0842" },
"autoclose.nvim": { "branch": "main", "commit": "b2077aa2c83df7ebc19b2a20a3a0654b24ae9c8f" }, "autoclose.nvim": { "branch": "main", "commit": "b2077aa2c83df7ebc19b2a20a3a0654b24ae9c8f" },
"blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" }, "blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" },
"fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" }, "fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" },
"gitsigns.nvim": { "branch": "main", "commit": "ee7e50dfbdf49e3acfa416fd3ad3abbdb658582c" }, "gitsigns.nvim": { "branch": "main", "commit": "ee7e50dfbdf49e3acfa416fd3ad3abbdb658582c" },
"harpoon": { "branch": "harpoon2", "commit": "ed1f853847ffd04b2b61c314865665e1dadf22c7" },
"image.nvim": { "branch": "master", "commit": "c40215d7d7d1d8c823ee9a77be1a894d5c8df41b" }, "image.nvim": { "branch": "master", "commit": "c40215d7d7d1d8c823ee9a77be1a894d5c8df41b" },
"indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" }, "indent-blankline.nvim": { "branch": "master", "commit": "005b56001b2cb30bfa61b7986bc50657816ba4ba" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" }, "lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
@ -18,9 +20,9 @@
"oil.nvim": { "branch": "master", "commit": "685cdb4ffa74473d75a1b97451f8654ceeab0f4a" }, "oil.nvim": { "branch": "master", "commit": "685cdb4ffa74473d75a1b97451f8654ceeab0f4a" },
"onedark.nvim": { "branch": "master", "commit": "67a74c275d1116d575ab25485d1bfa6b2a9c38a6" }, "onedark.nvim": { "branch": "master", "commit": "67a74c275d1116d575ab25485d1bfa6b2a9c38a6" },
"plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" },
"tabby.nvim": { "branch": "main", "commit": "6362aa9595428cefbb6556c05390e8444d1bcd12" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" },
"telescope.nvim": { "branch": "master", "commit": "a4ed82509cecc56df1c7138920a1aeaf246c0ac5" }, "telescope.nvim": { "branch": "master", "commit": "a4ed82509cecc56df1c7138920a1aeaf246c0ac5" },
"todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" }, "todo-comments.nvim": { "branch": "main", "commit": "304a8d204ee787d2544d8bc23cd38d2f929e7cc5" },
"vim-be-good": { "branch": "master", "commit": "0ae3de14eb8efc6effe7704b5e46495e91931cc5" },
"vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" } "vim-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }
} }

View file

@ -1,3 +1,5 @@
local util = require('config.util')
-- NOTE: General -- -- NOTE: General --
-- hjkl to ijkl remap -- hjkl to ijkl remap
@ -15,6 +17,7 @@ vim.keymap.set({ 'v', 'o' }, '<S-Tab>', '<', { desc = 'S-tab unindent ' })
-- scrolling -- scrolling
vim.keymap.set({ 'n', 'v' }, '<C-d>', '<C-d>zz', { desc = 'centered scroll' }) vim.keymap.set({ 'n', 'v' }, '<C-d>', '<C-d>zz', { desc = 'centered scroll' })
vim.keymap.set({ 'n', 'v' }, '<C-u>', '<C-u>zz', { desc = 'centered scroll' }) vim.keymap.set({ 'n', 'v' }, '<C-u>', '<C-u>zz', { desc = 'centered scroll' })
vim.keymap.set({ 'n', 'v' }, '<C-o>', '<C-o>zz', { desc = 'centered jump back' })
-- start of line -- start of line
vim.keymap.set({ 'n', 'v', 'o' }, '#', '_', { desc = '# start of line' }) vim.keymap.set({ 'n', 'v', 'o' }, '#', '_', { desc = '# start of line' })
@ -25,15 +28,15 @@ vim.keymap.set('n', '<C-w>', ':bd<CR>', { desc = 'save and close', nowait = true
-- tabs -- tabs
-- TODO: redo with telescope and ctrl tab -- TODO: redo with telescope and ctrl tab
vim.keymap.set('n', '<leader><Tab>', ':tabnext<CR>', { desc = 'next buffer' })
vim.keymap.set('n', '<leader><S-Tab>', ':tabprev<CR>', { desc = 'previous buffer', noremap = true }) -- vim.keymap.set('n', '<leader><Tab>', ':bnext<CR>', { desc = 'next buffer' })
-- vim.keymap.set('n', '<leader><S-Tab>', ':bprev<CR>', { desc = 'previous buffer', noremap = true })
-- delete word in insert mode -- delete word in insert mode
vim.keymap.set('i', '<C-BS>', '<C-w>', { desc = 'delete word in insert mode' }) vim.keymap.set('i', '<C-BS>', '<C-w>', { desc = 'delete word in insert mode' })
-- NOTE: Right Dock: Terminal & Oil -- NOTE: Right Dock: Terminal & Oil
local util = require('config.util')
vim.keymap.set('n', '<C-l>', function() vim.keymap.set('n', '<C-l>', function()
util.open_in_right_dock('term://') util.open_in_right_dock('term://')
@ -41,6 +44,7 @@ end, { desc = 'open terminal' })
vim.keymap.set('t', '<C-j>', '<cmd>wincmd h<CR>', { desc = 'focus editor', silent = true }) vim.keymap.set('t', '<C-j>', '<cmd>wincmd h<CR>', { desc = 'focus editor', silent = true })
vim.keymap.set('t', '<C-w>', '<C-d>', { desc = 'kill terminal' }) vim.keymap.set('t', '<C-w>', '<C-d>', { desc = 'kill terminal' })
vim.keymap.set('t', '<F28>', '<cmd>q<CR>', { desc = 'close terminal window' })
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', { desc = 'normal mode in terminal' }) vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', { desc = 'normal mode in terminal' })
@ -166,3 +170,15 @@ vim.api.nvim_create_autocmd('LspAttach', {
end end
end, end,
}) })
-- NOTE: Molten
vim.keymap.set("n", "<leader>mi", ":MoltenInit<CR>",
{ silent = true, desc = "Initialize the plugin" })
vim.keymap.set("n", "<leader>mo", ":MoltenEvaluateOperator<CR>",
{ silent = true, desc = "run operator selection" })
vim.keymap.set("n", "<leader>ml", ":MoltenEvaluateLine<CR>",
{ silent = true, desc = "evaluate line" })
vim.keymap.set("v", "<leader>mv", ":<C-u>MoltenEvaluateVisual<CR>gv",
{ silent = false, desc = "evaluate visual selection" })
vim.keymap.set("n", "<leader>mh", ":MoltenHideOutput<CR>",
{ silent = true, desc = "hide output" })

View file

@ -31,7 +31,7 @@ vim.opt.splitbelow = true
vim.opt.cursorline = true vim.opt.cursorline = true
-- Minimal number of screen lines to keep above and below the cursor. -- 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`), -- 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) -- 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.tabstop = 4
vim.opt.shiftwidth = 4 vim.opt.shiftwidth = 4
vim.opt.hlsearch = false
-- Example for configuring Neovim to load user-installed installed Lua rocks: -- 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/?/init.lua;'
package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?.lua;' package.path = package.path .. ';' .. vim.fn.expand('$HOME') .. '/.luarocks/share/lua/5.1/?.lua;'

View file

@ -1,45 +0,0 @@
-- NOTE: Revisit Later
return {
multicursor = function()
return {
{'i', 'k', mode = {'n'}},
{'<F27>', '<Cmd>MultipleCursorsAddUp<CR>', mode = {'n', 'x'}, desc = 'Add cursor and move up'},
{'<F28>', '<Cmd>MultipleCursorsAddDown<CR>', mode = {'n', 'x'}, desc = 'Add cursor and move down'},
{'<C-LeftMouse>', '<Cmd>MultipleCursorsMouseAddDelete<CR>', mode = {'n', 'i'}, desc = 'Add or remove cursor'},
-- {'<Leader>m', '<Cmd>MultipleCursorsAddVisualArea<CR>', mode = {'x'}, desc = 'Add cursors to the lines of the visual area'},
{'<Leader>a', '<Cmd>MultipleCursorsAddMatches<CR>', mode = {'n', 'x'}, desc = 'Add cursors to cword'},
{'<Leader>A', '<Cmd>MultipleCursorsAddMatchesV<CR>', mode = {'n', 'x'}, desc = 'Add cursors to cword in previous area'},
{'<C-n>', '<Cmd>MultipleCursorsAddJumpNextMatch<CR>', mode = {'n', 'x'}, desc = 'Add cursor and jump to next cword'},
-- {'q', '<Cmd>MultipleCursorsJumpNextMatch<CR>', mode = {'n', 'x'}, desc = 'Jump to next cword'},
-- {'Q', '<Cmd>MultipleCursorsJumpPrevMatch<CR>', mode = {'n', 'x'}, desc = 'Jump to next cword'},
-- {'<Leader>l', '<Cmd>MultipleCursorsLock<CR>', 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
}

View file

@ -0,0 +1,13 @@
return {
'rmagatti/auto-session',
lazy = false,
---enables autocomplete for opts
---@module "auto-session"
---@type AutoSession.Config
opts = {
suppressed_dirs = { '~/', '~/Downloads', '/' },
}
}

View file

@ -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', '<leader>a', function() harpoon:list():add() end)
vim.keymap.set('n', '<C-h>', function() harpoon.ui:toggle_quick_menu(harpoon:list()) end)
vim.keymap.set('n', '<A-1>', function() harpoon:list():select(1) end)
vim.keymap.set('n', '<A-2>', function() harpoon:list():select(2) end)
vim.keymap.set('n', '<A-3>', function() harpoon:list():select(3) end)
vim.keymap.set('n', '<A-q>', function() harpoon:list():select(4) end)
-- -- Toggle previous & next buffers stored within Harpoon list
-- vim.keymap.set('n', '<C-S-P>', function() harpoon:list():prev() end)
-- vim.keymap.set('n', '<C-S-N>', function() harpoon:list():next() end)
end
}

View file

@ -34,6 +34,8 @@ require('lazy').setup({
opts = {}, opts = {},
}, },
'ThePrimeagen/vim-be-good',
require('config.plugins.oil'), require('config.plugins.oil'),
require('config.plugins.git'), require('config.plugins.git'),
require('config.plugins.ui'), require('config.plugins.ui'),
@ -41,6 +43,8 @@ require('lazy').setup({
require('config.plugins.blinkcmp'), require('config.plugins.blinkcmp'),
require('config.plugins.lsp'), require('config.plugins.lsp'),
require('config.plugins.treesitter'), require('config.plugins.treesitter'),
require('config.plugins.autosession'),
require('config.plugins.harpoon'),
require('config.plugins.molten'), require('config.plugins.molten'),

View file

@ -1,10 +1,13 @@
return { return {
'stevearc/oil.nvim', 'stevearc/oil.nvim',
---@module 'oil' ---@module 'oil'
---@type oil.SetupOpts ---@type oil.SetupOpts
opts = { opts = {
use_default_keymaps = false, use_default_keymaps = false,
keymaps = { buf_options = {
buflisted = true
},
keymaps = {
['<C-j>'] = { '<Down><C-j>', remap = true }, ['<C-j>'] = { '<Down><C-j>', remap = true },
['<Space>'] = { callback = function() ['<Space>'] = { callback = function()
@ -18,31 +21,31 @@ return {
if cursor_entry.type == 'directory' then if cursor_entry.type == 'directory' then
oil.select() oil.select()
else else
oil.select(nil, function()
vim.cmd.wincmd('h') vim.cmd.wincmd('h')
local bufname = vim.api.nvim_buf_get_name(0) local buf_name = vim.api.nvim_buf_get_name(0)
local is_empty = bufname == '' and not vim.bo.modified local is_empty = buf_name == '' and not vim.bo.modified
if is_empty then
if is_empty then -- delete empty buffer
vim.cmd(':q') vim.cmd('bd')
oil.select({ vertical = true, split = 'topleft' }, function() else
vim.cmd.wincmd('l') -- close window of not empty buffer
vim.api.nvim_win_set_width(0, 40) vim.cmd('q')
vim.cmd.wincmd('h') end
end) end)
else
vim.cmd.wincmd('l')
oil.select({ tab = true })
end
end end
end, nowait = true }, end, nowait = true },
-- shift space remapping -- shift space remapping
['<F26>'] = 'actions.parent', ['<F26>'] = 'actions.parent',
}
}, ['<C-w>'] = { callback = function()
-- dependencies = { { 'echasnovski/mini.icons', opts = {} } }, vim.cmd('bd')
dependencies = { 'nvim-tree/nvim-web-devicons' }, -- use if you prefer nvim-web-devicons end, nowait = true }
-- Lazy loading is not recommended because it is very tricky to make it work correctly in all situations. }
lazy = false, },
-- 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,
} }

View file

@ -13,7 +13,6 @@ return {
}, },
config = function() config = function()
local actions = require('telescope.actions') local actions = require('telescope.actions')
local actions_state = require('telescope.actions.state')
require('telescope').setup({ require('telescope').setup({
defaults = { defaults = {
mappings = { mappings = {
@ -23,23 +22,10 @@ return {
} }
}, },
pickers = { pickers = {
find_files = { mappings = {
mappings = { i = {
i = { ['<C-s>'] = actions.file_split,
['<CR>'] = function(prompt_bufnr) ['<C-v>'] = actions.file_vsplit
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
}
} }
} }
} }
@ -50,7 +36,9 @@ return {
local builtin = require('telescope.builtin') local builtin = require('telescope.builtin')
vim.keymap.set('n', '<C-o>', builtin.find_files, { desc = 'Telescope find files' }) vim.keymap.set('n', '<leader>sf', builtin.find_files, { desc = 'Telescope find files' })
vim.keymap.set('n', '<leader>sp', '<cmd>SessionSearch<CR>', { desc = 'Search Sessions' })
vim.keymap.set('n', '<leader>/', function() vim.keymap.set('n', '<leader>/', function()
-- You can pass additional configuration to Telescope to change the theme, layout, etc. -- You can pass additional configuration to Telescope to change the theme, layout, etc.

View file

@ -3,7 +3,7 @@ return {
build = ':TSUpdate', build = ':TSUpdate',
main = 'nvim-treesitter.configs', -- Sets main module to use for opts main = 'nvim-treesitter.configs', -- Sets main module to use for opts
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, auto_install = false,
highlight = { highlight = {
enable = true, enable = true,

View file

@ -1,65 +1,22 @@
return { return {
{ -- {
'nanozuki/tabby.nvim', -- 'akinsho/bufferline.nvim',
dependencies = 'nvim-tree/nvim-web-devicons', -- version = "*",
config = function() -- dependencies = 'nvim-tree/nvim-web-devicons',
local theme = { -- opts = {
-- this is carbonfox theme -- options = {
fill = 'TabLineFill', -- custom_filter = function(buf, _)
head = { fg = '#75beff', bg = '#1c1e26' }, -- local buf_name = vim.api.nvim_buf_get_name(buf)
current_tab = { fg = '#1c1e26', bg = '#75beff' }, -- if string.find(buf_name, '^term://') or string.find(buf_name, '^oil://') then
tab = { fg = '#c5cdd9', bg = '#1c1e26' }, -- return false
win = { fg = '#1c1e26', bg = '#75beff' }, -- end
tail = { fg = '#75beff', bg = '#1c1e26' }, -- return true
} -- end,
-- show_buffer_close_icons = false,
require('tabby.tabline').set(function(line) -- -- style_preset = require('bufferline').style_preset.minimal
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
},
{ {
'nvim-lualine/lualine.nvim', 'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' }, dependencies = { 'nvim-tree/nvim-web-devicons' },

View file

@ -2,19 +2,22 @@ local function starts_with(str, prefix)
return string.find(str, '^' .. prefix) ~= nil return string.find(str, '^' .. prefix) ~= nil
end end
---get the window for the right dock
---@return integer | nil window window id if exists, nil otherwise
local function get_dock_win() local function get_dock_win()
local windows = vim.api.nvim_list_wins() local windows = vim.api.nvim_list_wins()
for _, win in ipairs(windows) do 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)
local width = vim.api.nvim_win_get_width(win) if width == 60 or width == 40 then
if width == 60 or width == 40 then return win
return win
end
end end
end end
return nil return nil
end 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 function get_dock_buf(prefix)
local buffers = vim.api.nvim_list_bufs() local buffers = vim.api.nvim_list_bufs()
for _, buf in ipairs(buffers) do for _, buf in ipairs(buffers) do
@ -28,6 +31,22 @@ local function get_dock_buf(prefix)
return nil return nil
end 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 { return {
open_in_right_dock = function (prefix) open_in_right_dock = function (prefix)
@ -60,7 +79,7 @@ return {
end end
-- no dock window at this point so create new -- no dock window at this point so create new
vim.cmd.vnew() vim.cmd.vsplit()
vim.api.nvim_win_set_width(0, width) vim.api.nvim_win_set_width(0, width)
-- get existing buf if exists -- get existing buf if exists
@ -80,6 +99,6 @@ return {
else else
vim.cmd('Oil') vim.cmd('Oil')
end end
end,
end
} }