repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim/lua/bugabinga/options/keymaps.lua

Raw
local map = require 'std.map'
local togglers = require 'bugabinga.options.togglers'

-- 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,
}

for _, toggler in ipairs(togglers) do
  local option_name = toggler.options[1].name
  local first_char = string.sub(option_name, 1, 1)

  map.normal {
    description = 'Toggle ' .. option_name .. ' option',
    category = 'options',
    keys = '<leader>t' .. first_char,
    command = function()
      toggler:toggle()
    end,
  }
end

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,
}