initial
This commit is contained in:
1 parent
4d702fab7e
commit
f0ebf86684
55 files changed
+3839
No files matched your search
@@ -0,0 +1,105 @@
|
||||
local function augroup(name)
|
||||
return vim.api.nvim_create_augroup('nvim2k_' .. 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,
|
||||
})
|
||||
@@ -0,0 +1,35 @@
|
||||
-- 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('CRpath', 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('CApath', function()
|
||||
local path = vim.fn.expand('%:p')
|
||||
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, {})
|
||||
@@ -0,0 +1,80 @@
|
||||
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 }
|
||||
|
||||
-- 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",
|
||||
|
||||
-- Use jj as escape
|
||||
map('i', 'jj', '<Esc>', opts)
|
||||
map('t', 'JJ', '<C-\\><C-n>', opts)
|
||||
|
||||
-- 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
|
||||
map('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
|
||||
map('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
|
||||
|
||||
-- Move text up and down
|
||||
map({ 'v', 'x' }, 'J', ":move '>+1<CR>gv-gv", opts)
|
||||
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' })
|
||||
|
||||
-- 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')
|
||||
|
||||
-- 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>e', function()
|
||||
require("oil").toggle_float()
|
||||
end)
|
||||
@@ -0,0 +1,90 @@
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
]])
|
||||
|
||||
vim.opt.path:append({ '**' })
|
||||
|
||||
-- Undercurl
|
||||
vim.cmd([[let &t_Cs = "\e[4:3m"]])
|
||||
vim.cmd([[let &t_Ce = "\e[4:0m"]])
|
||||
|
||||
vim.opt.shortmess:append({ W = true, I = true, c = true })
|
||||
|
||||
if vim.fn.has('nvim-0.9.0') == 1 then
|
||||
vim.opt.splitkeep = 'screen'
|
||||
vim.opt.shortmess:append({ C = true })
|
||||
end
|
||||
|
||||
-- Fix markdown indentation settings
|
||||
vim.g.markdown_recommended_style = 0
|
||||
|
||||
for k, v in pairs(options) do
|
||||
vim.opt[k] = v
|
||||
end
|
||||
|
||||
vim.cmd('set whichwrap+=<,>,[,],h,l')
|
||||
vim.cmd([[set iskeyword+=-]])
|
||||
Reference in new issue
Block a user