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) 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 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.' }) -- the cursor STAYS IN THE MIDDLE map('n', '', 'mzJ`zdelm z') -- when combining lines map('n', 'n', 'nzzzv') -- when searching map('n', 'N', 'Nzzzv') map('n', '', 'zz') -- half page jumping map('n', '', 'zz') map('n', 'x', '!chmod +x %') -- execute order 111 -- add some keybinds to the file view (netrw) 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 }) -- tabs map('n', 'n', 'tabnew') map('n', 'w', 'tabclose') map('n', 'h', 'tabprev') map('n', 'l', 'tabnext') -- 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 map('n', 'sf', telebuilt.find_files, { desc = 'Find files.' }) map('n', 'sg', telebuilt.git_files, { desc = 'Find git files.' }) map('n', 'sp', function() telebuilt.grep_string({ search = vim.fn.input( 'Find string in project > ' ) }) end, { desc = 'Find string in project.' }) map('n', 'so', telebuilt.oldfiles, { desc = 'Find old files.' }) end map('n', 'u', 'UndotreeToggle', { desc = 'Open undo tree.' }) map('n', 'f', 'SFMToggle', { desc = 'Open file tree view.' }) map('n', 'b', 'JABSOpen', { desc = 'Switch between buffers.' }) map('n', 'tt', 'TroubleToggle', { desc = 'Diagnostic list.' }) map('n', 'tc', 'TodoTrouble', { desc = 'Comment list.' }) map('n', '', 'IconPickerYank', { desc = 'Icon picker list.' }) if pcall(require, "dapui") then local dapui = require('dapui') -- dap ui map('n', 'd', dapui.toggle, { desc = 'Debuging ui.' }) end if pcall(require, "smart-splits") then local smartsplits = require('smart-splits') -- resizing buffers (toggleable) map('n', 'r', smartsplits.start_resize_mode) end -- toggle term (don't use leader key in these binds) map({'n', 't'}, '', 'ToggleTerm direction=float') map({'n', 't'}, '', 'lua _glow()') -- true zen if pcall(require, "true-zen") then map('n', 'zf', require("true-zen.focus").toggle, { desc = 'fullscreen', }) map('n', 'zm', require("true-zen.minimalist").toggle, { desc = 'minimal', }) map('n', 'za', require("true-zen.ataraxis").toggle, { desc = 'zen', }) end -- Git map('n', 'gph', 'Gitsigns preview_hunk_inline') map('n', 'gsh', 'Gitsigns stage_hunk') map('n', 'gb', 'Gitsigns blame_line') -- neogen if pcall(require, "neogen") then map('n', 'df', require("neogen").generate, { desc = 'Generate anootations', }) end