huge updates
This commit is contained in:
1 parent
ca26b00c27
commit
18bd0cb00b
49 files changed
+4210
-2140
No files matched your search
@@ -0,0 +1,161 @@
|
||||
local function augroup(name)
|
||||
return vim.api.nvim_create_augroup('nvim2k_' .. name, { clear = true })
|
||||
end
|
||||
|
||||
-- don't auto comment new line
|
||||
vim.api.nvim_create_autocmd('BufEnter', { command = [[set formatoptions-=cro]] })
|
||||
|
||||
-- to make border as same as neovim ColorScheme
|
||||
vim.api.nvim_create_autocmd({ 'UIEnter', 'ColorScheme' }, {
|
||||
callback = function()
|
||||
local normal = vim.api.nvim_get_hl(0, { name = 'Normal' })
|
||||
if not normal.bg then
|
||||
return
|
||||
end
|
||||
io.write(string.format('\027Ptmux;\027\027]11;#%06x\007\027\\', normal.bg))
|
||||
io.write(string.format('\027]11;#%06x\027\\', normal.bg))
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('UILeave', {
|
||||
callback = function()
|
||||
io.write('\027Ptmux;\027\027]111;\007\027\\')
|
||||
io.write('\027]111\027\\')
|
||||
end,
|
||||
})
|
||||
|
||||
-- Highlight on yank
|
||||
vim.api.nvim_create_autocmd('TextYankPost', {
|
||||
group = augroup('highlight_yank'),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
-- go to last loc when opening a buffer
|
||||
-- this mean that when you open a file, you will be at the last position
|
||||
vim.api.nvim_create_autocmd('BufReadPost', {
|
||||
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,
|
||||
})
|
||||
|
||||
-- auto close brackets
|
||||
vim.api.nvim_create_autocmd('FileType', { pattern = 'man', command = [[nnoremap <buffer><silent> q :quit<CR>]] })
|
||||
|
||||
-- show cursor line only in active window
|
||||
local cursorGrp = vim.api.nvim_create_augroup('CursorLine', { clear = true })
|
||||
vim.api.nvim_create_autocmd({ 'InsertLeave', 'WinEnter' }, {
|
||||
pattern = '*',
|
||||
command = 'set cursorline',
|
||||
group = cursorGrp,
|
||||
})
|
||||
vim.api.nvim_create_autocmd(
|
||||
{ 'InsertEnter', 'WinLeave' },
|
||||
{ pattern = '*', command = 'set nocursorline', group = cursorGrp }
|
||||
)
|
||||
|
||||
-- Enable spell checking for certain file types
|
||||
vim.api.nvim_create_autocmd(
|
||||
{ 'BufRead', 'BufNewFile' },
|
||||
-- { pattern = { "*.txt", "*.md", "*.tex" }, command = [[setlocal spell<cr> setlocal spelllang=en,de<cr>]] }
|
||||
{
|
||||
pattern = { '*.txt', '*.md', '*.tex' },
|
||||
callback = function()
|
||||
vim.opt.spell = true
|
||||
vim.opt.spelllang = 'en,de'
|
||||
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,
|
||||
})
|
||||
|
||||
-- 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',
|
||||
})
|
||||
|
||||
-- resize splits if window got resized
|
||||
vim.api.nvim_create_autocmd({ 'VimResized' }, {
|
||||
group = augroup('resize_splits'),
|
||||
callback = function()
|
||||
vim.cmd('tabdo wincmd =')
|
||||
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('core.util').get_file_type_cmd('arb'),
|
||||
})
|
||||
|
||||
-- close some filetypes with <q>
|
||||
vim.api.nvim_create_autocmd('FileType', {
|
||||
group = vim.api.nvim_create_augroup('close_with_q', { clear = true }),
|
||||
pattern = {
|
||||
'PlenaryTestPopup',
|
||||
'help',
|
||||
'lspinfo',
|
||||
'man',
|
||||
'notify',
|
||||
'qf',
|
||||
'spectre_panel',
|
||||
'startuptime',
|
||||
'tsplayground',
|
||||
'neotest-output',
|
||||
'checkhealth',
|
||||
'neotest-summary',
|
||||
'neotest-output-panel',
|
||||
},
|
||||
callback = function(event)
|
||||
vim.bo[event.buf].buflisted = false
|
||||
vim.keymap.set('n', 'q', '<cmd>close<cr>', { buffer = event.buf, silent = true })
|
||||
end,
|
||||
})
|
||||
|
||||
-- resize neovim split when terminal is resized
|
||||
vim.api.nvim_command('autocmd VimResized * wincmd =')
|
||||
@@ -0,0 +1,39 @@
|
||||
-- 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, {})
|
||||
|
||||
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, {})
|
||||
|
||||
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('core.util').get_root_dir()
|
||||
|
||||
if root == '' then
|
||||
return
|
||||
end
|
||||
vim.cmd('lcd ' .. root)
|
||||
end, {})
|
||||
@@ -0,0 +1,75 @@
|
||||
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 }
|
||||
|
||||
-- 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' })
|
||||
|
||||
-- Select all
|
||||
map('n', '<C-a>', 'gg<S-v>G')
|
||||
|
||||
-- Deleting without yanking empty line
|
||||
map('n', 'dd', function()
|
||||
local is_empty_line = vim.api.nvim_get_current_line():match('^%s*$')
|
||||
if is_empty_line then
|
||||
return '"_dd'
|
||||
else
|
||||
return 'dd'
|
||||
end
|
||||
end, { noremap = true, expr = true, desc = "Don't Yank Empty Line to Clipboard" })
|
||||
|
||||
-- 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')
|
||||
|
||||
map({ 'i' }, '<C-l>', '<Right>', { desc = 'Move cursor to right' })
|
||||
map({ 'i' }, '<C-h>', '<Left>', { desc = 'Move cursor to right' })
|
||||
@@ -0,0 +1,95 @@
|
||||
-- Bootstrap lazy.nvim
|
||||
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
||||
---@diagnostic disable-next-line: undefined-field
|
||||
if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
|
||||
local out = vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath })
|
||||
if vim.v.shell_error ~= 0 then
|
||||
vim.api.nvim_echo({
|
||||
{ 'Failed to clone lazy.nvim:\n', 'ErrorMsg' },
|
||||
{ out, 'WarningMsg' },
|
||||
{ '\nPress any key to exit...' },
|
||||
}, true, {})
|
||||
vim.fn.getchar()
|
||||
os.exit(1)
|
||||
end
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
require('lazy').setup({
|
||||
spec = {
|
||||
{ import = 'plugins' },
|
||||
},
|
||||
install = {
|
||||
missing = true,
|
||||
colorscheme = { 'moonfly' },
|
||||
},
|
||||
checker = {
|
||||
enabled = true,
|
||||
notify = false,
|
||||
},
|
||||
change_detection = {
|
||||
enabled = true,
|
||||
notify = false,
|
||||
},
|
||||
ui = {
|
||||
icons = {
|
||||
cmd = ' ',
|
||||
config = ' ',
|
||||
event = '',
|
||||
ft = ' ',
|
||||
init = ' ',
|
||||
import = ' ',
|
||||
keys = ' ',
|
||||
lazy = ' ',
|
||||
loaded = '●',
|
||||
not_loaded = '○',
|
||||
plugin = ' ',
|
||||
runtime = ' ',
|
||||
require = ' ',
|
||||
source = ' ',
|
||||
start = '',
|
||||
task = '✔ ',
|
||||
list = {
|
||||
'●',
|
||||
'➜',
|
||||
'★',
|
||||
'‒',
|
||||
},
|
||||
},
|
||||
},
|
||||
lockfile = vim.fn.stdpath('config') .. '/lua/lock.json',
|
||||
performance = {
|
||||
rtp = {
|
||||
disabled_plugins = {
|
||||
'2html_plugin',
|
||||
'tohtml',
|
||||
'getscript',
|
||||
'getscriptPlugin',
|
||||
'gzip',
|
||||
'logipat',
|
||||
'netrw',
|
||||
'netrwPlugin',
|
||||
'netrwSettings',
|
||||
'netrwFileHandlers',
|
||||
'matchit',
|
||||
'tar',
|
||||
'tarPlugin',
|
||||
'rrhelper',
|
||||
'spellfile_plugin',
|
||||
'vimball',
|
||||
'vimballPlugin',
|
||||
'zip',
|
||||
'zipPlugin',
|
||||
'tutor',
|
||||
'rplugin',
|
||||
'syntax',
|
||||
'synmenu',
|
||||
'optwin',
|
||||
'compiler',
|
||||
'bugreport',
|
||||
'ftplugin',
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -0,0 +1,59 @@
|
||||
--Remap space as leader key
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
vim.opt.backup = false -- creates a backup file
|
||||
vim.opt.clipboard = 'unnamedplus' -- allows neovim to access the system clipboard
|
||||
vim.opt.cmdheight = 0 -- more space in the neovim command line for displaying messages
|
||||
vim.opt.completeopt = { 'menuone', 'noselect' } -- mostly just for cmp
|
||||
vim.opt.conceallevel = 0 -- so that `` is visible in markdown files
|
||||
-- vim.opt.fileencoding = "utf-8" -- the encoding written to a file
|
||||
vim.opt.hlsearch = true -- highlight all matches on previous search pattern
|
||||
vim.opt.ignorecase = true -- ignore case in search patterns
|
||||
vim.opt.mouse = 'a' -- allow the mouse to be used in neovim
|
||||
vim.opt.pumheight = 10 -- pop up menu height
|
||||
vim.opt.pumblend = 10
|
||||
vim.opt.showmode = false -- we don't need to see things like -- INSERT -- anymore
|
||||
vim.opt.showtabline = 2 -- always show tabs
|
||||
vim.opt.smartcase = true -- smart case
|
||||
vim.opt.smartindent = true -- make indenting smarter again
|
||||
vim.opt.splitbelow = true -- force all horizontal splits to go below current window
|
||||
vim.opt.splitright = true -- force all vertical splits to go to the right of current window
|
||||
vim.opt.swapfile = false -- creates a swapfile
|
||||
vim.opt.termguicolors = true -- set term gui colors (most terminals support this)
|
||||
vim.opt.timeoutlen = 1000 -- time to wait for a mapped sequence to complete (in milliseconds)
|
||||
vim.opt.undofile = true -- enable persistent undo
|
||||
vim.opt.updatetime = 100 -- faster completion (4000ms default)
|
||||
vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited
|
||||
vim.opt.expandtab = true -- convert tabs to spaces
|
||||
vim.opt.shiftwidth = 2 -- the number of spaces inserted for each indentation
|
||||
vim.opt.tabstop = 2 -- insert 2 spaces for a tab
|
||||
vim.opt.cursorline = false -- highlight the current line
|
||||
vim.opt.cursorlineopt = 'number'
|
||||
vim.opt.number = true -- set numbered lines
|
||||
vim.opt.laststatus = 0 --disable native statusline
|
||||
vim.opt.showcmd = false
|
||||
vim.opt.ruler = false
|
||||
vim.opt.relativenumber = true -- set relative numbered lines
|
||||
vim.opt.numberwidth = 4 -- set number column width to 2 {default 4}
|
||||
vim.opt.signcolumn = 'yes' -- always show the sign column, otherwise it would shift the text each time
|
||||
vim.opt.wrap = false -- display lines as one long line
|
||||
vim.opt.scrolloff = 0
|
||||
vim.opt.sidescrolloff = 8
|
||||
vim.opt.guifont = 'monospace:h17' -- the font used in graphical neovim applications
|
||||
vim.opt.title = true
|
||||
vim.opt.titlelen = 0 -- do not shorten title
|
||||
vim.opt.inccommand = 'split' -- split below for to show replaces
|
||||
vim.opt.virtualedit = 'block'
|
||||
vim.opt.fillchars = vim.opt.fillchars + 'eob: '
|
||||
vim.opt.fillchars:append({
|
||||
stl = ' ',
|
||||
})
|
||||
|
||||
vim.opt.shortmess:append('c')
|
||||
|
||||
vim.cmd('set whichwrap+=<,>,[,],h,l')
|
||||
vim.cmd([[set iskeyword+=-]])
|
||||
|
||||
vim.g.netrw_banner = 0
|
||||
vim.g.netrw_mouse = 2
|
||||
@@ -0,0 +1,66 @@
|
||||
local util = {}
|
||||
|
||||
util.get_user_config = function(key, default)
|
||||
local status_ok, user = pcall(require, 'user')
|
||||
if not status_ok then
|
||||
return default
|
||||
end
|
||||
|
||||
local user_config = user[key]
|
||||
if user_config == nil then
|
||||
return default
|
||||
end
|
||||
return user_config
|
||||
end
|
||||
|
||||
util.get_root_dir = function()
|
||||
local bufname = vim.fn.expand('%:p')
|
||||
if vim.fn.filereadable(bufname) == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local parent = vim.fn.fnamemodify(bufname, ':h')
|
||||
local git_root = vim.fn.systemlist('git -C ' .. parent .. ' rev-parse --show-toplevel')
|
||||
if #git_root > 0 and git_root[1] ~= '' then
|
||||
return git_root[1]
|
||||
else
|
||||
return parent
|
||||
end
|
||||
end
|
||||
|
||||
util.get_file_type_cmd = function(extension)
|
||||
local root = util.get_root_dir()
|
||||
|
||||
if extension == 'arb' and root then
|
||||
local gemfile_exists = vim.fn.filereadable(root .. '/Gemfile') == 1
|
||||
local pubspec_exists = vim.fn.filereadable(root .. '/pubspec.yaml') == 1
|
||||
if gemfile_exists then
|
||||
return 'setfiletype ruby'
|
||||
end
|
||||
if pubspec_exists then
|
||||
return 'setfiletype json'
|
||||
end
|
||||
end
|
||||
return ''
|
||||
end
|
||||
|
||||
util.is_present = function(bin)
|
||||
return vim.fn.executable(bin) == 1
|
||||
end
|
||||
|
||||
util.telescope_select = function(options, options_desc, select_prompt)
|
||||
require('telescope.pickers')
|
||||
.new({}, {
|
||||
prompt_title = select_prompt,
|
||||
results_title = options_desc,
|
||||
finder = require('telescope.finders').new_table({
|
||||
results = options,
|
||||
entry_maker = require('telescope.make_entry').gen_from_file(),
|
||||
}),
|
||||
sorter = require('telescope.sorters').get_fzy_sorter(),
|
||||
previewer = require('telescope.previewers').vim_buffer_cat.new({}),
|
||||
})
|
||||
:find()
|
||||
end
|
||||
|
||||
return util
|
||||
Reference in new issue
Block a user