feat(nvim): add keymaps

This commit is contained in:
Maciej Jur 2023-09-02 22:09:00 +02:00
parent 65f182862a
commit 8a386796eb
Signed by: kamov
GPG key ID: 191CBFF5F72ECAFD
7 changed files with 109 additions and 46 deletions

View file

@ -5,6 +5,7 @@ end
-- Setup default options
require("options")
require("keymaps")
-- Are we inside Neovide?
if vim.g.neovide then

View file

@ -6,24 +6,25 @@
"cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"cmp_luasnip": { "branch": "master", "commit": "18095520391186d634a0045dacaa346291096566" },
"diffview.nvim": { "branch": "main", "commit": "db97e667e03294bfa9f15e544e78f3082247bf79" },
"gitsigns.nvim": { "branch": "main", "commit": "749267aaa863c30d721c9913699c5d94e0c07dd3" },
"haskell-tools.nvim": { "branch": "1.x.x", "commit": "2c3cbdf386ecb03210b56962db96e601705c5118" },
"kanagawa.nvim": { "branch": "master", "commit": "1749cea392acb7d1548a946fcee1e6f1304cd3cb" },
"lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" },
"diffview.nvim": { "branch": "main", "commit": "7e5a85c186027cab1e825d018f07c350177077fc" },
"gitsigns.nvim": { "branch": "main", "commit": "d927caa075df63bf301d92f874efb72fd22fd3b4" },
"haskell-tools.nvim": { "branch": "1.x.x", "commit": "0bf0c887eeb7febe2199b7638befb4138d293111" },
"kanagawa.nvim": { "branch": "master", "commit": "0a24e504a3a278849ad0aef31cd6dd24c73ca3db" },
"lazy.nvim": { "branch": "main", "commit": "2a9354c7d2368d78cbd5575a51a2af5bd8a6ad01" },
"lualine.nvim": { "branch": "master", "commit": "45e27ca739c7be6c49e5496d14fcf45a303c3a63" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "2997f467881ac4faa6f8c5e7065e3a672297c8ad" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "dfdd771b792fbb4bad8e057d72558255695aa1a7" },
"mason-nvim-dap.nvim": { "branch": "main", "commit": "6148b51db945b55b3b725da39eaea6441e59dff8" },
"mason.nvim": { "branch": "main", "commit": "a51c2d063c5377ee9e58c5f9cda7c7436787be72" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "cac2e1bfa1ecd5bd0ce7ae29e12efb3ba5a7347d" },
"nui.nvim": { "branch": "main", "commit": "9e3916e784660f55f47daa6f26053ad044db5d6a" },
"nvim-cmp": { "branch": "main", "commit": "51f1e11a89ec701221877532ee1a23557d291dd5" },
"nvim-dap": { "branch": "master", "commit": "1c63f37f95cd4fb54512898168138d9a75d1516a" },
"mason.nvim": { "branch": "main", "commit": "0942198fb9a998b6ccee36fb8dd7495eb8ba659c" },
"neo-tree.nvim": { "branch": "v3.x", "commit": "9b5b4c874b13e372500f07c37187ba06c0c1ac0a" },
"nui.nvim": { "branch": "main", "commit": "aa1b4c1e05983ff7debd2b4b2788651db099de2f" },
"nvim-cmp": { "branch": "main", "commit": "5dce1b778b85c717f6614e3f4da45e9f19f54435" },
"nvim-dap": { "branch": "master", "commit": "31e1ece773e10448dcb616d5144290946a6264b7" },
"nvim-dap-ui": { "branch": "master", "commit": "85b16ac2309d85c88577cd8ee1733ce52be8227e" },
"nvim-lspconfig": { "branch": "master", "commit": "67f151e84daddc86cc65f5d935e592f76b9f4496" },
"nvim-treesitter": { "branch": "master", "commit": "43b2153d26da8308e3d58ac0db911111c7c35395" },
"nvim-lspconfig": { "branch": "master", "commit": "a27356f1ef9c11e1f459cc96a3fcac5c265e72d6" },
"nvim-treesitter": { "branch": "master", "commit": "17b943e7c5cc2b2db3ac7b5720fbd42e75a00d8d" },
"nvim-web-devicons": { "branch": "master", "commit": "cfc8824cc1db316a276b36517f093baccb8e799a" },
"plenary.nvim": { "branch": "master", "commit": "267282a9ce242bbb0c5dc31445b6d353bed978bb" },
"plenary.nvim": { "branch": "master", "commit": "0dbe561ae023f02c2fb772b879e905055b939ce3" },
"rust-tools.nvim": { "branch": "master", "commit": "0cc8adab23117783a0292a0c8a2fbed1005dc645" },
"telescope-fzf-native.nvim": { "branch": "main", "commit": "9bc8237565ded606e6c366a71c64c0af25cd7a50" },
"telescope.nvim": { "branch": "0.1.x", "commit": "776b509f80dd49d8205b9b0d94485568236d1192" }
}

21
nvim/lua/keymaps.lua Normal file
View file

@ -0,0 +1,21 @@
local map = require("utility").curried_map
local n, t = map 'n', map 't'
n "<Leader>hl" ":nohl<CR>" "Hide highlights"
n "j" "gj" "Move: down by line"
n "k" "gk" "Move: up by line"
n "<Leader>bn" ":bn<CR>" "Buffer: next"
n "<Leader>bp" ":bp<CR>" "Buffer: previous"
n "<Leader>bd" ":bd<CR>" "Buffer: delete"
t "<Esc><Esc>" [[<C-\><C-n>]] "Exit from terminal mode"
n "<C-h>" "<C-w>h" "Window: move left"
n "<C-j>" "<C-w>j" "Window: move down"
n "<C-k>" "<C-w>k" "Window: move up"
n "<C-l>" "<C-w>l" "Window: move right"
n "<Leader>e" ":Explore<CR>" "Netrw: open"

View file

@ -37,6 +37,7 @@ vim.filetype.add({
extension = {
mdx = "mdx",
typ = "typst",
purs = "purescript",
}
})

View file

@ -1,4 +1,4 @@
local U = require("utils")
local U = require("utility")
return {
@ -24,6 +24,38 @@ return {
end
},
-- Telescope
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = {
"nvim-lua/plenary.nvim",
{"nvim-telescope/telescope-fzf-native.nvim", build = "make"}
},
config = function()
local telescope = require "telescope"
local builtin = require "telescope.builtin"
telescope.setup({
extensions = {
fzf = {
fuzzy = true,
override_generic_sorter = true,
override_file_sorter = true,
case_mode = "smart_case",
}
}
})
telescope.load_extension("fzf")
local nmap = U.curried_map 'n'
nmap "<leader>ff" (builtin.find_files) "Telescope: find files"
nmap "<leader>fb" (builtin.buffers) "Telescope: find buffers"
nmap "<leader>fg" (builtin.live_grep) "Telescope: grep content"
nmap "<leader>fh" (builtin.help_tags) "Telescope: search docs"
end,
},
-- File tree
{
"nvim-neo-tree/neo-tree.nvim",
@ -35,22 +67,6 @@ return {
},
},
-- Telescope
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
dependencies = {
"nvim-lua/plenary.nvim",
},
config = function()
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
end,
},
-- Bufferline
{
'akinsho/bufferline.nvim',

38
nvim/lua/utility.lua Normal file
View file

@ -0,0 +1,38 @@
local M = {}
local def_opts = {noremap = true, silent = true}
---Loads plugin config
---@param path string
function M.plugin(path)
local loaded = require(path)
---@param meta table
---@return table
return function(meta)
return vim.tbl_extend("keep", meta, loaded)
end
end
---Wrapper around `vim.keymap.set`
---@param modes string|string[]
function M.curried_map(modes)
---@param lhs string
return function(lhs)
---@param rhs string|function
return function(rhs)
---@param opts string|table
return function(opts)
local supplied = type(opts)
local options
if supplied == "string" then
options = vim.tbl_extend("force", def_opts, {desc=opts})
else
options = vim.tbl_extend("force", def_opts, opts)
end
vim.keymap.set(modes, lhs, rhs, options)
end
end
end
end
return M

View file

@ -1,15 +0,0 @@
local M = {}
--- Loads plugin config
---@param path string
---@return fun(meta: table): table
function M.plugin(path)
local loaded = require(path)
return function(meta)
return vim.tbl_extend("keep", meta, loaded)
end
end
return M