|
|
|
-- General-Purpose keybinds
|
|
|
|
local keymap_opts = { silent = true, noremap = true }
|
|
|
|
|
|
|
|
function NumberToggle()
|
|
|
|
if vim.o.relativenumber then
|
|
|
|
vim.opt.relativenumber = false
|
|
|
|
vim.opt.number = true
|
|
|
|
else
|
|
|
|
vim.opt.relativenumber = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Space is the leader key when outside of insert mode.
|
|
|
|
vim.g.mapleader = " "
|
|
|
|
|
|
|
|
vim.api.nvim_set_keymap('', '<Leader>t', ':NERDTreeToggle<CR>', {silent = true})
|
|
|
|
|
|
|
|
-- <SPC>-r controls relative line numbering.
|
|
|
|
vim.api.nvim_set_keymap('n', '<Leader>r', '<cmd>lua NumberToggle()<CR>', keymap_opts)
|
|
|
|
|
|
|
|
-- Pressing enter in command mode clears the current search highlighting until
|
|
|
|
-- the next search.
|
|
|
|
vim.api.nvim_set_keymap('n', '<CR>', ':noh<CR><CR>', keymap_opts)
|
|
|
|
|
|
|
|
-- Autocomplete bindings
|
|
|
|
vim.keymap.set('i', '<Tab>', function()
|
|
|
|
if vim.fn.pumvisible() == 1 then return '<C-n>' end
|
|
|
|
return '<Tab>'
|
|
|
|
end, {expr = true})
|
|
|
|
|
|
|
|
vim.keymap.set('i', '<S-Tab>', function()
|
|
|
|
if vim.fn.pumvisible() == 1 then return '<C-p>' end
|
|
|
|
return '<S-Tab>'
|
|
|
|
end, {expr = true})
|
|
|
|
|
|
|
|
vim.keymap.set('i', '<CR>', function()
|
|
|
|
if vim.fn.pumvisible() == 1 then
|
|
|
|
vim.cmd [[ asyncomplete#close_popup() . "\<CR>" ]]
|
|
|
|
else
|
|
|
|
return '<CR>'
|
|
|
|
end
|
|
|
|
end, {expr = true})
|
|
|
|
|
|
|
|
vim.keymap.set('i', '<C-Space>', '<Plug>(asyncomplete_force_refresh)', keymap_opts)
|
|
|
|
|
|
|
|
-- This one maps F5 to delete all trailing whitespace
|
|
|
|
vim.api.nvim_set_keymap(
|
|
|
|
'n',
|
|
|
|
'<F5>',
|
|
|
|
[[:let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar>:nohl<CR>]],
|
|
|
|
keymap_opts)
|
|
|
|
|