Luigit
repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by admin

neovim/lua/bugabinga/options/keymaps.lua

Raw
local map = require 'std.map'

-- set <SPACE> as leader key
map {
	keys = '<space>',
	command = '<nop>',
}
vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

-- disable them evil arrows
map {
	keys = '<up>',
	command = '<nop>',
}

map {
	keys = '<down>',
	command = '<nop>',
}

map {
	keys = '<left>',
	command = '<nop>',
}

map {
	keys = '<right>',
	command = '<nop>',
}

map.visual {
	description = 'Keep visual selection when indenting',
	keys = '>',
	command = '>gv',
	remap = false,
}

map.visual {
	description = 'Keep visual selection when outdenting',
	keys = '<',
	command = '<gv',
	remap = false,
}

map.normal {
	description = 'Dismiss current search highlight',
	category = 'search',
	keys = '<esc><esc>',
	command = vim.cmd.nohlsearch
}

map.normal {
	description = 'Source current file',
	category = 'vim',
	keys = '<leader>xx',
	command = function()
		vim.cmd.source '%'
		vim.notify('Sourcing current file...')
	end,
}

map.normal {
	description = 'Toggle dark/light theme variant',
	category = 'ui',
	keys = '<leader>tt',
	command = function()
		if vim.opt.background:get() == 'dark' then ---@diagnostic disable-line: undefined-field
			vim.opt.background = 'light'
		else
			vim.opt.background = 'dark'
		end
		vim.notify('Toggled background to ' .. vim.opt.background:get() .. '.') ---@diagnostic disable-line: undefined-field
	end,
}

map.normal {
	description = 'Redo undone operation',
	category = 'history',
	keys = 'U',
	command = vim.cmd.redo,
}

map.normal {
	description = 'Run command and pipe output into temp buffer',
	category = 'external',
	keys = '<leader>c',
	command = function()
		vim.ui.input({ prompt = 'command: ' }, function(cmd)
			if cmd and cmd ~= '' then
				vim.cmd [[noswapfile vnew]]
				vim.bo.buftype = 'nofile'
				vim.bo.bufhidden = 'wipe'
				vim.api.nvim_buf_set_lines(0, 0, -1, false, vim.fn.systemlist(cmd))
			end
		end)
	end,
}

map.normal {
	description = 'Select all text in current buffer',
	category = 'edit',
	keys = '<leader>a',
	command = 'ggVG'
}

map.normal {
	description = 'current project',
	category = 'build',
	keys = '<F9>',
	command = function()
		vim.cmd.wall()
		vim.cmd.make()
	end,
}

map.normal {
	description = 'save',
	category = 'file',
	keys = '<C-S>',
	command = function()
		vim.cmd.FormatSync()
		vim.cmd.wall()
	end,
}