This commit is contained in:
2025-10-20 20:53:54 +03:00
commit b8cad0f750
20 changed files with 1526 additions and 0 deletions

49
lua/config/autocmds.lua Normal file
View File

@@ -0,0 +1,49 @@
-- Automatically create a scratch buffer if Neovim starts with no files
vim.api.nvim_create_autocmd('VimEnter', {
callback = function()
-- Only trigger if no file arguments are passed
if vim.fn.argc() == 0 then
vim.cmd('enew')
vim.bo.buftype = 'nofile'
vim.bo.bufhidden = 'wipe'
vim.bo.swapfile = false
end
end,
})
-- Highlight when yanking (copying) text
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
vim.highlight.on_yank()
end,
})
-- Disable comment continuation only when using 'o'/'O', but keep it for <Enter>
vim.api.nvim_create_autocmd('FileType', {
pattern = '*',
callback = function()
vim.opt_local.formatoptions:remove('o')
end,
})
-- Show cursor line only in active window
vim.api.nvim_create_autocmd({ 'WinEnter', 'InsertLeave' }, {
callback = function()
if vim.w.auto_cursorline then
vim.wo.cursorline = true
vim.w.auto_cursorline = nil
end
end,
})
vim.api.nvim_create_autocmd({ 'WinLeave', 'InsertEnter' }, {
callback = function()
if vim.bo.filetype == 'NvimTree' then
return
end
if vim.wo.cursorline then
vim.w.auto_cursorline = true
vim.wo.cursorline = false
end
end,
})

25
lua/config/clipboard.lua Normal file
View File

@@ -0,0 +1,25 @@
if vim.env.CONTAINER then
vim.g.clipboard = {
name = 'osc52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
end
vim.schedule(function()
vim.opt.clipboard = 'unnamedplus'
end)
-- TEMP: Check if it helps with edge cases
vim.api.nvim_create_user_command('FixClipboard', function()
vim.cmd('lua require("vim.ui.clipboard.osc52")')
vim.schedule(function()
vim.notify('Clipboard provider reloaded (OSC52)')
end)
end, {})

54
lua/config/keymaps.lua Normal file
View File

@@ -0,0 +1,54 @@
local map = vim.keymap.set
map('n', '<leader>q', vim.diagnostic.setloclist)
map({ 'i', 'c' }, 'jk', '<Esc>')
map('n', '<Esc>', '<cmd>nohlsearch<CR>')
-- Prevent overriding the register
map('n', 'x', '"_x')
-- Window Navigation
map('n', '<C-h>', '<C-w>h')
map('n', '<C-l>', '<C-w>l')
map('n', '<C-j>', '<C-w>j')
map('n', '<C-k>', '<C-w>k')
-- Tab management
map('n', '<Leader>tn', ':tabnew<CR>')
map('n', '<Leader>tc', ':tabclose<CR>')
map('n', '<Leader>tl', ':tabnext<CR>')
map('n', '<Leader>th', ':tabprevious<CR>')
map('n', '<Leader>tm.', ':tabmove +1<CR>')
map('n', '<Leader>tm,', ':tabmove -1<CR>')
for i = 1, 9 do
map('n', string.format('<Leader>%d', i), string.format('%dgt', i))
end
-- Buffer Management
-- map('n', '<Leader>bl', ':ls<CR>')
-- map('n', '<Leader>bd', ':bdelete<CR>')
-- map('n', ']b', ':bnext<CR>')
-- map('n', '[b', ':bprevious<CR>')
-- map('n', '<Leader>bb', ':b<Space>')
-- map('n', '<Leader>bo', ':bufdo bd|1bd<CR>')
-- Terminal
map('n', '<leader>tt', ':TermDefault<CR>')
map('n', '<leader>tr', ':TermRelative<CR>')
map('n', '<leader>ts', ':TermSplit<CR>')
map('n', '<leader>tv', ':TermVSplit<CR>')
-- Terminal mode mappings
local tn = '<C-\\><C-n>'
map('t', '<Esc>', tn)
map('t', 'jk', tn)
map('t', '<C-w>', tn .. '<C-w>')
map('t', '<C-h>', '<cmd>wincmd h<CR>')
map('t', '<C-j>', '<cmd>wincmd j<CR>')
map('t', '<C-k>', '<cmd>wincmd k<CR>')
map('t', '<C-l>', '<cmd>wincmd l<CR>')
-- File explorer
vim.keymap.set('n', '<leader>e', '<cmd>NvimTreeToggle<CR>')
vim.keymap.set('n', '<leader>E', '<cmd>NvimTreeOpen<CR>')

89
lua/config/options.lua Normal file
View File

@@ -0,0 +1,89 @@
-- Map Leader
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Disable built-in plugins
vim.loader.enable()
vim.g.loaded_gzip = 1
vim.g.loaded_tar = 1
vim.g.loaded_tarPlugin = 1
vim.g.loaded_zip = 1
vim.g.loaded_zipPlugin = 1
vim.g.loaded_getscript = 1
vim.g.loaded_getscriptPlugin = 1
vim.g.loaded_vimball = 1
vim.g.loaded_vimballPlugin = 1
vim.g.loaded_matchit = 1
vim.g.loaded_2html_plugin = 1
vim.g.loaded_rrhelper = 1
vim.g.loaded_netrw = 1 -- use nvim-tree instead
vim.g.loaded_netrwPlugin = 1
-- UI
vim.g.health = { style = 'float' }
vim.g.have_nerd_font = true
vim.opt.termguicolors = false
vim.opt.textwidth = 100
vim.opt.colorcolumn = '+0'
vim.opt.signcolumn = 'no'
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.cursorline = true
vim.opt.winborder = 'rounded'
vim.opt.guicursor = 'n-v-i-c:block'
vim.opt.ruler = false
vim.opt.laststatus = 3
vim.opt.statusline = '── %f %h%w%m%r %= [%l,%c-%L] ──'
vim.opt.fillchars = {
stl = '',
stlnc = '',
horiz = '',
horizdown = '',
horizup = '',
vert = '',
vertleft = '',
vertright = '',
verthoriz = '',
}
-- Wrap
vim.opt.wrap = false
vim.opt.linebreak = true
vim.opt.breakindent = true
-- Indent
vim.opt.shiftwidth = 2 -- Number of spaces to use for (auto)indent
vim.opt.tabstop = 2 -- Number of spaces that a <Tab> in file counts for
vim.opt.softtabstop = 2 -- Number of spaces when pressing <Tab> in insert mode
vim.opt.expandtab = true -- Use spaces instead of literal tab characters
vim.opt.autoindent = true -- Copy indent from the current line when starting a new one
vim.opt.smartindent = true -- Automatically inserts indents in code blocks (for C-like languages)
-- Scroll and mouse
vim.opt.scrolloff = 10
vim.opt.sidescrolloff = 5
vim.opt.mousescroll = 'hor:1,ver:5'
vim.opt.mouse = 'a' -- Enable mouse support
-- Search
vim.opt.ignorecase = true
vim.opt.smartcase = true -- Override ignorecase if search contains upper case chars
vim.opt.inccommand = 'split' -- Live substitution preview
vim.opt.completeopt = { 'menu,menuone,noselect' }
-- Splits
vim.opt.splitright = true
vim.opt.splitbelow = true
-- Persistence
vim.opt.undofile = true
vim.opt.swapfile = false
-- Tweaks
vim.opt.updatetime = 1000
vim.opt.timeout = true
vim.opt.ttimeout = true
vim.opt.timeoutlen = 500
vim.opt.ttimeoutlen = 10

62
lua/config/terminal.lua Normal file
View File

@@ -0,0 +1,62 @@
local term_group = vim.api.nvim_create_augroup('custom-term-open', { clear = true })
vim.api.nvim_create_autocmd('TermOpen', {
group = term_group,
callback = function()
vim.opt_local.number = false
vim.opt_local.relativenumber = false
vim.opt_local.scrolloff = 0
vim.bo.filetype = 'terminal'
vim.cmd.startinsert()
end,
})
-- Close all terminal buffers before quitting
vim.api.nvim_create_autocmd('QuitPre', {
group = vim.api.nvim_create_augroup('shoutoff_terminals', { clear = true }),
callback = function()
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_loaded(buf) and vim.bo[buf].buftype == 'terminal' then
vim.api.nvim_buf_delete(buf, { force = true })
end
end
end,
})
-- Insert when re-entering a terminal window (after switching back)
vim.api.nvim_create_autocmd('BufEnter', {
group = term_group,
pattern = 'term://*',
callback = function()
if vim.bo.buftype == 'terminal' and vim.fn.mode() ~= 'i' then
vim.cmd.startinsert()
end
end,
})
local function open_default()
vim.cmd('terminal')
end
local function open_relative()
local shell = vim.o.shell or 'zsh'
local dir = vim.fn.expand('%:p:h')
vim.cmd(string.format('edit term://%s//%s', dir, shell))
end
local function open_split()
vim.cmd('new')
vim.cmd('wincmd J')
vim.api.nvim_win_set_height(0, 12)
vim.wo.winfixheight = true
vim.cmd('term')
end
local function open_vertical()
vim.cmd('vsplit')
vim.cmd('term')
end
vim.api.nvim_create_user_command('TermDefault', open_default, {})
vim.api.nvim_create_user_command('TermRelative', open_relative, {})
vim.api.nvim_create_user_command('TermSplit', open_split, {})
vim.api.nvim_create_user_command('TermVSplit', open_vertical, {})