nixos-config/home-manager/neovim/keymaps.lua

49 lines
1.6 KiB
Lua
Raw Normal View History

2022-06-20 13:49:53 +00:00
local function nnoremap(key, command)
vim.api.nvim_set_keymap("n", key, command, { noremap = true })
end
vim.g.mapleader = " "
vim.g.maplocalleader = " "
-- Move around windows
nnoremap("<C-h>", "<C-w>h")
nnoremap("<C-j>", "<C-w>j")
nnoremap("<C-k>", "<C-w>k")
nnoremap("<C-l>", "<C-w>l")
-- Switch buffers
nnoremap("<C-PageDown>", ":TablineBufferNext<CR>")
nnoremap("<C-PageUp>", ":TablineBufferPrevious<CR>")
-- fugitive
nnoremap("<leader>g", ":0Git<CR>")
nnoremap("<leader>G", ":GV --all<CR>")
-- telescope
nnoremap("<leader>ff", "<Cmd>Telescope find_files theme=dropdown<CR>")
nnoremap("<leader>fb", "<Cmd>Telescope buffers theme=dropdown<CR>")
nnoremap("<leader>fg", "<Cmd>Telescope git_files theme=dropdown<CR>")
nnoremap("<leader>fp", "<Cmd>Telescope projects theme=dropdown<CR>")
2022-06-20 13:49:53 +00:00
nnoremap("<C-f>", "<Cmd>Telescope grep_string<CR>")
nnoremap("<C-g>", "<Cmd>Telescope live_grep<CR>")
-- terminal
vim.api.nvim_create_autocmd("TermOpen", {
pattern = "term://*",
callback = function()
local opts = { noremap = true }
vim.api.nvim_buf_set_keymap(0, 't', '<esc>', [[<C-\><C-n>]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-h>', [[<C-\><C-n><C-W>h]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-j>', [[<C-\><C-n><C-W>j]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-k>', [[<C-\><C-n><C-W>k]], opts)
vim.api.nvim_buf_set_keymap(0, 't', '<C-l>', [[<C-\><C-n><C-W>l]], opts)
end,
desc = "Map terminal esc and window switch keys",
})
-- buffer closing
nnoremap("<leader>q", ":Bdelete<CR>")
-- toggle search highlighting
vim.cmd('nnoremap <expr> * v:hlsearch ? ":nohlsearch<cr>" : "*"')