This commit is contained in:
sankalp committed 2024-08-13 02:51:30 +05:45
1 parent 965247d989
commit ca207347cf
98 files changed
-15609

No files matched your search

-107
View File
@@ -1,107 +0,0 @@
local function augroup(name)
return vim.api.nvim_create_augroup('nvim' .. name, { clear = true })
end
-- Strip trailing spaces before write
vim.api.nvim_create_autocmd({ 'BufWritePre' }, {
group = augroup('strip_space'),
pattern = { '*' },
callback = function()
vim.cmd([[ %s/\s\+$//e ]])
end,
})
-- 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
vim.api.nvim_create_autocmd('TextYankPost', {
group = augroup('highlight_yank'),
callback = function()
vim.highlight.on_yank()
end,
})
-- resize splits if window got resized
vim.api.nvim_create_autocmd({ 'VimResized' }, {
group = augroup('resize_splits'),
callback = function()
vim.cmd('tabdo wincmd =')
end,
})
-- go to last loc when opening a buffer
vim.api.nvim_create_autocmd('BufReadPost', {
group = augroup('last_loc'),
callback = function()
local mark = vim.api.nvim_buf_get_mark(0, '"')
local lcount = vim.api.nvim_buf_line_count(0)
if mark[1] > 0 and mark[1] <= lcount then
pcall(vim.api.nvim_win_set_cursor, 0, mark)
end
end,
})
-- close some filetypes with <q>
vim.api.nvim_create_autocmd('FileType', {
group = augroup('close_with_q'),
pattern = {
'DressingSelect',
'Jaq',
'PlenaryTestPopup',
'fugitive',
'help',
'lir',
'lspinfo',
'man',
'notify',
'qf',
'spectre_panel',
'startuptime',
'tsplayground',
},
callback = function(event)
vim.bo[event.buf].buflisted = false
vim.keymap.set('n', 'q', '<cmd>close<cr>', { buffer = event.buf, silent = true })
end,
})
-- wrap and check for spell in text filetypes
vim.api.nvim_create_autocmd('FileType', {
group = augroup('wrap_spell'),
pattern = { 'gitcommit', 'markdown' },
callback = function()
vim.opt_local.wrap = true
vim.opt_local.spell = true
end,
})
-- 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)
local file = vim.loop.fs_realpath(event.match) or event.match
vim.fn.mkdir(vim.fn.fnamemodify(file, ':p:h'), 'p')
end,
})
-- 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
vim.api.nvim_create_autocmd('FileType', {
group = augroup('disable_formatoptions'),
pattern = '*',
callback = function()
vim.opt_local.formatoptions:remove({ 'c', 'r', 'o' })
end,
})
-41
View File
@@ -1,41 +0,0 @@
-- Reload neovim config
vim.api.nvim_create_user_command('ReloadConfig', function()
for name, _ in pairs(package.loaded) do
if name:match('^plugins') then
package.loaded[name] = nil
end
end
dofile(vim.env.MYVIMRC)
vim.notify('Nvim configuration reloaded!', vim.log.levels.INFO)
end, {})
-- Copy relative path
vim.api.nvim_create_user_command('CopyRelativePath', function()
local path = vim.fn.expand('%')
vim.fn.setreg('+', path)
vim.notify('Copied "' .. path .. '" to the clipboard!')
end, {})
-- Copy absolute path
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!')
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!')
end, {})
-- Switch to git root or file parent dir
vim.api.nvim_create_user_command('RootDir', function()
local root = require('lib.util').get_root_dir()
if root == '' then
return
end
vim.cmd('lcd ' .. root)
end, {})
-211
View File
@@ -1,211 +0,0 @@
local function map(mode, lhs, rhs, opts)
opts = opts or {}
opts.silent = opts.silent ~= false
vim.keymap.set(mode, lhs, rhs, opts)
end
local opts = { noremap = true, silent = true }
local icons = require('lib.icons')
-- Space as leader
map('n', '<Space>', '', opts)
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '
-- Modes
-- normal_mode = "n", insert_mode = "i", visual_mode = "v",
-- visual_block_mode = "x", term_mode = "t", command_mode = "c",
-- Save File
map({
"i",
"v",
"n",
"s"
}, "<C-s>", "<cmd>w<cr><esc>", {
desc = "Save file"
})
-- ctrl a to selected all text in file
map({
"n",
"i",
"v"
}, "<C-a>", "<esc>ggVG")
-- Copy whole file
map("n", "<C-y>", "<cmd>%y+<CR>", {
desc = "Copy whole file"
})
-- Paste
map("n", "]p", "o<Esc>p", {
desc = "Paste below"
})
map("n", "[P", "O<Esc>p", {
desc = "Paste above"
})
map("i", "<C-v>", '<ESC>"+p<ESC>a', {
desc = "Paste from clipboard"
})
map({
"n",
"x"
}, "<C-c>", '"+y<ESC>', {
desc = "Copy to clipboard"
})
-- Better escape using jk in insert and terminal mode
map("i", "jk", "<ESC>")
map("i", "kj", "<ESC>")
map("i", "jj", "<ESC>")
-- Terminal Mappings
map("t", "jk", "<C-\\><C-n>")
map("t", "kj", "<C-\\><C-n>")
map("t", "<ESC>", "<C-\\><C-n>")
-- Visual overwrite paste
map({ 'v', 'x' }, 'p', '"_dP', opts)
-- Do not copy on x
map({ 'v', 'x' }, 'x', '"_x', opts)
-- Increment/decrement
map({ 'n', 'v', 'x' }, '-', '<C-x>', opts)
map({ 'n', 'v', 'x' }, '=', '<C-a>', opts)
-- Move to line beginning and end
map({ 'n', 'v', 'x' }, 'gl', '$', { desc = 'End of line' })
map({ 'n', 'v', 'x' }, 'gh', '^', { desc = 'Beginning of line' })
-- Center Cursors
map('n', 'J', 'mzJ`z', opts)
map('n', '<C-d>', '<C-d>zz', opts)
map('n', '<C-u>', '<C-u>zz', opts)
map('n', 'n', 'nzzzv', opts)
map('n', 'N', 'Nzzzv', opts)
-- Better up/down
vim.keymap.set({ "n", "x" }, "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
vim.keymap.set({ "n", "x" }, "<Down>", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
vim.keymap.set({ "n", "x" }, "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set({ "n", "x" }, "<Up>", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
-- Move text up and down
vim.keymap.set("n", "<A-j>", "<cmd>m .+1<cr>==", { desc = "Move Down" })
vim.keymap.set("n", "<A-k>", "<cmd>m .-2<cr>==", { desc = "Move Up" })
vim.keymap.set("i", "<A-j>", "<esc><cmd>m .+1<cr>==gi", { desc = "Move Down" })
vim.keymap.set("i", "<A-k>", "<esc><cmd>m .-2<cr>==gi", { desc = "Move Up" })
vim.keymap.set("v", "<A-j>", ":m '>+1<cr>gv=gv", { desc = "Move Down" })
vim.keymap.set("v", "<A-k>", ":m '<-4<cr>gv=gv", { desc = "Move Up" })
-- Clear search, diff update and redraw
map({ 'i', 'n' }, '<esc>', '<cmd>noh<cr><esc>', { desc = 'Escape and clear hlsearch' })
-- 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' })
map('o', 'n', "'Nn'[v:searchforward]", { expr = true, desc = 'Next search result' })
map('n', 'N', "'nN'[v:searchforward]", { expr = true, desc = 'Prev search result' })
map('x', 'N', "'nN'[v:searchforward]", { expr = true, desc = 'Prev search result' })
map('o', 'N', "'nN'[v:searchforward]", { expr = true, desc = 'Prev search result' })
-- Better indenting
map('v', '<', '<gv')
map('v', '>', '>gv')
-- Add undo breakpoints
map('i', ',', ',<c-g>u')
map('i', '.', '.<c-g>u')
map('i', ';', ';<c-g>u')
-- Search
map({
"n",
"x"
}, "gw", "*N", {
desc = "Search word under cursor"
})
-- Insert empty line in insert mode
map("i", "<A-o>", "<C-O>o", {
desc = "Insert empty line below"
})
map("i", "<A-O>", "<C-O>O", {
desc = "Insert empty line above"
})
-- Insert empty line without entering insert mode
map('n', '[o', ':<C-u>call append(line("."), repeat([""], v:count1))<CR>', {
desc = "Insert empty line below"
})
map('n', ']o', ':<C-u>call append(line(".")-1, repeat([""], v:count1))<CR>', {
desc = "Insert empty line above"
})
-- go to beginning and end in insert mode
map("i", "<A-b>", "<ESC>^i", {
desc = "Go to beginning of line"
})
map("i", "<A-e>", "<End>", {
desc = "Go to end of line"
})
-- navigate within insert mode
map("i", "<C-h>", "<Left>", {
desc = "Move Left"
})
map("i", "<C-l>", "<Right>", {
desc = "Move Right"
})
map("i", "<C-j>", "<Down>", {
desc = "Move Down"
})
map("i", "<C-k>", "<Up>", {
desc = "Move Up"
})
-- Move to window using the <ctrl> hjkl keys
vim.keymap.set("n", "<C-h>", "<C-w>h", { desc = "Go to Left Window", remap = true })
vim.keymap.set("n", "<C-j>", "<C-w>j", { desc = "Go to Lower Window", remap = true })
vim.keymap.set("n", "<C-k>", "<C-w>k", { desc = "Go to Upper Window", remap = true })
vim.keymap.set("n", "<C-l>", "<C-w>l", { desc = "Go to Right Window", remap = true })
-- Move with shift-arrows
map("n", "<S-Left>", "<C-w><S-h>", {
desc = "Move window to the left"
})
map("n", "<S-Down>", "<C-w><S-j>", {
desc = "Move window down"
})
map("n", "<S-Up>", "<C-w><S-k>", {
desc = "Move window up"
})
map("n", "<S-Right>", "<C-w><S-l>", {
desc = "Move window to the right"
})
-- Resize window using <ctrl> arrow keys
vim.keymap.set("n", "<C-Up>", "<cmd>resize +2<cr>", { desc = "Increase Window Height" })
vim.keymap.set("n", "<C-Down>", "<cmd>resize -2<cr>", { desc = "Decrease Window Height" })
vim.keymap.set("n", "<C-Left>", "<cmd>vertical resize -2<cr>", { desc = "Decrease Window Width" })
vim.keymap.set("n", "<C-Right>", "<cmd>vertical resize +2<cr>", { desc = "Increase Window Width" })
-- Codeium
map('i', '<M-;>', function () return vim.fn['codeium#Accept']() end, { expr = true, silent = true })
map('i', '<M-]>', function() return vim.fn['codeium#CycleCompletions'](1) end, { expr = true, silent = true })
map('i', '<M-[>', function() return vim.fn['codeium#CycleCompletions'](-1) end, { expr = true, silent = true })
map('i', '<M-c>', function() return vim.fn['codeium#Clear']() end, { expr = true, silent = true })
map('n', '<leader>mu', function()
require("notify").dismiss({ silent = true, pending = true })
end, { desc = 'Dismiss All Notifications' })
-89
View File
@@ -1,89 +0,0 @@
local options = {
ai = true,
autoindent = true,
autowrite = true,
backspace = 'indent,eol,start',
backup = false, -- creates a backup file
breakindent = true,
clipboard = 'unnamedplus', -- allows neovim to access the system clipboard
cmdheight = 1, -- more space in the neovim command line for displaying messages
completeopt = 'menu,menuone,noselect', -- mostly just for cmp
conceallevel = 0, -- so that `` is visible in markdown files
confirm = true, -- Confirm to save changes before exiting modified buffer
cursorline = true, -- highlight the current line
expandtab = true, -- convert tabs to spaces
fileencoding = 'utf-8', -- the encoding written to a file
formatoptions = 'jlnqt', -- set formatoptions, check help fo-table
grepformat = '%f:%l:%c:%m',
grepprg = 'rg --vimgrep',
hlsearch = true, -- highlight all matches on previous search pattern
ignorecase = true, -- ignore case in search patterns
inccommand = 'split', -- preview incremental substitute
laststatus = 3,
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 2 {default 4}
pumblend = 10, -- Popup blen
pumheight = 10, -- pop up menu height
relativenumber = true, -- set relative numbered lines
scrolloff = 10, -- is one of my fav
sessionoptions = 'blank,buffers,curdir,folds,help,tabpages,winsize,winpos,terminal',
shiftround = true, -- Round indent
shiftwidth = 4, -- the number of spaces inserted for each indentation
showcmd = false,
showmode = false, -- we don't need to see things like -- INSERT -- anymore
showtabline = 0, -- always show tabs
si = true,
sidescrolloff = 8,
signcolumn = 'yes', -- always show the sign column, otherwise it would shift the text each time
smartcase = true, -- smart case
smartindent = true, -- make indenting smarter again
smarttab = true,
splitbelow = true, -- force all horizontal splits to go below current window
splitright = true, -- force all vertical splits to go to the right of current window
swapfile = false, -- creates a swapfile
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)
undofile = true, -- enable persistent undo
undolevels = 10000,
updatetime = 50, -- faster completion (4000ms default)
wildmenu = true, -- wildmenu
wildmode = 'longest:full,full', -- Command-line completion mode
winminwidth = 5, -- Minimum window width
wrap = false, -- display lines as one long line
writebackup = false, -- do not edit backups
}
for k, v in pairs(options) do
vim.opt[k] = v
end
-- netrw file explorer settings
vim.g.netrw_winsize = 20
vim.g.netrw_banner = 0
vim.g.netrw_liststyle = 1
-- Fix markdown indentation settings
vim.g.markdown_recommended_style = 0
vim.opt.path:append({ '**' })
vim.opt.shortmess:append({ W = true, I = true, c = true })
-- hides `~` at the end of the buffer
vim.cmd([[set fillchars+=eob:\ ]])
vim.cmd([[
setlocal spell spelllang=en "Set spellcheck language to en
setlocal spell! "Disable spell checks by default
filetype plugin indent on
if has('win32')
let g:python3_host_prog = $HOME . '/scoop/apps/python/current/python.exe'
endif
let &t_Cs = "\e[4:3m" "Undercurl
let &t_Ce = "\e[4:0m"
set whichwrap+=<,>,[,],h,l
set iskeyword+=-
]])