From c489d393695e90d424f9ae51e35c4d42358e6a71 Mon Sep 17 00:00:00 2001 From: Squibid Date: Fri, 9 Aug 2024 02:45:31 -0400 Subject: yes there's a bit of java in my nvim config why do you ask? --- lua/conf/binds.lua | 165 +++++++---------------------------------------------- 1 file changed, 20 insertions(+), 145 deletions(-) (limited to 'lua/conf/binds.lua') diff --git a/lua/conf/binds.lua b/lua/conf/binds.lua index 42c609e..2031852 100644 --- a/lua/conf/binds.lua +++ b/lua/conf/binds.lua @@ -1,25 +1,11 @@ -local conf = require('core.conf') +local misc = require('core.misc') +local map, auto = misc.map, misc.auto -local function map(mode, bind, cmd, opts) - opts = opts or {} - opts['noremap'] = true - opts['silent'] = true - - if type(bind) == 'table' then - for i in pairs(bind) do - vim.keymap.set(mode, bind[i], cmd, opts) - end - elseif type(bind) == 'string' then - vim.keymap.set(mode, bind, cmd, opts) - end -end - --- vim binds ------------------------------------------------------------------ -g.mapleader = ' ' -- set leader key +-- vim binds +vim.g.mapleader = ' ' -- set leader key map('x', 'p', [["_dP]], { desc = 'Greatest remap of all time.' }) map('n', '', ':nohlsearch:echo', { desc = 'Clear search.' }) -map('t', '', '', { desc = 'make work in terminals.' }) -- move selected text up/down map('v', '', ":m '<-2gv=gv", { desc = 'Move selected text up.' }) map('v', '', ":m '>+1gv=gv", { desc = 'Move selected text down.' }) @@ -45,22 +31,7 @@ map('n', 'x', function() -- execute order 111 else vim.notify("File doesn't exist", vim.log.levels.INFO, { title = misc.appid }) end -end) - --- add some keybinds to the file view (netrw) -a.nvim_create_autocmd('FileType', { - pattern = 'netrw', - callback = function() - local function bind(lhs, rhs) - vim.keymap.set('n', lhs, rhs, { remap = true, buffer = true }) - end - bind('h', '-^') -- Go up a directory - bind('l', '') -- Go down a directory / open a file - bind('.', 'gh') -- Toggle hidden files - bind('P', 'z') -- Close preview window - bind('', 'q') -- Close netrw - end -}) +end, { desc = 'toggle executable flag of the file' }) -- tabs map('n', '[]', 'tabnew') @@ -68,118 +39,22 @@ map('n', '][', 'tabc') map('n', '[[', 'tabp') map('n', ']]', 'tabn') --- config binds --------------------------------------------------------------- -map('n', 'm', conf.configmenu, { desc = 'Neovim config manager menu', }) - --- plugin binds --------------------------------------------------------------- - --- pretty lsp view -map('n', 'gd', 'Glance definitions') -map('n', 'gr', 'Glance references') -map('n', 'gy', 'Glance type_definitions') -map('n', 'gi', 'Glance implementations') - -if pcall(require, "treesj") then - local treesj = require('treesj') -- treesj - map('n', 'j', treesj.toggle) -end - -if pcall(require, "telescope") then - local telebuilt = require('telescope.builtin') -- telescope - -- local telexten = require('telescope').extensions - map('n', 'sf', telebuilt.find_files, { desc = 'Find files.' }) - map('n', 'so', telebuilt.oldfiles, { desc = 'Find old files.' }) - map('n', 'sg', telebuilt.git_files, { desc = 'Find git files.' }) - -- search urls in buffer - map('n', 'su', 'UrlView', { desc = 'Find urls in buffer.' }) - -- search lsp symbols - map('n', 'ss', telebuilt.lsp_document_symbols, - { desc = 'Find LSP Symbols.' }) - -- search for keybinds - map('n', 'sk', telebuilt.keymaps, - { desc = 'Find nvim Keymaps.' }) - -- search for highlights - map('n', 'sh', telebuilt.highlights, - { desc = 'Find nvim Highlights.' }) - -- search for autocommands - map('n', 'sa', telebuilt.autocommands, - { desc = 'Find nvim Autocommands.' }) - -- search for vim options - map('n', 'sv', telebuilt.vim_options, { desc = 'Find vim options.' }) - -- search for string in project - map('n', 'sp', telebuilt.live_grep, { desc = 'Find string in project.' }) - - -- Code Actions (requires telescope) - if pcall(require, "actions-preview") then - map({ "n", "v" }, "ca", require("actions-preview").code_actions, { - desc = 'preview code actions' - }) +-- good spell suggestion ui +-- (stolen from https://github.com/neovim/neovim/pull/25833) +local spell_on_choice = vim.schedule_wrap(function(_, idx) + if type(idx) == 'number' then + vim.cmd('normal! ' .. idx .. 'z=') end -end - --- todo list -if pcall(require, "todo-comments") then - map("n", "td", "TodoQuickFix", { desc = 'open up list of TODO\'s' }) -end - --- harpoon -if (pcall(require, 'harpoon')) then - local harpoon = require("harpoon") - - map("n", "a", function() - harpoon:list():append() - vim.notify('added new file to quickmarks', vim.log.levels.INFO, { - title = misc.appid, - }) - end) - map('n', '', function() harpoon:list():select(1) end) - map('n', '', function() harpoon:list():select(2) end) - map('n', '', function() harpoon:list():select(3) end) - map('n', '', function() harpoon:list():select(4) end) - - map("n", "", function() harpoon:list():prev() end) - map("n", "", function() harpoon:list():next() end) - - map("n", "", function() require("core.harpoon").switcher() end) -end - -map('n', 'u', 'UndotreeToggle', { desc = 'Open undo tree.' }) -map('n', 'f', 'SFMToggle', { desc = 'Open file tree view.' }) -map('n', '', 'JABSOpen', { desc = 'Switch between buffers.' }) - -if pcall(require, "smart-splits") then - local smartsplits = require('smart-splits') -- resizing buffers (toggleable) - map('n', 'r', smartsplits.start_resize_mode) -end - --- neogen -if pcall(require, "neogen") then - map('n', 'df', require("neogen").generate, { - desc = 'Generate anotations', - }) -end +end) --- venn -function _G.Toggle_venn() - local mapb = vim.api.nvim_buf_set_keymap - local venn_enabled = vim.inspect(vim.b.venn_enabled) - if venn_enabled == "nil" then - vim.notify("Enabled venn mode", vim.log.levels.LOW, { title = misc.appid }) - vim.b.venn_enabled = true - vim.cmd([[setlocal ve=all]]) - -- draw a line on HJKL keystokes - mapb(0, "n", "J", "j:VBox", { noremap = true }) - mapb(0, "n", "K", "k:VBox", { noremap = true }) - mapb(0, "n", "L", "l:VBox", { noremap = true }) - mapb(0, "n", "H", "h:VBox", { noremap = true }) - -- draw a box by pressing "f" with visual selection - mapb(0, "v", "f", ":VBox", { noremap = true }) - else - vim.notify("Disabled venn mode", vim.log.levels.LOW, { title = misc.appid }) - vim.cmd[[setlocal ve=]] - vim.cmd[[mapclear ]] - vim.b.venn_enabled = nil +local spellsuggest_select = function() + if vim.v.count > 0 then + spell_on_choice(nil, vim.v.count) + return end + local cword = vim.fn.expand('') + local prompt = 'Change ' .. vim.inspect(cword) .. ' to:' + vim.ui.select(vim.fn.spellsuggest(cword, vim.o.lines), { prompt = prompt }, spell_on_choice) end --- toggle keymappings for venn using v -map('n', 'v', ":lua Toggle_venn()") + +vim.keymap.set('n', 'z=', spellsuggest_select, { desc = 'Shows spelling suggestions' }) -- cgit v1.2.1