1
0
Fork 0
dotfiles/config/nvim/lua/nifoc/keymap.lua

215 lines
5.4 KiB
Lua
Raw Normal View History

2021-12-06 22:35:29 +00:00
local wk = require('which-key')
2021-12-06 22:35:29 +00:00
local npairs = require('nvim-autopairs')
local telescope = require('telescope')
local telescope_builtin = require('telescope.builtin')
local telescope_themes = require('telescope.themes')
local M = {}
function M.setup()
vim.keymap.set('n', '<space>', '<nop>', {noremap = true})
2021-12-06 22:35:29 +00:00
vim.g.mapleader = ' '
vim.opt.timeoutlen = 500
-- <leader> mappings
local leader = {
n = {
"<cmd>NvimTreeToggle<CR>",
"Toggle nvim-tree"
},
o = {
function() require('nifoc.utils.telescope').project_files() end,
"Find Files"
},
s = {
function() telescope_builtin.live_grep(telescope_themes.get_ivy()) end,
"Live Grep"
},
["ut"] = {
"<cmd>UndotreeToggle<CR>",
"Undotree"
},
f = {
name = "file",
n = {
"<cmd>enew<cr>",
"New File"
},
},
b = {
name = "buffer",
l = {
function() telescope_builtin.buffers(telescope_themes.get_dropdown()) end,
"List Buffers"
},
n = {
"<cmd>BufferLineCycleNext<CR>",
"Next Buffer"
},
p = {
"<cmd>BufferLineCyclePrev<CR>",
"Previous Buffer"
},
f = {
function() telescope_builtin.current_buffer_fuzzy_find(telescope_themes.get_dropdown()) end,
"Find In Buffer"
},
t = {
function() telescope_builtin.treesitter(telescope_themes.get_dropdown()) end,
"Find Via Treesitter"
},
},
p = {
name = "project",
t = {
"<cmd>TodoTelescope<CR>",
"TODO Comments"
},
},
v = {
name = "vcs",
s = {
function() telescope_builtin.git_status(telescope_themes.get_ivy()) end,
"Status"
},
b = {
function() telescope_builtin.git_branches(telescope_themes.get_ivy()) end,
"List Branches"
},
l = {
function() require('gitsigns').blame_line() end,
"Blame Line"
},
n = {
"<cmd>Neogit<CR>",
"Neogit"
},
2021-12-19 20:32:38 +00:00
c = {
"<cmd>Neogit commit<CR>",
"Commit"
},
p = {
"<cmd>Neogit pull<CR>",
"Pull"
},
P = {
"<cmd>Neogit push<CR>",
"Push"
2021-12-19 20:32:38 +00:00
},
2021-12-06 22:35:29 +00:00
},
d = {
name = "debug",
l = {
name = "lsp",
i = {
"<cmd>LspInfo<CR>",
"Info"
},
n = {
"<cmd>NullLsInfo<CR>",
"null-ls Info"
},
2021-12-06 22:35:29 +00:00
r = {
"<cmd>LspRestart<CR>",
"Restart"
}
},
t = {
"<cmd>TSPlaygroundToggle<CR>",
"TS Playground"
},
n = {
function() telescope.extensions.notify.notify() end,
"Notifications"
},
}
}
-- Register which-key mappings
wk.register(leader, {prefix = "<leader>", noremap = false, silent = true})
-- Other mappings
vim.keymap.set('n', '<CR>', ':nohlsearch<CR><CR>', {noremap = true, silent = true})
vim.keymap.set('i', '<CR>', npairs.autopairs_cr, {noremap = true, expr = true, silent = true})
2021-12-06 22:35:29 +00:00
vim.keymap.set('n', '<A-Left>', 'b', {noremap = true})
vim.keymap.set('n', '<A-Right>', 'w', {noremap = true})
vim.keymap.set('n', '<S-Left>', '^', {noremap = true})
vim.keymap.set('n', '<S-Right>', '$', {noremap = true})
vim.keymap.set('i', '<A-Left>', '<C-o>b', {noremap = true})
vim.keymap.set('i', '<A-Right>', '<C-o>w', {noremap = true})
vim.keymap.set('i', '<S-Left>', '<C-o>^', {noremap = true})
vim.keymap.set('i', '<S-Right>', '<C-o>$', {noremap = true})
2021-12-06 22:35:29 +00:00
2021-12-07 20:59:18 +00:00
-- vim-yoink
vim.keymap.set('n', 'p', '<Plug>(YoinkPaste_p)')
vim.keymap.set('n', 'P', '<Plug>(YoinkPaste_P)')
vim.keymap.set('x', 'p', '<Plug>(SubversiveSubstitute)')
vim.keymap.set('x', 'P', '<Plug>(SubversiveSubstitute)')
vim.keymap.set('n', 'gp', '<Plug>(YoinkPaste_gp)')
vim.keymap.set('n', 'gP', '<Plug>(YoinkPaste_gP)')
vim.keymap.set('n', 'y', '<Plug>(YoinkYankPreserveCursorPosition)')
vim.keymap.set('x', 'y', '<Plug>(YoinkYankPreserveCursorPosition)')
2021-12-06 22:35:29 +00:00
vim.api.nvim_set_keymap('n', '<C-t>', '<cmd>lua require("FTerm").toggle()<CR>', {noremap = true, silent = true})
vim.api.nvim_set_keymap('t', '<C-t>', '<C-\\><C-n><cmd>lua require("FTerm").toggle()<CR>', {noremap = true, silent = true})
end
function M.lsp_attach(client, bufnr)
-- <leader> mappings
local leader = {
t = {
"<cmd>Telescope lsp_document_symbols theme=get_dropdown<CR>",
"LSP Document Tags"
},
l = {
name = "lsp",
d = {
name = "diagnostics",
d = {
2021-12-18 22:55:56 +00:00
"<cmd>TroubleToggle document_diagnostics<CR>",
2021-12-06 22:35:29 +00:00
"Document Diagnostics"
},
w = {
2021-12-18 22:55:56 +00:00
"<cmd>TroubleToggle workspace_diagnostics<CR>",
2021-12-06 22:35:29 +00:00
"Workspace Diagnostics"
},
},
c = {
name = "code action",
a = {
"<cmd>Telescope lsp_code_actions theme=get_dropdown<CR>",
"Code Action"
},
},
f = {
name = "find",
r = {
2021-12-18 22:55:56 +00:00
"<cmd>TroubleToggle lsp_references<CR>",
2021-12-06 22:35:29 +00:00
"References"
},
d = {
2021-12-18 22:55:56 +00:00
"<cmd>TroubleToggle lsp_definitions<CR>",
2021-12-06 22:35:29 +00:00
"Definitions"
},
},
},
}
-- Top-level mappings
local top = {
K = {
"<cmd>lua vim.lsp.buf.hover()<CR>",
"Show Documentation"
},
}
-- Register which-key mappings
wk.register(leader, {prefix = "<leader>", noremap = true, silent = true, buffer = bufnr})
wk.register(top, {noremap = true, silent = true, buffer = bufnr})
end
return M