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', '<leader>p', [["_dP]]) -- clear search map('n', '<ESC>', ':nohlsearch<Bar>:echo<CR>') -- move selected text up/down map('v', '<S-k>', ":m '<-2<CR>gv=gv") map('v', '<S-j>', ":m '>+1<CR>gv=gv") -- the cursor STAYS IN THE MIDDLE map('n', '<S-j>', 'mzJ`z<cmd>delm z<CR>') -- when combining lines map('n', 'n', 'nzzzv') -- searching map('n', 'N', 'Nzzzv') map('n', '<C-d>', '<C-d>zz') -- half page jumping map('n', '<C-u>', '<C-u>zz') -- execute order 111 map('n', '<leader>x', '<cmd>!chmod +x %<CR>') -- 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', '<CR>') -- Go down a directory / open a file bind('.', 'gh') -- Toggle dotfiles bind('P', '<C-w>z') -- Close preview window bind('<ESC>', '<cmd>q<CR>') -- Close netrw end }) -- plugin binds --------------------------------------------------------------- -- treesj local treesj = require('treesj') map('n', '<leader>j', treesj.toggle) -- telescope local telebuilt = require('telescope.builtin') map('n', '<leader>sf', telebuilt.find_files) map('n', '<leader>sg', telebuilt.git_files) map('n', '<leader>sp', function() telebuilt.grep_string({ search = vim.fn.input('Find string in project > ') }); end) map('n', '<leader>so', telebuilt.oldfiles) -- intellitab local intellitab = require('intellitab') map('n', '<Tab>', intellitab.indent) -- undo tree map('n', '<leader>u', '<cmd>UndotreeToggle<CR>') -- sfm map('n', '<leader>f', '<cmd>SFMToggle<CR>') -- dap ui local dapui = require('dapui') map('n', '<leader>d', dapui.toggle) -- switch between previous buffers map('n', '<leader>b', '<cmd>JABSOpen<CR>') -- resizing buffers (toggleable) local smartsplits = require('smart-splits') map('n', '<leader>r', smartsplits.start_resize_mode) -- trouble (lsp error view) map('n', '<leader>t', '<cmd>TroubleToggle<CR>') -- icon picker map('n', '<C-e>', '<cmd>IconPickerYank<CR>') -- toggle term map('t', '<ESC>', '<C-\\><C-n>') -- make <ESC> work in terminals map({'n', 't'}, '<C-\\>', '<cmd>ToggleTerm size=20<CR>') map({'n', 't'}, '<leader>gl', '<cmd>lua _glow()<CR>')