new structure

This commit is contained in:
00xJ4CK committed 2024-12-31 02:19:32 +05:45
1 parent d3f06cbee8
commit 2a0e6f86c6
72 files changed
+2659 -2947

No files matched your search

+29 -114
View File
@@ -1,11 +1,8 @@
local function augroup(name)
return vim.api.nvim_create_augroup('nvim' .. name, { clear = true })
return vim.api.nvim_create_augroup('nvim2k_' .. name, { clear = true })
end
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Strip trailing spaces before write │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Strip trailing spaces before write
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
group = augroup('strip_space'),
pattern = { '*' },
@@ -14,19 +11,13 @@ vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Check if we need to reload the file when it changed │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Check if we need to reload the file when it changed
vim.api.nvim_create_autocmd({ 'FocusGained', 'TermClose', 'TermLeave' }, {
group = augroup('checktime'),
command = 'checktime',
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Highlight on yank │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Highlight on yank
vim.api.nvim_create_autocmd('TextYankPost', {
group = augroup('highlight_yank'),
callback = function()
@@ -34,10 +25,7 @@ vim.api.nvim_create_autocmd('TextYankPost', {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ resize splits if window got resized │
-- ╰───────────────────────────────────────────────────────────────────╯
-- resize splits if window got resized
vim.api.nvim_create_autocmd({ 'VimResized' }, {
group = augroup('resize_splits'),
callback = function()
@@ -45,10 +33,7 @@ vim.api.nvim_create_autocmd({ 'VimResized' }, {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ go to last loc when opening a buffer │
-- ╰───────────────────────────────────────────────────────────────────╯
-- go to last loc when opening a buffer
vim.api.nvim_create_autocmd('BufReadPost', {
group = augroup('last_loc'),
callback = function()
@@ -60,10 +45,7 @@ vim.api.nvim_create_autocmd('BufReadPost', {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ close some filetypes with <q> │
-- ╰───────────────────────────────────────────────────────────────────╯
-- close some filetypes with <q>
vim.api.nvim_create_autocmd('FileType', {
group = augroup('close_with_q'),
pattern = {
@@ -71,6 +53,7 @@ vim.api.nvim_create_autocmd('FileType', {
'Jaq',
'PlenaryTestPopup',
'fugitive',
'git',
'help',
'lir',
'lspinfo',
@@ -87,10 +70,7 @@ vim.api.nvim_create_autocmd('FileType', {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ wrap and check for spell in text filetypes │
-- ╰───────────────────────────────────────────────────────────────────╯
-- wrap and check for spell in text filetypes
vim.api.nvim_create_autocmd('FileType', {
group = augroup('wrap_spell'),
pattern = { 'gitcommit', 'markdown' },
@@ -100,11 +80,7 @@ vim.api.nvim_create_autocmd('FileType', {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Auto create dir when saving a file, in case some intermediate │
-- │ directory does not exist │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Auto create dir when saving a file, in case some intermediate directory does not exist
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
group = augroup('auto_create_dir'),
callback = function(event)
@@ -113,20 +89,14 @@ vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
end,
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Set arb filetype │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Set arb filetype
vim.api.nvim_create_autocmd({ 'BufEnter' }, {
group = augroup('set_file_type'),
pattern = { '*.arb' },
command = require('lib.util').get_file_type_cmd('arb'),
})
-- ╭───────────────────────────────────────────────────────────────────╮
-- │ Disable format options │
-- ╰───────────────────────────────────────────────────────────────────╯
-- Disable format options
vim.api.nvim_create_autocmd('FileType', {
group = augroup('disable_formatoptions'),
pattern = '*',
@@ -135,77 +105,22 @@ vim.api.nvim_create_autocmd('FileType', {
end,
})
vim.api.nvim_create_autocmd('BufReadPost', {
callback = function()
if vim.fn.line('\'"') > 1 and vim.fn.line('\'"') <= vim.fn.line('$') then
vim.cmd('normal! g`"')
end
end,
group = augroup('General'),
desc = 'Go To The Last Cursor Position',
})
local function enable_autoformat()
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
group = augroup('autoformat'),
pattern = { '*' },
callback = function()
vim.lsp.buf.format()
end,
})
end
vim.api.nvim_create_autocmd('FileType', {
pattern = { 'c', 'cpp', 'py', 'java', 'cs' },
callback = function()
vim.bo.shiftwidth = 4
end,
group = augroup('General'),
desc = 'Set shiftwidth to 4 in these filetypes',
})
enable_autoformat()
-- Toggle between relative/absolute line numbers
local numbertoggle = augroup('numbertoggle')
vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained', 'InsertLeave', 'CmdlineLeave', 'WinEnter' }, {
pattern = '*',
group = numbertoggle,
callback = function()
if vim.o.nu and vim.api.nvim_get_mode().mode ~= 'i' then
vim.opt.relativenumber = true
end
end,
})
vim.api.nvim_create_autocmd({ 'BufLeave', 'FocusLost', 'InsertEnter', 'CmdlineEnter', 'WinLeave' }, {
pattern = '*',
group = numbertoggle,
callback = function()
if vim.o.nu then
vim.opt.relativenumber = false
vim.cmd.redraw()
end
end,
})
-- ╭─────────────────────────────────────────────────────────╮
-- │ VIM-VISUAL-MULTI │
-- ╰─────────────────────────────────────────────────────────╯
local visual_multi_group = vim.api.nvim_create_augroup('VisualMulti', { clear = true })
vim.api.nvim_create_autocmd('User', {
pattern = 'visual_multi_start',
callback = function()
-- vim.cmd('NoiceDisable')
vim.lsp.inlay_hint.enable(false)
end,
group = visual_multi_group,
})
vim.api.nvim_create_autocmd('User', {
pattern = 'visual_multi_exit',
callback = function()
-- vim.cmd('NoiceEnable')
vim.lsp.inlay_hint.enable(true)
end,
group = visual_multi_group,
})
-- ╭─────────────────────────────────────────────────────────╮
-- │ MESSAGE IF MACRO IS STOPPED │
-- ╰─────────────────────────────────────────────────────────╯
local macro_group = vim.api.nvim_create_augroup('MacroRecording', { clear = true })
vim.api.nvim_create_autocmd('RecordingLeave', {
group = macro_group,
callback = function()
-- Display a message when macro recording stops
print('Macro recording stopped')
end,
})
vim.api.nvim_create_user_command('WriteNoFormat', function()
-- Temporarily disable the autoformat autocmd
vim.api.nvim_del_augroup_by_name('nvim2k_autoformat')
vim.cmd('write')
-- Re-enable the autoformat autocmd
enable_autoformat()
end, {})
+22 -6
View File
@@ -10,22 +10,38 @@ vim.api.nvim_create_user_command('ReloadConfig', function()
vim.notify('Nvim configuration reloaded!', vim.log.levels.INFO)
end, {})
local function copy_to_clipboard(content, message)
vim.fn.setreg('+', content)
vim.notify('Copied "' .. content .. '" to the clipboard!', vim.log.levels.INFO)
end
vim.api.nvim_create_user_command('CopyRelativePath', function()
local path = vim.fn.expand('%')
vim.fn.setreg('+', path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyAbsolutePath', function()
local path = vim.fn.expand('%:p')
vim.fn.setreg('+', path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyRelativePathWithLine', function()
local path = vim.fn.expand('%')
local line = vim.fn.line('.')
local result = path .. ':' .. line
copy_to_clipboard(result, 'Copied "' .. result .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyAbsolutePathWithLine', function()
local path = vim.fn.expand('%:p')
local line = vim.fn.line('.')
local result = path .. ':' .. line
copy_to_clipboard(result, 'Copied "' .. result .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyFileName', function()
local path = vim.fn.expand('%:t')
vim.fn.setreg('+', path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
-- Switch to git root or file parent dir
+13 -68
View File
@@ -18,18 +18,6 @@ vim.g.maplocalleader = ' '
map({ 'n', 'v' }, '<leader>/', 'gcc', { desc = 'Comment toggle', remap = true })
map({ 'v', 'x' }, '<leader>/', 'gc', { desc = 'Comment toggle', remap = true })
-- save file
map({ 'x', 'i', 'n', 's' }, '<C-s>', '<cmd>w<cr>', { desc = 'Save File' })
-- Shortcut for surrounding a word (inner) with a '
map('n', 'S', '<nop>') -- Don't keep S mapping
map('n', 'Sq', "Siw'", { desc = "Wrap word with '", remap = true })
map('n', 'Sp', 'SiW(', { desc = 'Wrap word with ()', remap = true })
map('n', 'Sb', 'Saw}', { desc = 'Wrap word with {}', remap = true })
-- Remove all text
map('n', '<leader>r', '<cmd>%d+<cr>', { desc = 'General | Remove All Text', silent = true })
-- Able to use semicolon in normal mode
map('n', ';', ':', { desc = '; Command mode' })
@@ -79,6 +67,12 @@ map({ 'v', 'x' }, 'K', ":move '<-2<CR>gv-gv", opts)
-- Clear search, diff update and redraw
map({ 'i', 'n' }, '<esc>', '<cmd>noh<cr><esc>', { desc = 'Escape and clear hlsearch' })
-- Cursor navigation on insert mode
map('i', '<M-h>', '<left>', { desc = 'Move Cursor Left' })
map('i', '<M-l>', '<right>', { desc = 'Move Cursor Left' })
map('i', '<M-j>', '<down>', { desc = 'Move Cursor Left' })
map('i', '<M-k>', '<up>', { desc = 'Move Cursor Left' })
-- Consistent n/N search navigation
map('n', 'n', "'Nn'[v:searchforward]", { expr = true, desc = 'Next search result' })
map('x', 'n', "'Nn'[v:searchforward]", { expr = true, desc = 'Next search result' })
@@ -96,59 +90,10 @@ map('i', ',', ',<c-g>u')
map('i', '.', '.<c-g>u')
map('i', ';', ';<c-g>u')
map('n', 'd', '"_d', { desc = 'Delete without replacing clipboad' })
map('n', 'x', '"_x', { desc = 'Cut without replacing clipboad' })
map('n', 'c', '"_c', { desc = 'Change without replacing clipboad' })
map('v', 'p', '"_dP', { desc = 'Paste without replacing clipboard' })
map('n', '<leader>oz', function()
---@diagnostic disable-next-line: undefined-field
if vim.opt.foldcolumn:get() == '0' then
vim.opt.foldcolumn = '1'
else
vim.opt.foldcolumn = '0'
end
end, { desc = 'Toggle foldcolumn' })
map('n', '<leader>op', function()
vim.g.minipairs_disable = not vim.g.minipairs_disable and true or false
end, { desc = 'Toggle mini.pairs' })
-- -- Indent backward
-- vim.keymap.set("n", "<", "<<", { desc = "General | Indent backward", silent = true })
--
-- -- Indent forward
-- vim.keymap.set("n", ">", ">>", { desc = "General | Indent forward", silent = true })
--
-- -- Move the line up
-- vim.keymap.set("n", "<A-j>", "<cmd>m .+1<CR>==", { desc = "General | Move the line up", silent = true })
--
-- -- Move the line down
-- vim.keymap.set("n", "<A-k>", "<cmd>m .-2<CR>==", { desc = "General | Move the line down", silent = true })
--
-- -- Move the line up (Insert Mode)
-- vim.keymap.set("i", "<A-j>", "<Esc>:m .+1<CR>==gi", { desc = "General | Move the line up", silent = true })
--
-- -- Move the line down (Insert Mode)
-- vim.keymap.set("i", "<A-k>", "<Esc>:m .-2<CR>==gi", { desc = "General | Move the line down", silent = true })
--
-- -- Better Down (Visual Mode)
-- vim.keymap.set("v", "j", "v:count == 0 ? 'gj' : 'j'", { desc = "General | Better Down", expr = true, silent = true })
--
-- -- Better Up (Visual Mode)
-- vim.keymap.set("v", "k", "v:count == 0 ? 'gk' : 'k'", { desc = "General | Better Up", expr = true, silent = true })
--
-- -- Better Paste (Visual Mode)
-- vim.keymap.set("v", "p", '"_dP', { desc = "General | Better Paste", silent = true })
--
-- -- Indent backward (Visual Mode)
-- vim.keymap.set("v", "<", "<gv", { desc = "General | Indent backward", silent = true })
--
-- -- Indent forward (Visual Mode)
-- vim.keymap.set("v", ">", ">gv", { desc = "General | Indent forward", silent = true })
--
-- -- Move the selected text up (Visual Mode)
-- vim.keymap.set("v", "<A-j>", "<cmd>m '>+1<CR>gv=gv", { desc = "General | Move the selected text up", silent = true })
--
-- -- Move the selected text down (Visual Mode)
-- vim.keymap.set("v", "<A-k>", "<cmd>m '<-2<CR>gv=gv", { desc = "General | Move the selected text down", silent = true })
-- Move Lines
vim.keymap.set('n', '<A-j>', ':m .+1<CR>==', { desc = 'Move lines', silent = true })
vim.keymap.set('v', '<A-j>', ":m '>+1<CR>gv=gv", { desc = 'Move lines', silent = true })
vim.keymap.set('i', '<A-j>', '<Esc>:m .+1<CR>==gi', { desc = 'Move lines', silent = true })
vim.keymap.set('n', '<A-k>', ':m .-2<CR>==', { desc = 'Move lines', silent = true })
vim.keymap.set('v', '<A-k>', ":m '<-2<CR>gv=gv", { desc = 'Move lines', silent = true })
vim.keymap.set('i', '<A-k>', '<Esc>:m .-2<CR>==gi', { desc = 'Move lines', silent = true })
-108
View File
@@ -1,108 +0,0 @@
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
'git',
'clone',
'--filter=blob:none',
'--single-branch',
'https://github.com/folke/lazy.nvim.git',
lazypath,
})
end
vim.opt.runtimepath:prepend(lazypath)
local status_ok, lazy = pcall(require, 'lazy')
if not status_ok then
return
end
local icons = require('lib.icons')
lazy.setup({
root = vim.fn.stdpath('data') .. '/lazy',
defaults = { lazy = true },
spec = 'plugins',
lockfile = vim.fn.stdpath('config') .. '/lua/lock.json',
concurrency = 8,
dev = { path = '~/Projects/GitHub/', patterns = {}, fallback = false },
install = { missing = true, colorscheme = { 'onedark' } },
git = {
log = { '--since=3 days ago' },
timeout = 120,
url_format = 'https://github.com/%s.git',
filter = true,
},
ui = {
size = { width = 0.9, height = 0.8 },
wrap = true,
border = 'rounded',
icons = {
cmd = icons.ui.Terminal,
config = icons.ui.Gear,
event = icons.ui.Electric,
ft = icons.documents.File,
init = icons.ui.Rocket,
import = icons.documents.Import,
keys = icons.ui.Keyboard,
lazy = icons.ui.Sleep,
loaded = icons.ui.CircleSmall,
not_loaded = icons.ui.CircleSmallEmpty,
plugin = icons.ui.Package,
runtime = icons.ui.Neovim,
source = icons.ui.Code,
start = icons.ui.Play,
task = icons.ui.Check,
list = {
icons.ui.CircleSmall,
icons.ui.Arrow,
icons.ui.Star,
icons.ui.Minus,
},
},
browser = nil,
throttle = 20,
custom_keys = {
['<localleader>l'] = function(plugin)
require('lazy.util').float_term({ 'lazygit', 'log' }, {
cwd = plugin.dir,
})
end,
['<localleader>t'] = function(plugin)
require('lazy.util').float_term(nil, {
cwd = plugin.dir,
})
end,
},
},
diff = { cmd = 'git' },
checker = { enabled = false, concurrency = nil, notify = true, frequency = 3600 },
change_detection = { enabled = true, notify = true },
performance = {
cache = { enabled = true },
reset_packpath = true,
rtp = {
reset = true,
paths = {},
disabled_plugins = {
'gzip',
'tarPlugin',
'zipPlugin',
'tohtml',
-- 'tutor',
-- 'matchit',
-- 'matchparen',
-- 'netrwPlugin',
},
},
},
readme = {
root = vim.fn.stdpath('state') .. '/lazy/readme',
files = { 'README.md', 'lua/**/README.md' },
skip_if_doc_exists = true,
},
state = vim.fn.stdpath('state') .. '/lazy/state.json',
})
+4 -4
View File
@@ -20,12 +20,11 @@ local options = {
ignorecase = true, -- ignore case in search patterns
inccommand = 'split', -- preview incremental substitute
laststatus = 3,
title = true, -- title for context
list = false,
-- listchars = { trail = "", tab = "", nbsp = "_", extends = ">", precedes = "<" }, -- highlight
list = true,
-- listchars = { trail = '', tab = '', nbsp = '_', extends = '>', precedes = '<' }, -- highlight
mouse = 'a', -- allow the mouse to be used in neovim
number = true, -- set numbered lines
numberwidth = 4, -- set number column width to 3 {default 4}
numberwidth = 4, -- set number column width to 2 {default 4}
pumblend = 10, -- Popup blen
pumheight = 10, -- pop up menu height
relativenumber = true, -- set relative numbered lines
@@ -48,6 +47,7 @@ local options = {
tabstop = 4, -- insert 2 spaces for a tab
termguicolors = true, -- set term gui colors (most terminals support this)
timeoutlen = 300, -- time to wait for a mapped sequence to complete (in milliseconds)
title = true, -- window titles
undofile = true, -- enable persistent undo
undolevels = 10000,
updatetime = 50, -- faster completion (4000ms default)