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 %') -- 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()')