From 01a09f243ce07d367c539d69d4a7f4541ab1dcd7 Mon Sep 17 00:00:00 2001 From: Squibid Date: Sun, 30 Apr 2023 18:41:13 -0400 Subject: new config old version is now on v1 branch --- lua/core/binds.lua | 148 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 lua/core/binds.lua (limited to 'lua/core/binds.lua') diff --git a/lua/core/binds.lua b/lua/core/binds.lua new file mode 100644 index 0000000..bf04f59 --- /dev/null +++ b/lua/core/binds.lua @@ -0,0 +1,148 @@ +local function map(mode, bind, cmd, opts) + opts = opts or {noremap = true, 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) + else + vim.notify('-- Invalid bind for keymap:\nvim.keymap.set(\'' + .. mode .. '\', ' .. bind .. ', \'' .. cmd .. '\')', + vim.log.levels.WARN, { + title = 'Neovim Config', + on_open = function(win) + local buf = vim.api.nvim_win_get_buf(win) + vim.api.nvim_buf_set_option(buf, "filetype", "lua") + end + } + ) + end +end + +-- vim binds ------------------------------------------------------------------ +g.mapleader = ' ' -- set leader key + +-- greatest remap ever +map('x', 'p', [["_dP]]) + +-- clear search +map('n', '', ':nohlsearch:echo') + +-- move selected text up/down +map('v', '', ":m '<-2gv=gv") +map('v', '', ":m '>+1gv=gv") + +-- the cursor STAYS IN THE MIDDLE +map('n', '', 'mzJ`zdelm z') -- when combining lines +map('n', 'n', 'nzzzv') -- searching +map('n', 'N', 'Nzzzv') +map('n', '', 'zz') -- half page jumping +map('n', '', 'zz') + +-- execute order 111 +map('n', 'x', '!chmod +x %') + +-- tabs +--[[ map('n', '', 'tabnew') +map('n', '', 'tabclose') +map('n', '', 'tabprevious') +map('n', '', 'tabnext') +map('n', 'tL', 'tabmove +1') +map('n', 'tH', 'tabmove -1') ]] + +-- add some keybinds to the file view +a.nvim_create_autocmd('FileType', { + pattern = 'netrw', + callback = function() + local bind = function(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 dotfiles + bind('P', 'z') -- Close preview window + bind('', 'q') -- Close netrw + end +}) + +-- custom menu for simpler neovim managment ----------------------------------- +local function configmenu() + local list = {} + local function add(name, plug) + if not plug then + table.insert(list, name) + return + end + if package.loaded[plug] then + table.insert(list, name) + end + end + + add('edit config') + add('update plugins', 'dep') + + vim.ui.select(list, { prompt = 'Config Menu' }, + function(choice) + if choice == 'edit config' then + vim.cmd'e $XDG_CONFIG_HOME/nvim/init.lua' + end + if choice == 'update plugins' then + require('dep').sync() + if package.loaded['nvim-treesitter'] then + vim.cmd'TSUpdate' + end + if package.loaded['mason'] then + require('mason.api.command').MasonUpdate() + end + end + end) +end + +map('n', '', configmenu) + +-- plugin binds --------------------------------------------------------------- +-- treesj +local treesj = require('treesj') +map('n', 'j', treesj.toggle) + +-- telescope +local telebuilt = require('telescope.builtin') +map('n', 'sf', telebuilt.find_files) +map('n', 'sg', telebuilt.git_files) +map('n', 'sp', function() + telebuilt.grep_string({ search = vim.fn.input('Find string in project > ') }); +end) +map('n', 'so', telebuilt.oldfiles) + +-- intellitab +local intellitab = require('intellitab') +map('n', '', intellitab.indent) + +-- undo tree +map('n', 'u', 'UndotreeToggle') + +-- sfm +map('n', 'f', 'SFMToggle') + +-- dap ui +local dapui = require('dapui') +map('n', 'd', dapui.toggle) + +-- switch between previous buffers +map('n', 'b', 'JABSOpen') + +-- resizing buffers (toggleable) +local smartsplits = require('smart-splits') +map('n', 'r', smartsplits.start_resize_mode) + +-- trouble (lsp error view) +map('n', 't', 'TroubleToggle') + +-- icon picker +map('n', '', 'IconPickerYank') + +-- toggle term +map('t', '', '') -- make work in terminals +map({'n', 't'}, '', 'ToggleTerm size=20') +map({'n', 't'}, 'gl', 'lua _glow()') -- cgit v1.2.1