diff --git a/config/nvim/after/ftplugin/help.lua b/config/nvim/after/ftplugin/help.lua index b091af0..c895f25 100644 --- a/config/nvim/after/ftplugin/help.lua +++ b/config/nvim/after/ftplugin/help.lua @@ -2,4 +2,4 @@ vim.o.number = true vim.o.conceallevel = 0 vim.o.relativenumber = true -bmap({ 'n', 'q', vim.cmd.helpclose }) +vim.keymap.set('n', 'q', vim.cmd.helpclose, { buffer = 0 }) diff --git a/config/nvim/init.lua b/config/nvim/init.lua index faca17b..9102e8c 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -1,16 +1,13 @@ vim.g.mapleader = ' ' -function _G.map(mapping, opts) - vim.keymap.set( - mapping[1], - mapping[2], - mapping[3], - vim.tbl_extend('keep', opts or {}, { silent = true }) - ) -end +vim.g.lz_n = { + load = function(name) + vim.cmd('packadd! ' .. name) + end, +} -function _G.bmap(mapping, opts) - _G.map(mapping, vim.tbl_extend('force', opts or {}, { buffer = 0 })) -end +vim.pack.add({ + 'https://github.com/lumen-oss/lz.n', +}) -require('config.pack') +require('lz.n').load('plugins') diff --git a/config/nvim/lua/config/lsp.lua b/config/nvim/lua/config/lsp.lua index 67203de..9e7ed84 100644 --- a/config/nvim/lua/config/lsp.lua +++ b/config/nvim/lua/config/lsp.lua @@ -4,7 +4,7 @@ local Methods = vim.lsp.protocol.Methods function M.on_attach(client, bufnr) if client:supports_method(Methods.textDocument_hover) then - bmap({ 'n', 'K', vim.lsp.buf.hover }) + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { buffer = 0 }) end local ok, _ = pcall(require, 'fzf-lua') @@ -67,7 +67,7 @@ function M.on_attach(client, bufnr) for _, m in ipairs(mappings) do local method, key, cmd = unpack(m) if client:supports_method(method) then - bmap({ 'n', key, cmd }) + vim.keymap.set('n', key, cmd, { buffer = 0 }) end end end diff --git a/config/nvim/lua/config/pack.lua b/config/nvim/lua/config/pack.lua deleted file mode 100644 index 3affd2b..0000000 --- a/config/nvim/lua/config/pack.lua +++ /dev/null @@ -1,47 +0,0 @@ -vim.g.loaded_2html_plugin = true -vim.g.loaded_bugreport = true -vim.g.loaded_getscript = true -vim.g.loaded_getscriptPlugin = true -vim.g.loaded_gzip = true -vim.g.loaded_logipat = true -vim.g.loaded_netrw = true -vim.g.loaded_netrwFileHandlers = true -vim.g.loaded_netrwPlugin = true -vim.g.loaded_netrwSettings = true -vim.g.loaded_optwin = true -vim.g.loaded_rplugin = true -vim.g.loaded_rrhelper = true -vim.g.loaded_synmenu = true -vim.g.loaded_tar = true -vim.g.loaded_tarPlugin = true -vim.g.loaded_tohtml = true -vim.g.loaded_tutor = true -vim.g.loaded_vimball = true -vim.g.loaded_vimballPlugin = true -vim.g.loaded_zip = true -vim.g.loaded_zipPlugin = true - -local dev_plugins = { - ['diffs.nvim'] = '~/dev/diffs.nvim', - ['canola.nvim'] = '~/dev/canola.nvim', - ['pending.nvim'] = '~/dev/pending.nvim', -} - -for _, path in pairs(dev_plugins) do - vim.opt.rtp:prepend(path) -end - -vim.g.lz_n = { - load = function(name) - name = name:match('[^/]+$') or name - if not dev_plugins[name] then - vim.cmd.packadd(name) - end - end, -} - -vim.pack.add({ - 'https://github.com/lumen-oss/lz.n', -}) - -require('lz.n').load('plugins') diff --git a/config/nvim/lua/lsp/clangd.lua b/config/nvim/lua/lsp/clangd.lua index 59ee69b..fe59776 100644 --- a/config/nvim/lua/lsp/clangd.lua +++ b/config/nvim/lua/lsp/clangd.lua @@ -2,8 +2,10 @@ vim.api.nvim_create_autocmd('LspAttach', { callback = function(args) local client = vim.lsp.get_client_by_id(args.data.client_id) if client and client.name == 'clangd' then - bmap( - { 'n', 'gh', vim.cmd.ClangdSwitchSourceHeader }, + vim.keymap.set( + 'n', + 'gh', + vim.cmd.ClangdSwitchSourceHeader, { buffer = args.buf } ) end diff --git a/config/nvim/lua/lsp/rust-analyzer.lua b/config/nvim/lua/lsp/rust-analyzer.lua index 729f3a2..8756511 100644 --- a/config/nvim/lua/lsp/rust-analyzer.lua +++ b/config/nvim/lua/lsp/rust-analyzer.lua @@ -21,8 +21,23 @@ return { }, on_attach = function(...) require('config.lsp').on_attach(...) - bmap({ 'n', '\\Rc', 'RustLsp codeAction' }) - bmap({ 'n', '\\Rm', 'RustLsp expandMacro' }) - bmap({ 'n', '\\Ro', 'RustLsp openCargo' }) + vim.keymap.set( + 'n', + '\\Rc', + 'RustLsp codeAction', + { buffer = 0 } + ) + vim.keymap.set( + 'n', + '\\Rm', + 'RustLsp expandMacro', + { buffer = 0 } + ) + vim.keymap.set( + 'n', + '\\Ro', + 'RustLsp openCargo', + { buffer = 0 } + ) end, } diff --git a/config/nvim/lua/plugins/cp.lua b/config/nvim/lua/plugins/cp.lua deleted file mode 100644 index cb59d79..0000000 --- a/config/nvim/lua/plugins/cp.lua +++ /dev/null @@ -1,253 +0,0 @@ -local clang_format = [[BasedOnStyle: LLVM -IndentWidth: 2 -UseTab: Never - -AllowShortIfStatementsOnASingleLine: Never -AllowShortLoopsOnASingleLine: false -AllowShortFunctionsOnASingleLine: None -AllowShortLambdasOnASingleLine: None -AllowShortBlocksOnASingleLine: Never -AllowShortEnumsOnASingleLine: false -AllowShortCaseExpressionOnASingleLine: false - -BreakBeforeBraces: Attach -ColumnLimit: 100 -AlignAfterOpenBracket: Align -BinPackArguments: false -BinPackParameters: false]] - -local cpp_base = [[#include // {{{ - -#include -#ifdef __cpp_lib_ranges_enumerate -#include -namespace rv = std::views; -namespace rs = std::ranges; -#endif - -#pragma GCC optimize("O2,unroll-loops") -#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") - -using namespace std; - -using i32 = int32_t; -using u32 = uint32_t; -using i64 = int64_t; -using u64 = uint64_t; -using f64 = double; -using f128 = long double; - -#if __cplusplus >= 202002L -template -constexpr T MIN = std::numeric_limits::min(); - -template -constexpr T MAX = std::numeric_limits::max(); -#endif - -#ifdef LOCAL -#define db(...) std::print(__VA_ARGS__) -#define dbln(...) std::println(__VA_ARGS__) -#else -#define db(...) -#define dbln(...) -#endif -// }}} - -void solve() { - <++> -} - -int main() { // {{{ - std::cin.exceptions(std::cin.failbit); -#ifdef LOCAL - std::cerr.rdbuf(std::cout.rdbuf()); - std::cout.setf(std::ios::unitbuf); - std::cerr.setf(std::ios::unitbuf); -#else - std::cin.tie(nullptr)->sync_with_stdio(false); -#endif -]] - -local cpp_single = cpp_base .. [[ solve(); - return 0; -} // }}}]] - -local cpp_multi = cpp_base - .. [[ u32 tc = 1; - std::cin >> tc; - for (u32 t = 0; t < tc; ++t) { - solve(); - } - return 0; -} // }}}]] - -local templates = { - cpp = { - default = cpp_multi, - codeforces = cpp_multi, - atcoder = cpp_single, - cses = cpp_single, - }, - python = { - default = [[def main() -> None: - <++> - - -if __name__ == '__main__': - main()]], - }, -} - -local function insert_template(buf, lang, platform) - local lang_templates = templates[lang] - if not lang_templates then - return false - end - - local template = lang_templates[platform] or lang_templates.default - if not template then - return false - end - - local lines = vim.split(template, '\n') - vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) - - for lnum, line in ipairs(lines) do - local col = line:find('<++>', 1, true) - if col then - local new_line = line:sub(1, col - 1) .. line:sub(col + 4) - vim.api.nvim_buf_set_lines(buf, lnum - 1, lnum, false, { new_line }) - vim.api.nvim_win_set_cursor(0, { lnum, col - 1 }) - break - end - end - - return true -end - -vim.pack.add({ 'https://github.com/barrettruth/cp.nvim' }) - -return { - 'barrettruth/cp.nvim', - cmd = 'CP', - keys = { - { 'ce', 'CP edit' }, - { 'cp', 'CP panel' }, - { 'cP', 'CP pick' }, - { 'cr', 'CP run all' }, - { 'cd', 'CP run --debug' }, - { ']c', 'CP next' }, - { '[c', 'CP prev' }, - }, - before = function() - vim.g.cp = { - debug = false, - languages = { - cpp = { - extension = 'cc', - commands = { - build = { - 'g++', - '-std=c++23', - '-O2', - '-Wall', - '-Wextra', - '-Wpedantic', - '-Wshadow', - '-Wconversion', - '-Wformat=2', - '-Wfloat-equal', - '-Wundef', - '-fdiagnostics-color=always', - '-DLOCAL', - '{source}', - '-o', - '{binary}', - }, - run = { '{binary}' }, - debug = { - 'g++', - '-std=c++23', - '-g3', - '-fsanitize=address,undefined', - '-fno-omit-frame-pointer', - '-fstack-protector-all', - '-D_GLIBCXX_DEBUG', - '-DLOCAL', - '{source}', - '-o', - '{binary}', - }, - }, - }, - python = { - extension = 'py', - commands = { - run = { 'python', '{source}' }, - debug = { 'python', '{source}' }, - }, - }, - }, - platforms = { - codeforces = { - enabled_languages = { 'cpp', 'python' }, - default_language = 'cpp', - }, - atcoder = { - enabled_languages = { 'cpp', 'python' }, - default_language = 'cpp', - }, - cses = {}, - }, - ui = { - picker = 'fzf-lua', - panel = { diff_modes = { 'side-by-side', 'git' } }, - }, - hooks = { - setup_io_input = function(buf) - require('cp.helpers').clearcol(buf) - end, - setup_io_output = function(buf) - require('cp.helpers').clearcol(buf) - end, - before_run = function(_) - require('config.lsp').format() - end, - before_debug = function(_) - require('config.lsp').format() - end, - setup_code = function(state) - vim.opt_local.winbar = '' - vim.opt_local.foldlevel = 0 - vim.opt_local.foldmethod = 'marker' - vim.opt_local.foldmarker = '{{{,}}}' - vim.opt_local.foldtext = '' - vim.diagnostic.enable(false) - - local buf = vim.api.nvim_get_current_buf() - local lines = vim.api.nvim_buf_get_lines(buf, 0, 1, true) - if #lines > 1 or (#lines == 1 and lines[1] ~= '') then - return - end - - local lang = state.get_language() - local platform = state.get_platform() - insert_template(buf, lang, platform) - - local clang_format_path = vim.fn.getcwd() - .. '/.clang-format' - if vim.fn.filereadable(clang_format_path) == 0 then - vim.fn.writefile( - vim.split(clang_format, '\n'), - clang_format_path - ) - end - end, - }, - filename = function(_, _, problem_id) - return problem_id - end, - } - end, -} diff --git a/config/nvim/lua/plugins/dev.lua b/config/nvim/lua/plugins/dev.lua new file mode 100644 index 0000000..b3d6f67 --- /dev/null +++ b/config/nvim/lua/plugins/dev.lua @@ -0,0 +1,405 @@ +local dev_plugins = { + ['diffs.nvim'] = '~/dev/diffs.nvim', + ['canola.nvim'] = '~/dev/canola.nvim', + ['pending.nvim'] = '~/dev/pending.nvim', +} + +for _, path in pairs(dev_plugins) do + vim.opt.rtp:prepend(path) +end + +local function parse_output(proc) + local result = proc:wait() + local ret = {} + if result.code == 0 then + for line in + vim.gsplit(result.stdout, '\n', { plain = true, trimempty = true }) + do + ret[line:gsub('/$', '')] = true + end + end + return ret +end + +local function new_git_status() + return setmetatable({}, { + __index = function(self, key) + local ignored_proc = vim.system({ + 'git', + 'ls-files', + '--ignored', + '--exclude-standard', + '--others', + '--directory', + }, { cwd = key, text = true }) + local tracked_proc = vim.system( + { 'git', 'ls-tree', 'HEAD', '--name-only' }, + { cwd = key, text = true } + ) + local ret = { + ignored = parse_output(ignored_proc), + tracked = parse_output(tracked_proc), + } + rawset(self, key, ret) + return ret + end, + }) +end + +local git_status = new_git_status() + +local clang_format = [[BasedOnStyle: LLVM +IndentWidth: 2 +UseTab: Never + +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false +AllowShortFunctionsOnASingleLine: None +AllowShortLambdasOnASingleLine: None +AllowShortBlocksOnASingleLine: Never +AllowShortEnumsOnASingleLine: false +AllowShortCaseExpressionOnASingleLine: false + +BreakBeforeBraces: Attach +ColumnLimit: 100 +AlignAfterOpenBracket: Align +BinPackArguments: false +BinPackParameters: false]] + +local cpp_base = [[#include // {{{ + +#include +#ifdef __cpp_lib_ranges_enumerate +#include +namespace rv = std::views; +namespace rs = std::ranges; +#endif + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using f64 = double; +using f128 = long double; + +#if __cplusplus >= 202002L +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); +#endif + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + <++> +} + +int main() { // {{{ + std::cin.exceptions(std::cin.failbit); +#ifdef LOCAL + std::cerr.rdbuf(std::cout.rdbuf()); + std::cout.setf(std::ios::unitbuf); + std::cerr.setf(std::ios::unitbuf); +#else + std::cin.tie(nullptr)->sync_with_stdio(false); +#endif +]] + +local cpp_single = cpp_base .. [[ solve(); + return 0; +} // }}}]] + +local cpp_multi = cpp_base + .. [[ u32 tc = 1; + std::cin >> tc; + for (u32 t = 0; t < tc; ++t) { + solve(); + } + return 0; +} // }}}]] + +local templates = { + cpp = { + default = cpp_multi, + codeforces = cpp_multi, + atcoder = cpp_single, + cses = cpp_single, + }, + python = { + default = [[def main() -> None: + <++> + + +if __name__ == '__main__': + main()]], + }, +} + +local function insert_template(buf, lang, platform) + local lang_templates = templates[lang] + if not lang_templates then + return false + end + + local template = lang_templates[platform] or lang_templates.default + if not template then + return false + end + + local lines = vim.split(template, '\n') + vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) + + for lnum, line in ipairs(lines) do + local col = line:find('<++>', 1, true) + if col then + local new_line = line:sub(1, col - 1) .. line:sub(col + 4) + vim.api.nvim_buf_set_lines(buf, lnum - 1, lnum, false, { new_line }) + vim.api.nvim_win_set_cursor(0, { lnum, col - 1 }) + break + end + end + + return true +end + +vim.pack.add({ + 'https://github.com/barrettruth/cp.nvim', + 'https://github.com/nvim-tree/nvim-web-devicons', +}) + +return { + { + 'barrettruth/midnight.nvim', + enabled = false, + after = function() + vim.cmd.colorscheme('midnight') + end, + }, + { + 'barrettruth/live-server.nvim', + enabled = false, + before = function() + vim.g.live_server = { + debug = false, + } + end, + keys = { { 'l', 'LiveServerToggle' } }, + }, + { + 'barrettruth/nonicons.nvim', + enabled = false, + }, + { + 'barrettruth/canola.nvim', + enabled = true, + after = function() + require('oil').setup({ + skip_confirm_for_simple_edits = true, + prompt_save_on_select_new_entry = false, + float = { border = 'single' }, + view_options = { + is_hidden_file = function(name, bufnr) + local dir = require('oil').get_current_dir(bufnr) + local is_dotfile = vim.startswith(name, '.') + and name ~= '..' + if not dir then + return is_dotfile + end + if is_dotfile then + return not git_status[dir].tracked[name] + else + return git_status[dir].ignored[name] + end + end, + }, + keymaps = { + [''] = false, + [''] = false, + [''] = false, + [''] = 'actions.refresh', + [''] = { 'actions.select', opts = { vertical = true } }, + [''] = { + 'actions.select', + opts = { horizontal = true }, + }, + q = function() + local ok, bufremove = pcall(require, 'mini.bufremove') + if ok then + bufremove.delete() + else + vim.cmd.bd() + end + end, + }, + }) + local refresh = require('oil.actions').refresh + local orig_refresh = refresh.callback + refresh.callback = function(...) + git_status = new_git_status() + orig_refresh(...) + end + vim.api.nvim_create_autocmd('BufEnter', { + callback = function() + local ft = vim.bo.filetype + if ft == '' then + local path = vim.fn.expand('%:p') + if vim.fn.isdirectory(path) == 1 then + vim.cmd('Oil ' .. path) + end + end + end, + group = vim.api.nvim_create_augroup('AOil', { clear = true }), + }) + end, + event = 'DeferredUIEnter', + keys = { + { '-', 'e .' }, + { '_', 'Oil' }, + }, + }, + { + 'barrettruth/pending.nvim', + before = function() + vim.g.pending = { debug = true } + end, + keys = { { 'p', 'Pending' } }, + }, + { + 'barrettruth/cp.nvim', + cmd = 'CP', + keys = { + { 'ce', 'CP edit' }, + { 'cp', 'CP panel' }, + { 'cP', 'CP pick' }, + { 'cr', 'CP run all' }, + { 'cd', 'CP run --debug' }, + { ']c', 'CP next' }, + { '[c', 'CP prev' }, + }, + before = function() + vim.g.cp = { + debug = false, + languages = { + cpp = { + extension = 'cc', + commands = { + build = { + 'g++', + '-std=c++23', + '-O2', + '-Wall', + '-Wextra', + '-Wpedantic', + '-Wshadow', + '-Wconversion', + '-Wformat=2', + '-Wfloat-equal', + '-Wundef', + '-fdiagnostics-color=always', + '-DLOCAL', + '{source}', + '-o', + '{binary}', + }, + run = { '{binary}' }, + debug = { + 'g++', + '-std=c++23', + '-g3', + '-fsanitize=address,undefined', + '-fno-omit-frame-pointer', + '-fstack-protector-all', + '-D_GLIBCXX_DEBUG', + '-DLOCAL', + '{source}', + '-o', + '{binary}', + }, + }, + }, + python = { + extension = 'py', + commands = { + run = { 'python', '{source}' }, + debug = { 'python', '{source}' }, + }, + }, + }, + platforms = { + codeforces = { + enabled_languages = { 'cpp', 'python' }, + default_language = 'cpp', + }, + atcoder = { + enabled_languages = { 'cpp', 'python' }, + default_language = 'cpp', + }, + cses = {}, + }, + ui = { + picker = 'fzf-lua', + panel = { diff_modes = { 'side-by-side', 'git' } }, + }, + hooks = { + setup_io_input = function(buf) + require('cp.helpers').clearcol(buf) + end, + setup_io_output = function(buf) + require('cp.helpers').clearcol(buf) + end, + before_run = function(_) + require('config.lsp').format() + end, + before_debug = function(_) + require('config.lsp').format() + end, + setup_code = function(state) + vim.opt_local.winbar = '' + vim.opt_local.foldlevel = 0 + vim.opt_local.foldmethod = 'marker' + vim.opt_local.foldmarker = '{{{,}}}' + vim.opt_local.foldtext = '' + vim.diagnostic.enable(false) + + local buf = vim.api.nvim_get_current_buf() + local lines = + vim.api.nvim_buf_get_lines(buf, 0, 1, true) + if #lines > 1 or (#lines == 1 and lines[1] ~= '') then + return + end + + local lang = state.get_language() + local platform = state.get_platform() + insert_template(buf, lang, platform) + + local clang_format_path = vim.fn.getcwd() + .. '/.clang-format' + if vim.fn.filereadable(clang_format_path) == 0 then + vim.fn.writefile( + vim.split(clang_format, '\n'), + clang_format_path + ) + end + end, + }, + filename = function(_, _, problem_id) + return problem_id + end, + } + end, + }, +} diff --git a/config/nvim/lua/plugins/fzf.lua b/config/nvim/lua/plugins/fzf.lua index 71121b5..3e33872 100644 --- a/config/nvim/lua/plugins/fzf.lua +++ b/config/nvim/lua/plugins/fzf.lua @@ -129,7 +129,7 @@ return { { 'f/', 'FzfLua search_history' }, { 'f:', 'FzfLua command_history' }, { 'fa', 'FzfLua autocmds' }, - { 'fB', 'FzfLua buffers' }, + { 'fb', 'FzfLua buffers' }, { 'fc', 'FzfLua commands' }, { 'fe', diff --git a/config/nvim/lua/plugins/git.lua b/config/nvim/lua/plugins/git.lua index 4ff43e6..a23823d 100644 --- a/config/nvim/lua/plugins/git.lua +++ b/config/nvim/lua/plugins/git.lua @@ -159,67 +159,52 @@ local function with_forge(fn) end end -map({ +vim.keymap.set( { 'n', 'v' }, 'go', with_forge(function(forge) local branch = vim.trim(vim.fn.system('git branch --show-current')) forge.browse(file_loc(), branch) - end), -}) -map({ + end) +) +vim.keymap.set( { 'n', 'v' }, 'gy', with_forge(function(forge) forge.yank_commit(file_loc()) - end), -}) -map({ + end) +) +vim.keymap.set( { 'n', 'v' }, 'gl', with_forge(function(forge) forge.yank_branch(file_loc()) - end), -}) -map({ + end) +) +vim.keymap.set( 'n', 'gx', with_forge(function(forge) forge.browse_root() - end), -}) -map({ - 'n', - 'gd', - function() - pcall(vim.cmd.packadd, 'fzf-lua') - require('fzf-lua').fzf_exec( - 'git branch -a --format="%(refname:short)"', - { - prompt = 'Git diff> ', - actions = { - ['default'] = function(selected) - vim.cmd('Git diff ' .. selected[1]) - end, - }, - } - ) - end, -}) -map({ - 'n', - 'gi', - function() - forge_picker('issue', 'all') - end, -}) -map({ - 'n', - 'gp', - function() - forge_picker('pr', 'all') - end, -}) + end) +) +vim.keymap.set('n', 'gd', function() + pcall(vim.cmd.packadd, 'fzf-lua') + require('fzf-lua').fzf_exec('git branch -a --format="%(refname:short)"', { + prompt = 'Git diff> ', + actions = { + ['default'] = function(selected) + vim.cmd('Git diff ' .. selected[1]) + end, + }, + }) +end) +vim.keymap.set('n', 'gi', function() + forge_picker('issue', 'all') +end) +vim.keymap.set('n', 'gp', function() + forge_picker('pr', 'all') +end) return { { diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 3bd53c0..c521182 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -32,8 +32,10 @@ return { local clients = vim.lsp.get_clients({ buffer = o.buf }) for _, client in ipairs(clients) do if client:supports_method('textDocument/rename') then - bmap( - { 'n', 'grn', live_rename.rename }, + vim.keymap.set( + 'n', + 'grn', + live_rename.rename, { buffer = o.buf } ) end @@ -53,8 +55,10 @@ return { after = function() require('vtsls').config({ on_attach = function(_, bufnr) - bmap( - { 'n', 'gD', vim.cmd.VtsExec('goto_source_definition') }, + vim.keymap.set( + 'n', + 'gD', + vim.cmd.VtsExec('goto_source_definition'), { buffer = bufnr } ) end, diff --git a/config/nvim/lua/plugins/nvim.lua b/config/nvim/lua/plugins/nvim.lua index b58d3ad..ac6b4d0 100644 --- a/config/nvim/lua/plugins/nvim.lua +++ b/config/nvim/lua/plugins/nvim.lua @@ -1,43 +1,3 @@ -local function parse_output(proc) - local result = proc:wait() - local ret = {} - if result.code == 0 then - for line in - vim.gsplit(result.stdout, '\n', { plain = true, trimempty = true }) - do - ret[line:gsub('/$', '')] = true - end - end - return ret -end - -local function new_git_status() - return setmetatable({}, { - __index = function(self, key) - local ignored_proc = vim.system({ - 'git', - 'ls-files', - '--ignored', - '--exclude-standard', - '--others', - '--directory', - }, { cwd = key, text = true }) - local tracked_proc = vim.system( - { 'git', 'ls-tree', 'HEAD', '--name-only' }, - { cwd = key, text = true } - ) - local ret = { - ignored = parse_output(ignored_proc), - tracked = parse_output(tracked_proc), - } - rawset(self, key, ret) - return ret - end, - }) -end - -local git_status = new_git_status() - vim.pack.add({ 'https://github.com/echasnovski/mini.ai', 'https://github.com/monaqa/dial.nvim', @@ -52,20 +12,6 @@ vim.pack.add({ }) return { - { - 'barrettruth/live-server.nvim', - enabled = false, - before = function() - vim.g.live_server = { - debug = false, - } - end, - keys = { { 'l', 'LiveServerToggle' } }, - }, - { - 'barrettruth/nonicons.nvim', - enabled = false, - }, { 'echasnovski/mini.pairs', after = function() @@ -286,74 +232,6 @@ return { end, event = 'BufReadPre', }, - { - 'barrettruth/canola.nvim', - enabled = true, - after = function() - require('oil').setup({ - skip_confirm_for_simple_edits = true, - prompt_save_on_select_new_entry = false, - float = { border = 'single' }, - view_options = { - is_hidden_file = function(name, bufnr) - local dir = require('oil').get_current_dir(bufnr) - local is_dotfile = vim.startswith(name, '.') - and name ~= '..' - if not dir then - return is_dotfile - end - if is_dotfile then - return not git_status[dir].tracked[name] - else - return git_status[dir].ignored[name] - end - end, - }, - keymaps = { - [''] = false, - [''] = false, - [''] = false, - [''] = 'actions.refresh', - [''] = { 'actions.select', opts = { vertical = true } }, - [''] = { - 'actions.select', - opts = { horizontal = true }, - }, - q = function() - local ok, bufremove = pcall(require, 'mini.bufremove') - if ok then - bufremove.delete() - else - vim.cmd.bd() - end - end, - }, - }) - local refresh = require('oil.actions').refresh - local orig_refresh = refresh.callback - refresh.callback = function(...) - git_status = new_git_status() - orig_refresh(...) - end - vim.api.nvim_create_autocmd('BufEnter', { - callback = function() - local ft = vim.bo.filetype - if ft == '' then - local path = vim.fn.expand('%:p') - if vim.fn.isdirectory(path) == 1 then - vim.cmd('Oil ' .. path) - end - end - end, - group = vim.api.nvim_create_augroup('AOil', { clear = true }), - }) - end, - event = 'DeferredUIEnter', - keys = { - { '-', 'e .' }, - { '_', 'Oil' }, - }, - }, { 'echasnovski/mini.misc', after = function() @@ -398,12 +276,4 @@ return { { 'ySs', mode = 'n' }, }, }, - { - 'barrettruth/pending.nvim', - before = function() - vim.g.pending = { debug = true } - end, - -- TODO: should we be using this or `` mappings? - keys = { { 'p', 'Pending' } }, - }, } diff --git a/config/nvim/lua/plugins/treesitter.lua b/config/nvim/lua/plugins/treesitter.lua index a379231..fd1166c 100644 --- a/config/nvim/lua/plugins/treesitter.lua +++ b/config/nvim/lua/plugins/treesitter.lua @@ -59,13 +59,9 @@ return { } for _, m in ipairs({ 'x', 'o' }) do for _, t in ipairs(select_maps) do - map({ - m, - t[1], - function() - select.select_textobject(t[2], 'textobjects', m) - end, - }) + vim.keymap.set(m, t[1], function() + select.select_textobject(t[2], 'textobjects', m) + end) end end @@ -80,36 +76,20 @@ return { for _, m in ipairs({ 'n', 'x', 'o' }) do for _, t in ipairs(move_textobjects) do local key, capture = t[1], t[2] - map({ - m, - ']' .. key, - function() - move.goto_next_start(capture, 'textobjects') - end, - }) - map({ - m, - '[' .. key, - function() - move.goto_previous_start(capture, 'textobjects') - end, - }) + vim.keymap.set(m, ']' .. key, function() + move.goto_next_start(capture, 'textobjects') + end) + vim.keymap.set(m, '[' .. key, function() + move.goto_previous_start(capture, 'textobjects') + end) local upper = key:upper() if upper ~= key then - map({ - m, - ']' .. upper, - function() - move.goto_next_end(capture, 'textobjects') - end, - }) - map({ - m, - '[' .. upper, - function() - move.goto_previous_end(capture, 'textobjects') - end, - }) + vim.keymap.set(m, ']' .. upper, function() + move.goto_next_end(capture, 'textobjects') + end) + vim.keymap.set(m, '[' .. upper, function() + move.goto_previous_end(capture, 'textobjects') + end) end end end @@ -117,12 +97,32 @@ return { local ts_repeat = require('nvim-treesitter-textobjects.repeatable_move') for _, m in ipairs({ 'n', 'x', 'o' }) do - map({ m, ';', ts_repeat.repeat_last_move_next }) - map({ m, ',', ts_repeat.repeat_last_move_previous }) - map({ m, 'f', ts_repeat.builtin_f_expr }, { expr = true }) - map({ m, 'F', ts_repeat.builtin_F_expr }, { expr = true }) - map({ m, 't', ts_repeat.builtin_t_expr }, { expr = true }) - map({ m, 'T', ts_repeat.builtin_T_expr }, { expr = true }) + vim.keymap.set(m, ';', ts_repeat.repeat_last_move_next) + vim.keymap.set(m, ',', ts_repeat.repeat_last_move_previous) + vim.keymap.set( + m, + 'f', + ts_repeat.builtin_f_expr, + { expr = true } + ) + vim.keymap.set( + m, + 'F', + ts_repeat.builtin_F_expr, + { expr = true } + ) + vim.keymap.set( + m, + 't', + ts_repeat.builtin_t_expr, + { expr = true } + ) + vim.keymap.set( + m, + 'T', + ts_repeat.builtin_T_expr, + { expr = true } + ) end end, }, diff --git a/config/nvim/plugin/autocmds.lua b/config/nvim/plugin/autocmds.lua index a4e22a8..d268b52 100644 --- a/config/nvim/plugin/autocmds.lua +++ b/config/nvim/plugin/autocmds.lua @@ -20,7 +20,6 @@ vim.api.nvim_create_autocmd('BufReadPost', { command = 'sil! normal g`"', group = aug, }) - vim.api.nvim_create_autocmd('TextYankPost', { callback = function() vim.highlight.on_yank({ higroup = 'Visual', timeout = 300 }) diff --git a/config/nvim/plugin/keymaps.lua b/config/nvim/plugin/keymaps.lua index c73b956..87bb479 100644 --- a/config/nvim/plugin/keymaps.lua +++ b/config/nvim/plugin/keymaps.lua @@ -1,10 +1,10 @@ -map({ 'n', '', 'vertical resize -10' }) -map({ 'n', '', 'vertical resize +10' }) -map({ 'n', '', 'resize +10' }) -map({ 'n', '', 'resize -10' }) +vim.keymap.set('n', '', 'vertical resize -10') +vim.keymap.set('n', '', 'vertical resize +10') +vim.keymap.set('n', '', 'resize +10') +vim.keymap.set('n', '', 'resize -10') -map({ 'n', 'J', 'mzJ`z' }) +vim.keymap.set('n', 'J', 'mzJ`z') -map({ 'x', 'p', '"_dp' }) -map({ 'x', 'P', '"_dP' }) -map({ 't', '', '' }) +vim.keymap.set('x', 'p', '"_dp') +vim.keymap.set('x', 'P', '"_dP') +vim.keymap.set('t', '', '') diff --git a/config/nvim/plugin/options.lua b/config/nvim/plugin/options.lua index d241082..1e77ce6 100644 --- a/config/nvim/plugin/options.lua +++ b/config/nvim/plugin/options.lua @@ -14,9 +14,8 @@ o.expandtab = true o.exrc = true o.secure = true -o.foldcolumn = '1' o.foldexpr = 'v:lua.vim.treesitter.foldexpr()' -o.foldlevel = 1 +o.foldlevel = 99 o.foldmethod = 'expr' o.foldtext = '' @@ -24,6 +23,10 @@ opt.fillchars = { eob = ' ', vert = '│', diff = '╱', + foldopen = 'v', + foldclose = '>', + foldsep = ' ', + foldinner = ' ', } opt.iskeyword:append('-') @@ -42,6 +45,8 @@ opt.matchpairs:append('<:>') o.number = true o.relativenumber = true +o.signcolumn = 'no' +o.statuscolumn = '%s%C %=%{v:relnum?v:relnum:v:lnum} ' opt.path:append('**')