neovim config part 2

This commit is contained in:
RafayAhmad7548 2025-04-25 20:25:48 +05:00
parent 21bcbd0bdc
commit 6f23ebd0f5
4 changed files with 368 additions and 61 deletions

View file

@ -1,12 +1,23 @@
{
"LuaSnip": { "branch": "master", "commit": "03c8e67eb7293c404845b3982db895d59c0d1538" },
"autoclose.nvim": { "branch": "main", "commit": "b2077aa2c83df7ebc19b2a20a3a0654b24ae9c8f" },
"blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" },
"fidget.nvim": { "branch": "main", "commit": "d9ba6b7bfe29b3119a610892af67602641da778e" },
"gitsigns.nvim": { "branch": "main", "commit": "ee7e50dfbdf49e3acfa416fd3ad3abbdb658582c" },
"lazy.nvim": { "branch": "main", "commit": "6c3bda4aca61a13a9c63f1c1d1b16b9d3be90d7a" },
"lazydev.nvim": { "branch": "main", "commit": "2367a6c0a01eb9edb0464731cc0fb61ed9ab9d2c" },
"lualine.nvim": { "branch": "master", "commit": "15884cee63a8c205334ab13ab1c891cd4d27101a" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "1a31f824b9cd5bc6f342fc29e9a53b60d74af245" },
"mason-tool-installer.nvim": { "branch": "main", "commit": "1255518cb067e038a4755f5cb3e980f79b6ab89c" },
"mason.nvim": { "branch": "main", "commit": "fc98833b6da5de5a9c5b1446ac541577059555be" },
"nvim-lspconfig": { "branch": "master", "commit": "8b0f47d851ee5343d38fe194a06ad16b9b9bd086" },
"nvim-treesitter": { "branch": "master", "commit": "684eeac91ed8e297685a97ef70031d19ac1de25a" },
"nvim-web-devicons": { "branch": "master", "commit": "68f70df44652d310d2adedf181b174c33a693665" },
"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-sleuth": { "branch": "master", "commit": "be69bff86754b1aa5adcbb527d7fcd1635a84080" }
}

View file

@ -1,4 +1,4 @@
-- General --
-- NOTE: General --
-- hjkl to ijkl remap
vim.keymap.set({ 'n', 'v', 'o' }, 'j', 'h', { desc = 'hjkl to ijkl' })
@ -6,14 +6,12 @@ vim.keymap.set({ 'n', 'v', 'o' }, 'h', 'i', { desc = 'hjkl to ijkl' })
vim.keymap.set({ 'n', 'v', 'o' }, 'i', 'k', { desc = 'hjkl to ijkl' })
vim.keymap.set({ 'n', 'v', 'o' }, 'k', 'j', { desc = 'hjkl to ijkl' })
-- indentation
vim.keymap.set('n', '<Tab>', '>>', { desc = 'tab indent ' })
vim.keymap.set('n', '<S-Tab>', '<<', { desc = 'S-tab unindent ' })
vim.keymap.set({ 'v', 'o' }, '<Tab>', '>', { desc = 'tab indent ' })
vim.keymap.set({ 'v', 'o' }, '<S-Tab>', '<', { desc = 'S-tab unindent ' })
-- scrolling
vim.keymap.set({ 'n', 'v', 'o' }, '<C-d>', '<C-d>zz', { desc = 'centered scroll' })
vim.keymap.set({ 'n', 'v', 'o' }, '<C-u>', '<C-u>zz', { desc = 'centered scroll' })
@ -24,11 +22,76 @@ vim.keymap.set({ 'n', 'v', 'o' }, '#', '_', { desc = '# start of line' })
-- save
vim.keymap.set('n', '<C-s>', ':w<CR>', { desc = 'ctrl-s save' })
-- Buffers --
vim.keymap.set('n', '<leader>l', ':tabnext<CR>', { desc = 'next buffer' })
vim.keymap.set('n', '<leader>j', ':tabprev<CR>', { desc = 'previous buffer' })
-- tabs
vim.keymap.set('n', '<leader><Tab>', ':tabnext<CR>', { desc = 'next buffer' })
vim.keymap.set('n', '<leader><S-Tab>', ':tabprev<CR>', { desc = 'previous buffer' })
-- delete word in insert mode
vim.keymap.set('i', '<C-BS>', '<C-w>', { desc = 'delete word in insert mode' })
-- tab luasnip
-- TODO: fix this for snippets
vim.keymap.del('i', '<Tab>', { desc = 'remove keymap cause not be worky' })
-- NOTE: Terminal
vim.keymap.set('n', '<C-l>', function ()
local buffers = vim.api.nvim_list_bufs()
local terminal_exists = false
for _, buf in ipairs(buffers) do
local buf_name = vim.api.nvim_buf_get_name(buf)
-- find all terminal buffers
if vim.api.nvim_buf_is_loaded(buf) and string.find(buf_name, '^term://') ~= nil then
-- find window of first terminal window if exists
local window_exists = false
local windows = vim.api.nvim_list_wins()
for _, win in ipairs(windows) do
if vim.api.nvim_win_get_buf(win) == buf then
vim.api.nvim_set_current_win(win)
window_exists = true
break
end
end
-- window dosnt exist so create and put existing terminal there
if not window_exists then
vim.cmd.vnew()
vim.api.nvim_win_set_width(0, 60)
vim.api.nvim_set_current_buf(buf)
end
terminal_exists = true
end
end
-- if no terminal then create new one
if not terminal_exists then
vim.cmd.vnew()
vim.cmd.term()
vim.api.nvim_win_set_width(0, 60)
end
vim.api.nvim_feedkeys('a', 'n', true)
end, { desc = 'open terminal', 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', '<Esc>', '<C-\\><C-n>', { desc = 'normal mode in terminal' })
-- NOTE: Windows
-- this is weird because ctrl-i => Up & ctrl-k => Down in Kitty conf
vim.keymap.set({ 'n', 'v', 'o' }, '<Down><Up>', ':wincmd k<CR>', { desc = 'moving around window using ctrl-k ijkl', silent = true })
vim.keymap.set({ 'n', 'v', 'o' }, '<Down><Down>', ':wincmd j<CR>', { desc = 'moving around window using ctrl-k ijkl', silent = true })
vim.keymap.set({ 'n', 'v', 'o' }, '<Down><C-l>', ':wincmd l<CR>', { desc = 'moving around window using ctrl-k ijkl', silent = true })
vim.keymap.set({ 'n', 'v', 'o' }, '<Down><C-j>', ':wincmd h<CR>', { desc = 'moving around window using ctrl-k ijkl', silent = true })
-- NOTE: Telescope --
-- Telescope --
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<C-o>', builtin.find_files, { desc = 'Telescope find files' })
@ -39,4 +102,19 @@ vim.keymap.set('n', '<leader>/', function()
winblend = 10,
previewer = false,
})
end, { desc = '[/] Fuzzily search in current buffer' })
end, { desc = 'Fuzzily search in current buffer' })
local mappings = {
telescope_defaults = function(actions)
return {
i = {
["<esc>"] = actions.close,
["<C-k>"] = actions.move_selection_next,
["<C-i>"] = actions.move_selection_previous,
}
}
end
}
return mappings

View file

@ -38,6 +38,5 @@ vim.opt.scrolloff = 10
-- See `:help 'confirm'`
vim.opt.confirm = true
vim.opt.signcolumn = yes
vim.opt.fillchars:append({ eob = " " })
vim.o.showtabline = 2

View file

@ -11,38 +11,31 @@ end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)
require('lazy').setup({
-- NOTE: General --
'tpope/vim-sleuth', -- Detect tabstop and shiftwidth automatically
{ 'm4xshen/autoclose.nvim', opts = {} },
{ 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = {} },
-- {
-- "folke/tokyonight.nvim",
-- priority = 1000,
-- config = function()
-- require('tokyonight').setup {
-- styles = {
-- comments = { italic = false }, -- Disable italics in comments
-- },
-- }
-- vim.cmd.colorscheme 'tokyonight-night'
-- end
-- },
{
'm4xshen/autoclose.nvim',
config = function()
require('autoclose').setup({})
'navarasu/onedark.nvim',
config = function ()
require('onedark').load()
end
},
{
'lewis6991/gitsigns.nvim',
opts = {
signs = {
add = { text = '' },
change = { text = '' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
untracked = { text = '' },
},
signs_staged = {
add = { text = '' },
change = { text = '' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
untracked = { text = '' },
},
signs_staged_enable = true,
signcolumn = true
}
},
-- NOTE: Telescope --
{
'nvim-telescope/telescope.nvim',
dependencies = {
@ -50,12 +43,10 @@ require('lazy').setup({
{
'nvim-telescope/telescope-fzf-native.nvim',
build = 'make',
-- cond = function()
-- return vim.fn.executable 'make' == 1
-- end,
cond = function()
return vim.fn.executable 'make' == 1
end,
},
},
config = function()
@ -63,14 +54,7 @@ require('lazy').setup({
local actions_state = require('telescope.actions.state')
require('telescope').setup({
defaults = {
mappings = {
i = {
["<esc>"] = actions.close,
["<C-k>"] = actions.move_selection_next,
["<C-i>"] = actions.move_selection_previous,
}
}
mappings = require('config.keymaps').telescope_defaults(actions)
},
pickers = {
find_files = {
@ -79,7 +63,15 @@ require('lazy').setup({
["<CR>"] = function(prompt_bufnr)
local selection = actions_state.get_selected_entry()
actions.close(prompt_bufnr)
vim.cmd("tabnew " .. vim.fn.fnameescape(selection.path or selection.filename))
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
}
}
@ -90,6 +82,217 @@ require('lazy').setup({
end
},
-- NOTE: AutoCompletions, LSP --
{
'saghen/blink.cmp',
event = 'VimEnter',
version = '1.*',
dependencies = {
{
'L3MON4D3/LuaSnip',
version = '2.*',
build = (function()
if vim.fn.has 'win32' == 1 or vim.fn.executable 'make' == 0 then
return
end
return 'make install_jsregexp'
end)(),
dependencies = {
-- `friendly-snippets` contains a variety of premade snippets.
-- See the README about individual language/framework/plugin snippets:
-- https://github.com/rafamadriz/friendly-snippets
-- {
-- 'rafamadriz/friendly-snippets',
-- config = function()
-- require('luasnip.loaders.from_vscode').lazy_load()
-- end,
-- },
},
opts = {},
},
'folke/lazydev.nvim',
},
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
keymap = {
preset = 'default',
['<C-i>'] = { 'select_prev' },
['<C-k>'] = { 'select_next' },
['<Tab>'] = { 'select_and_accept', 'fallback'},
-- ['<Esc>'] = { 'hide' },
},
appearance = { nerd_font_variant = 'mono' },
completion = {
-- By default, you may press `<c-space>` to show the documentation.
-- Optionally, set `auto_show = true` to show the documentation after a delay.
documentation = { auto_show = false, auto_show_delay_ms = 500 },
},
sources = {
default = { 'lsp', 'path', 'snippets', 'lazydev' },
providers = {
lazydev = { module = 'lazydev.integrations.blink', score_offset = 100 },
},
},
snippets = { preset = 'luasnip' },
-- Blink.cmp includes an optional, recommended rust fuzzy matcher,
-- which automatically downloads a prebuilt binary when enabled.
--
-- By default, we use the Lua implementation instead, but you may enable
-- the rust implementation via `'prefer_rust_with_warning'`
--
-- See :h blink-cmp-config-fuzzy for more information
fuzzy = { implementation = 'lua' },
-- Shows a signature help window while you type arguments for a function
signature = { enabled = true },
},
},
{
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = '${3rd}/luv/library', words = { 'vim%.uv' } },
},
},
},
{ "williamboman/mason.nvim", opts = {} },
{
'neovim/nvim-lspconfig',
dependencies = {
{ "williamboman/mason.nvim", opts = {} },
'williamboman/mason-lspconfig.nvim',
'WhoIsSethDaniel/mason-tool-installer.nvim',
-- Useful status updates for LSP.
{ 'j-hui/fidget.nvim', opts = {} },
-- completeions
'saghen/blink.cmp',
},
config = function()
vim.diagnostic.config {
severity_sort = true,
float = { border = 'rounded', source = 'if_many' },
underline = { severity = vim.diagnostic.severity.ERROR },
signs = vim.g.have_nerd_font and {
text = {
[vim.diagnostic.severity.ERROR] = '󰅚 ',
[vim.diagnostic.severity.WARN] = '󰀪 ',
[vim.diagnostic.severity.INFO] = '󰋽 ',
[vim.diagnostic.severity.HINT] = '󰌶 ',
},
} or {},
virtual_text = {
source = 'if_many',
spacing = 2,
format = function(diagnostic)
local diagnostic_message = {
[vim.diagnostic.severity.ERROR] = diagnostic.message,
[vim.diagnostic.severity.WARN] = diagnostic.message,
[vim.diagnostic.severity.INFO] = diagnostic.message,
[vim.diagnostic.severity.HINT] = diagnostic.message,
}
return diagnostic_message[diagnostic.severity]
end,
},
}
local capabilities = require('blink.cmp').get_lsp_capabilities()
local servers = {
-- clangd = {},
-- pyright = {},
rust_analyzer = {},
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
--
-- Some languages (like typescript) have entire language plugins that can be useful:
-- https://github.com/pmizio/typescript-tools.nvim
--
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},
--
lua_ls = {
-- cmd = { ... },
-- filetypes = { ... },
-- capabilities = {},
settings = {
Lua = {
completion = {
callSnippet = 'Replace',
},
-- You can toggle below to ignore Lua_LS's noisy `missing-fields` warnings
-- diagnostics = { disable = { 'missing-fields' } },
},
},
},
}
local ensure_installed = vim.tbl_keys(servers or {})
require('mason-tool-installer').setup { ensure_installed = ensure_installed }
require('mason-lspconfig').setup {
ensure_installed = {}, -- explicitly set to an empty table (already done using mason tool installer)
automatic_installation = false,
handlers = {
function(server_name)
local server = servers[server_name] or {}
-- This handles overriding only values explicitly passed
-- by the server configuration above. Useful when disabling
-- certain features of an LSP (for example, turning off formatting for ts_ls)
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
require('lspconfig')[server_name].setup(server)
end,
}
}
end
},
-- NOTE: TreeSitter
{
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
opts = {
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc', 'rust' },
auto_install = true,
highlight = {
enable = true,
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
-- If you are experiencing weird indenting issues, add the language to
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
-- additional_vim_regex_highlighting = { 'ruby' },
},
-- indent = { enable = true, disable = { 'ruby' } },
},
-- There are additional nvim-treesitter modules that you can use to interact
-- with nvim-treesitter. You should go explore a few and see what interests you:
--
-- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
-- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
-- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
},
-- NOTE: UI --
{
'nanozuki/tabby.nvim',
dependencies = 'nvim-tree/nvim-web-devicons',
@ -151,16 +354,32 @@ require('lazy').setup({
end)
end
},
{
'lewis6991/gitsigns.nvim',
opts = {
signs = {
add = { text = '' },
change = { text = '' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
untracked = { text = '' },
},
signs_staged = {
add = { text = '' },
change = { text = '' },
delete = { text = '_' },
topdelete = { text = '' },
changedelete = { text = '~' },
untracked = { text = '' },
},
signs_staged_enable = true,
signcolumn = true
}
},
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
opts = {
options = {
theme = 'ayu_mirage'
}
}
opts = {}
}
})