mirror of
https://github.com/ViViDboarder/vim-settings.git
synced 2024-12-22 23:47:34 +00:00
Now using v0.7+ API functions in many places
This preserves backwards compatibility still, but that will be removed at some point when dropping .6. At that point, another refactor can simplify many of the functions used.
This commit is contained in:
parent
72ba9591e7
commit
0e446b86d1
@ -1,48 +1,43 @@
|
|||||||
local utils = require("utils")
|
local utils = require("utils")
|
||||||
|
|
||||||
-- TODO: Use which-key for mappings
|
utils.keymap_set("n", "<C-L><C-L>", ":set wrap!<CR>", { desc = "Toggle line wrapping" })
|
||||||
local map = vim.api.nvim_set_keymap
|
utils.keymap_set("n", "<leader>lw", ":set wrap!<CR>", { desc = "Toggle line wrapping" })
|
||||||
|
utils.keymap_set("n", "<C-N><C-N>", ":set invnumber<CR>", { desc = "Toggle line numbers" })
|
||||||
local opt_silent = { silent = true }
|
utils.keymap_set("n", "<leader>ln", ":set invnumber<CR>", { desc = "Toggle line numbers" })
|
||||||
local opt_default = { silent = true, noremap = true }
|
utils.keymap_set("n", "<leader>/", ":set hlsearch! hlsearch?<CR>", { desc = "Toggle search highlighting" })
|
||||||
map("n", "<C-L><C-L>", ":set wrap!<CR>", opt_silent)
|
utils.keymap_set("n", "<leader>cs", ":nohlsearch<CR>", { desc = "Clear search highlighting" })
|
||||||
map("n", "<leader>lw", ":set wrap!<CR>", opt_silent)
|
utils.keymap_set("n", "<leader>ws", ":set list!<CR>", { desc = "Toggle whitespace characters" })
|
||||||
map("n", "<C-N><C-N>", ":set invnumber<CR>", opt_silent)
|
|
||||||
map("n", "<leader>ln", ":set invnumber<CR>", opt_silent)
|
|
||||||
map("n", "<leader>/", ":set hlsearch! hlsearch?<CR>", opt_silent)
|
|
||||||
map("n", "<leader>cs", ":nohlsearch<CR>", opt_silent)
|
|
||||||
map("n", "<leader>ws", ":set list!<CR>", opt_silent)
|
|
||||||
|
|
||||||
-- Save and quit typos
|
-- Save and quit typos
|
||||||
map("c", "WQ<CR>", "wq<CR>", opt_silent)
|
utils.keymap_set("c", "WQ<CR>", "wq<CR>", { desc = "Write and quit" })
|
||||||
map("c", "Wq<CR>", "wq<CR>", opt_silent)
|
utils.keymap_set("c", "Wq<CR>", "wq<CR>", { desc = "Write and quit" })
|
||||||
map("c", "W<CR>", "w<CR>", opt_silent)
|
utils.keymap_set("c", "W<CR>", "w<CR>", { desc = "Write" })
|
||||||
map("c", "Q<CR>", "q<CR>", opt_silent)
|
utils.keymap_set("c", "Q<CR>", "q<CR>", { desc = "Quit" })
|
||||||
map("c", "Q!<CR>", "q!<CR>", opt_silent)
|
utils.keymap_set("c", "Q!<CR>", "q!<CR>", { desc = "Force quit" })
|
||||||
map("c", "Qa<CR>", "qa<CR>", opt_silent)
|
utils.keymap_set("c", "Qa<CR>", "qa<CR>", { desc = "Quit all" })
|
||||||
map("c", "Qa!<CR>", "qa!<CR>", opt_silent)
|
utils.keymap_set("c", "Qa!<CR>", "qa!<CR>", { desc = "Force quit all" })
|
||||||
map("c", "QA<CR>", "qa<CR>", opt_silent)
|
utils.keymap_set("c", "QA<CR>", "qa<CR>", { desc = "Quit all" })
|
||||||
map("c", "QA!<CR>", "qa!<CR>", opt_silent)
|
utils.keymap_set("c", "QA!<CR>", "qa!<CR>", { desc = "Force quit all" })
|
||||||
map("c", "w;", "w", opt_default)
|
utils.keymap_set("c", "w;", "w", { desc = "Write" })
|
||||||
map("c", "W;", "w", opt_default)
|
utils.keymap_set("c", "W;", "w", { desc = "Write" })
|
||||||
map("c", "q;", "q", opt_default)
|
utils.keymap_set("c", "q;", "q", { desc = "Quit" })
|
||||||
map("c", "Q;", "q", opt_default)
|
utils.keymap_set("c", "Q;", "q", { desc = "Quit" })
|
||||||
|
|
||||||
-- Paste over
|
-- Paste over
|
||||||
map("v", "pp", "p", opt_default)
|
utils.keymap_set("v", "pp", "p", { desc = "Paste" })
|
||||||
map("v", "po", '"_dP', opt_default)
|
utils.keymap_set("v", "po", '"_dP', { desc = "Paste over and keep clipboard" })
|
||||||
|
|
||||||
-- Buffer nav
|
-- Buffer nav
|
||||||
map("n", "gb", ":bnext<CR>", { desc = "Next buffer" })
|
utils.keymap_set("n", "gb", ":bnext<CR>", { desc = "Next buffer" })
|
||||||
map("n", "gB", ":bprevious<CR>", { desc = "Previous buffer" })
|
utils.keymap_set("n", "gB", ":bprevious<CR>", { desc = "Previous buffer" })
|
||||||
|
|
||||||
-- Easy redo
|
-- Easy redo
|
||||||
map("n", "U", ":redo<CR>", opt_default)
|
utils.keymap_set("n", "U", ":redo<CR>", { desc = "Redo" })
|
||||||
|
|
||||||
-- Make escape easier
|
-- Make escape easier
|
||||||
map("i", "jk", "<esc>", opt_default)
|
utils.keymap_set("i", "jk", "<esc>", { desc = "Escape insert" })
|
||||||
map("i", "``", "<esc>", opt_default)
|
utils.keymap_set("i", "``", "<esc>", { desc = "Escape insert" })
|
||||||
map("v", "``", "<esc>", opt_default)
|
utils.keymap_set("v", "``", "<esc>", { desc = "Escape visual" })
|
||||||
|
|
||||||
-- C-Space completion
|
-- C-Space completion
|
||||||
function _G.complete_space()
|
function _G.complete_space()
|
||||||
@ -58,12 +53,21 @@ function _G.complete_space()
|
|||||||
return utils.t("<C-x><C-o>")
|
return utils.t("<C-x><C-o>")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
map("i", "<C-Space>", "v:lua.complete_space()", { expr = true })
|
utils.keymap_set("i", "<C-Space>", "v:lua.complete_space()", { expr = true })
|
||||||
|
|
||||||
|
-- TODO: remove check when dropping v0.6.0
|
||||||
|
if vim.fn.has("nvim-0.7.0") == 1 then
|
||||||
|
vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" })
|
||||||
|
vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" })
|
||||||
|
vim.api.nvim_create_user_command("Spell", "setlocal spell! spelllang=en_us", { desc = "Toggle spelling" })
|
||||||
|
else
|
||||||
|
vim.cmd("command! TagsUpdate !ctags -R .")
|
||||||
|
vim.cmd("command! Todo grep TODO")
|
||||||
|
vim.cmd("command Spell setlocal spell! spelllang=en_us")
|
||||||
|
end
|
||||||
|
|
||||||
-- Easily toggle spelling
|
|
||||||
vim.cmd("command Spell setlocal spell! spelllang=en_us")
|
|
||||||
-- Pop spelling completion for word under cursor
|
-- Pop spelling completion for word under cursor
|
||||||
map("n", "<leader>s", "viw<esc>a<c-x>s", {})
|
utils.keymap_set("n", "<leader>s", "viw<esc>a<c-x>s", { desc = "Show spelling suggestions" })
|
||||||
|
|
||||||
-- Build on F5
|
-- Build on F5
|
||||||
map("n", "<F5>", ":make<CR>", {})
|
utils.keymap_set("n", "<F5>", ":make<CR>", { desc = "Run make" })
|
||||||
|
@ -5,16 +5,6 @@ require("_settings")
|
|||||||
require("_bindings")
|
require("_bindings")
|
||||||
require("_colors")
|
require("_colors")
|
||||||
|
|
||||||
-- Create commands
|
|
||||||
-- TODO: remove check when dropping v0.6.0
|
|
||||||
if vim.fn.has("nvim-0.7.0") == 1 then
|
|
||||||
vim.api.nvim_create_user_command("TagsUpdate", "!ctags -R .", { desc = "Update ctags" })
|
|
||||||
vim.api.nvim_create_user_command("Todo", "grep TODO", { desc = "Search for TODO tags" })
|
|
||||||
else
|
|
||||||
vim.cmd("command! TagsUpdate !ctags -R .")
|
|
||||||
vim.cmd("command! Todo grep TODO")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Use better grep programs
|
-- Use better grep programs
|
||||||
if vim.fn.executable("rg") == 1 then
|
if vim.fn.executable("rg") == 1 then
|
||||||
o.grepprg = "rg --vimgrep --no-heading --color=never"
|
o.grepprg = "rg --vimgrep --no-heading --color=never"
|
||||||
|
@ -131,9 +131,8 @@ use({
|
|||||||
use({
|
use({
|
||||||
"tomtom/tcomment_vim",
|
"tomtom/tcomment_vim",
|
||||||
config = function()
|
config = function()
|
||||||
-- TODO: use which-key?
|
require("utils").keymap_set("n", "//", ":TComment<CR>", { desc = "Toggle comment" })
|
||||||
vim.api.nvim_set_keymap("n", "//", ":TComment<CR>", { silent = true, noremap = true })
|
require("utils").keymap_set("v", "//", ":TCommentBlock<CR>", { desc = "Toggle comment" })
|
||||||
vim.api.nvim_set_keymap("v", "//", ":TCommentBlock<CR>", { silent = true, noremap = true })
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -141,10 +140,7 @@ use({
|
|||||||
use({
|
use({
|
||||||
"FooSoft/vim-argwrap",
|
"FooSoft/vim-argwrap",
|
||||||
config = function()
|
config = function()
|
||||||
-- TODO: use which-key?
|
require("utils").keymap_set("n", "<Leader>a", "<cmd>ArgWrap<CR>", {
|
||||||
vim.api.nvim_set_keymap("n", "<Leader>a", "<cmd>ArgWrap<CR>", {
|
|
||||||
silent = true,
|
|
||||||
noremap = true,
|
|
||||||
desc = "Wrap or unwrap arguments",
|
desc = "Wrap or unwrap arguments",
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
@ -154,13 +150,11 @@ use({
|
|||||||
use({
|
use({
|
||||||
"tpope/vim-fugitive",
|
"tpope/vim-fugitive",
|
||||||
config = function()
|
config = function()
|
||||||
local opts = { silent = true, noremap = true }
|
require("utils").keymap_set("n", "gb", "<cmd>Git blame<CR>", { desc = "Git blame" })
|
||||||
-- TODO: use which-key?
|
require("utils").keymap_set("n", "gc", "<cmd>Git commit<CR>", { desc = "Git commit" })
|
||||||
vim.api.nvim_set_keymap("n", "gb", "<cmd>Git blame<CR>", opts)
|
require("utils").keymap_set("n", "gd", "<cmd>Git diff<CR>", { desc = "Git diff" })
|
||||||
vim.api.nvim_set_keymap("n", "gc", "<cmd>Git commit<CR>", opts)
|
require("utils").keymap_set("n", "gs", "<cmd>Git<CR>", { desc = "Git status" })
|
||||||
vim.api.nvim_set_keymap("n", "gd", "<cmd>Git diff<CR>", opts)
|
require("utils").keymap_set("n", "gw", "<cmd>Git write<CR>", { desc = "Git write" })
|
||||||
vim.api.nvim_set_keymap("n", "gs", "<cmd>Git<CR>", opts)
|
|
||||||
vim.api.nvim_set_keymap("n", "gw", "<cmd>Git write<CR>", opts)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -168,9 +162,8 @@ use({
|
|||||||
use({
|
use({
|
||||||
"milkypostman/vim-togglelist",
|
"milkypostman/vim-togglelist",
|
||||||
config = function()
|
config = function()
|
||||||
-- TODO: use which-key?
|
require("utils").keymap_set("n", "<F6>", ":call ToggleQuickfixList()<CR>", { desc = "Toggle quickfix" })
|
||||||
vim.api.nvim_set_keymap("n", "<F6>", ":call ToggleQuickfixList()<CR>", { silent = true, noremap = true })
|
require("utils").keymap_set("n", "<F7>", ":call ToggleLocationList()<CR>", { desc = "Toggle location list" })
|
||||||
vim.api.nvim_set_keymap("n", "<F7>", ":call ToggleLocationList()<CR>", { silent = true, noremap = true })
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -406,6 +399,7 @@ use("hsanson/vim-android")
|
|||||||
use({
|
use({
|
||||||
"sheerun/vim-polyglot",
|
"sheerun/vim-polyglot",
|
||||||
config = function()
|
config = function()
|
||||||
|
-- TODO: Replace with api calls when dropping 0.6
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
augroup polyglot_fts
|
augroup polyglot_fts
|
||||||
au BufRead,BufNewFile */playbooks/*.yml,*/playbooks/*.yaml set filetype=yaml.ansible
|
au BufRead,BufNewFile */playbooks/*.yml,*/playbooks/*.yaml set filetype=yaml.ansible
|
||||||
|
@ -45,11 +45,11 @@ function M.config_cmp()
|
|||||||
})
|
})
|
||||||
|
|
||||||
-- Add a plug mapping to use in C-Space binding
|
-- Add a plug mapping to use in C-Space binding
|
||||||
vim.api.nvim_set_keymap(
|
require("utils").keymap_set(
|
||||||
"i",
|
"i",
|
||||||
"<Plug>(cmp_complete)",
|
"<Plug>(cmp_complete)",
|
||||||
"<cmd>lua require('cmp').complete()<CR>",
|
"<cmd>lua require('cmp').complete()<CR>",
|
||||||
{ silent = true, noremap = true }
|
{ desc = "Autocomplete" }
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -8,21 +8,40 @@ vim.g.grepper = {
|
|||||||
dir = "repo,cwd",
|
dir = "repo,cwd",
|
||||||
}
|
}
|
||||||
|
|
||||||
local map = vim.api.nvim_set_keymap
|
require("utils").keymap_set({ "n", "x" }, "gs", "<plug>(GrepperOperator)", {
|
||||||
local opt_silent = { silent = true }
|
silent = true,
|
||||||
map("n", "gs", "<plug>(GrepperOperator)", opt_silent)
|
noremap = false,
|
||||||
map("x", "gs", "<plug>(GrepperOperator)", opt_silent)
|
desc = "Grepper",
|
||||||
|
})
|
||||||
|
|
||||||
-- Override Todo command to use Grepper
|
-- Override Todo command to use Grepper
|
||||||
vim.cmd("command! Todo :Grepper -noprompt -query TODO")
|
-- TODO: Remove check when dropping 0.6
|
||||||
|
if vim.fn.has("nvim-0.7.0") == 1 then
|
||||||
|
vim.api.nvim_create_user_command("Todo", ":Grepper -noprompt -query TODO", { desc = "Search for TODO tags" })
|
||||||
|
else
|
||||||
|
vim.cmd("command! Todo :Grepper -noprompt -query TODO")
|
||||||
|
end
|
||||||
|
|
||||||
-- Make some shortands for various grep programs
|
-- Make some shortands for various grep programs
|
||||||
if vim.fn.executable("rg") == 1 then
|
-- TODO: Remove check when dropping 0.6
|
||||||
|
if vim.fn.has("nvim-0.7.0") == 1 then
|
||||||
|
if vim.fn.executable("rg") == 1 then
|
||||||
|
vim.api.nvim_create_user_command("Rg", ":GrepperRg <args>", { nargs = "+", desc = "Ripgrep" })
|
||||||
|
end
|
||||||
|
if vim.fn.executable("ag") == 1 then
|
||||||
|
vim.api.nvim_create_user_command("Ag", ":GrepperAg <args>", { nargs = "+", desc = "Silversearcher" })
|
||||||
|
end
|
||||||
|
if vim.fn.executable("ack") == 1 then
|
||||||
|
vim.api.nvim_create_user_command("Ack", ":GrepperAck <args>", { nargs = "+", desc = "Ack search" })
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if vim.fn.executable("rg") == 1 then
|
||||||
vim.cmd("command -nargs=+ Rg :GrepperRg <args>")
|
vim.cmd("command -nargs=+ Rg :GrepperRg <args>")
|
||||||
end
|
end
|
||||||
if vim.fn.executable("ag") == 1 then
|
if vim.fn.executable("ag") == 1 then
|
||||||
vim.cmd("command -nargs=+ Ag :GrepperAg <args>")
|
vim.cmd("command -nargs=+ Ag :GrepperAg <args>")
|
||||||
end
|
end
|
||||||
if vim.fn.executable("ack") == 1 then
|
if vim.fn.executable("ack") == 1 then
|
||||||
vim.cmd("command -nargs=+ Ack :GrepperAck <args>")
|
vim.cmd("command -nargs=+ Ack :GrepperAck <args>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -73,10 +73,6 @@ local function get_default_attach(override_capabilities)
|
|||||||
server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {})
|
server_capabilities = vim.tbl_extend("force", server_capabilities, override_capabilities or {})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function buf_set_keymap(...)
|
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function buf_set_option(...)
|
local function buf_set_option(...)
|
||||||
vim.api.nvim_buf_set_option(bufnr, ...)
|
vim.api.nvim_buf_set_option(bufnr, ...)
|
||||||
end
|
end
|
||||||
@ -94,27 +90,37 @@ local function get_default_attach(override_capabilities)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Mappings
|
-- Mappings
|
||||||
local opts = { noremap = true, silent = true }
|
-- TODO: use functions instead of strings when dropping 0.6
|
||||||
local lsp_keymap = utils.keymap_group("n", "<leader>l", opts, bufnr)
|
local lsp_keymap = utils.curry_keymap("n", "<leader>l", { buffer = bufnr })
|
||||||
lsp_keymap("h", "<cmd>lua vim.lsp.buf.hover()<CR>")
|
lsp_keymap("h", "<cmd>lua vim.lsp.buf.hover()<CR>", { desc = "Display hover" })
|
||||||
lsp_keymap("rn", "<cmd>lua vim.lsp.buf.rename()<CR>")
|
lsp_keymap("rn", "<cmd>lua vim.lsp.buf.rename()<CR>", { desc = "Refactor rename" })
|
||||||
lsp_keymap("e", "<cmd>lua vim.diagnostic.open_float()<CR>")
|
lsp_keymap("e", "<cmd>lua vim.diagnostic.open_float()<CR>", { desc = "Open float dialog" })
|
||||||
lsp_keymap("D", "<cmd>lua vim.lsp.buf.declaration()<CR>")
|
lsp_keymap("D", "<cmd>lua vim.lsp.buf.declaration()<CR>", { desc = "Go to declaration" })
|
||||||
lsp_keymap("d", "<cmd>lua vim.lsp.buf.definition()<CR>")
|
lsp_keymap("d", "<cmd>lua vim.lsp.buf.definition()<CR>", { desc = "Go to definition" })
|
||||||
lsp_keymap("t", "<cmd>lua vim.lsp.buf.type_definition()<CR>")
|
lsp_keymap("t", "<cmd>lua vim.lsp.buf.type_definition()<CR>", { desc = "Go to type definition" })
|
||||||
lsp_keymap("i", "<cmd>lua vim.lsp.buf.implementation()<CR>")
|
lsp_keymap("i", "<cmd>lua vim.lsp.buf.implementation()<CR>", { desc = "Show implementations" })
|
||||||
lsp_keymap("s", "<cmd>lua vim.lsp.buf.signature_help()<CR>")
|
lsp_keymap("s", "<cmd>lua vim.lsp.buf.signature_help()<CR>", { desc = "Show signature help" })
|
||||||
lsp_keymap("wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
|
lsp_keymap("wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", { desc = "Workspace: Add folder" })
|
||||||
lsp_keymap("wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
|
lsp_keymap("wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", { desc = "Workspace: Remove folder" })
|
||||||
lsp_keymap("wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
|
lsp_keymap(
|
||||||
lsp_keymap("r", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
|
"wl",
|
||||||
lsp_keymap("p", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
|
"<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>",
|
||||||
lsp_keymap("n", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
|
{ desc = "Workspace: List folders" }
|
||||||
|
)
|
||||||
|
lsp_keymap("r", "<cmd>lua vim.lsp.buf.references()<CR>", { desc = "References" })
|
||||||
|
lsp_keymap("p", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", { desc = "Diagnostics: Go to previous" })
|
||||||
|
lsp_keymap("n", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", { desc = "Diagnostics: Go to next" })
|
||||||
|
|
||||||
-- Set insert keymap for signature help
|
-- Set insert keymap for signature help
|
||||||
buf_set_keymap("i", "<C-k>", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
|
utils.keymap_set(
|
||||||
|
"i",
|
||||||
|
"<C-k>",
|
||||||
|
"<cmd>lua vim.lsp.buf.signature_help()<CR>",
|
||||||
|
{ buffer = bufnr, desc = "Show signature help" }
|
||||||
|
)
|
||||||
|
|
||||||
-- Older keymaps
|
-- Older keymaps
|
||||||
|
--[[
|
||||||
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
buf_set_keymap("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts)
|
||||||
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
buf_set_keymap("n", "gd", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts)
|
||||||
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
buf_set_keymap("n", "K", "<Cmd>lua vim.lsp.buf.hover()<CR>", opts)
|
||||||
@ -129,14 +135,17 @@ local function get_default_attach(override_capabilities)
|
|||||||
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
|
buf_set_keymap("n", "[d", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
|
||||||
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
|
buf_set_keymap("n", "]d", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
|
||||||
buf_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
|
buf_set_keymap("n", "<leader>q", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
|
||||||
|
--]]
|
||||||
|
|
||||||
-- Open diagnostic on hold
|
-- Open diagnostic on hold
|
||||||
if vim["diagnostic"] ~= nil then
|
if vim["diagnostic"] ~= nil then
|
||||||
|
-- TODO: When dropping 0.6, use lua aucommand api
|
||||||
vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]])
|
vim.cmd([[autocmd CursorHold * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Use IncRename if available
|
-- Use IncRename if available
|
||||||
if utils.try_require("inc_rename") ~= nil then
|
if utils.try_require("inc_rename") ~= nil then
|
||||||
|
-- TODO: Should I be using this for calling lua functions from keymaps?
|
||||||
vim.keymap.set("n", "<leader>rn", function()
|
vim.keymap.set("n", "<leader>rn", function()
|
||||||
return ":IncRename " .. vim.fn.expand("<cword>")
|
return ":IncRename " .. vim.fn.expand("<cword>")
|
||||||
end, { expr = true, buffer = true, desc = "Rename current symbol" })
|
end, { expr = true, buffer = true, desc = "Rename current symbol" })
|
||||||
@ -144,25 +153,35 @@ local function get_default_attach(override_capabilities)
|
|||||||
|
|
||||||
-- Set some keybinds conditional on server capabilities
|
-- Set some keybinds conditional on server capabilities
|
||||||
if vim.fn.has("nvim-0.8") == 1 then
|
if vim.fn.has("nvim-0.8") == 1 then
|
||||||
buf_set_keymap("n", "<leader>lf", "<cmd>lua vim.lsp.buf.format({async=true})<CR>", opts)
|
lsp_keymap("f", "<cmd>lua vim.lsp.buf.format({async=true})<CR>", { desc = "Format code" })
|
||||||
buf_set_keymap("v", "<leader>lf", "<cmd>lua vim.lsp.buf.format({async=true})<CR>", opts)
|
lsp_keymap(
|
||||||
|
"f",
|
||||||
|
"<cmd>lua vim.lsp.buf.format({async=true})<CR>",
|
||||||
|
{ mode = "v", desc = "Format selected code" }
|
||||||
|
)
|
||||||
if server_capabilities.documentFormattingProvider then
|
if server_capabilities.documentFormattingProvider then
|
||||||
vim.cmd([[
|
vim.api.nvim_create_autocmd({ "BufWritePre" }, {
|
||||||
augroup lsp_format
|
pattern = { "*.rs", "*.go", "*.sh", "*.lua" },
|
||||||
autocmd!
|
callback = function()
|
||||||
autocmd BufWritePre *.rs,*.go,*.sh,*.lua lua vim.lsp.buf.format({async=false, timeout_ms=1000})
|
vim.lsp.buf.format({ async = false, timeout_ms = 1000 })
|
||||||
augroup END
|
end,
|
||||||
]])
|
group = vim.api.nvim_create_augroup("lsp_format", { clear = true }),
|
||||||
|
desc = "Auto format code on save",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- HACK: Support for <0.8
|
-- HACK: Support for <0.8
|
||||||
buf_set_keymap("n", "<leader>lf", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
|
lsp_keymap("f", "<cmd>lua vim.lsp.buf.formatting()<CR>", { desc = "Format code" })
|
||||||
buf_set_keymap("n", "<leader>lfr", "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
|
lsp_keymap(
|
||||||
|
"f",
|
||||||
|
"<cmd>lua vim.lsp.buf.range_formatting()<CR>",
|
||||||
|
{ mode = "v", desc = "Format selected code" }
|
||||||
|
)
|
||||||
if server_capabilities.documentFormattingProvider then
|
if server_capabilities.documentFormattingProvider then
|
||||||
vim.cmd([[
|
vim.cmd([[
|
||||||
augroup lsp_format
|
augroup lsp_format
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufWritePre *.rs,*.go,*.sh,*.lua lua vim.lsp.buf.formatting_sync(nil, 1000)
|
autocmd BufWritePre lua vim.lsp.buf.formatting_sync(nil, 1000)
|
||||||
augroup END
|
augroup END
|
||||||
]])
|
]])
|
||||||
end
|
end
|
||||||
@ -185,26 +204,25 @@ local function get_default_attach(override_capabilities)
|
|||||||
-- Some override some fuzzy finder bindings to use lsp sources
|
-- Some override some fuzzy finder bindings to use lsp sources
|
||||||
if utils.try_require("telescope") ~= nil then
|
if utils.try_require("telescope") ~= nil then
|
||||||
-- Replace some Telescope bindings with LSP versions
|
-- Replace some Telescope bindings with LSP versions
|
||||||
|
local telescope_keymap = utils.curry_keymap("n", "<leader>f", { buffer = bufnr })
|
||||||
if server_capabilities.documentSymbolProvider then
|
if server_capabilities.documentSymbolProvider then
|
||||||
buf_set_keymap("n", "<leader>t", "<cmd>Telescope lsp_document_symbols<CR>", opts)
|
telescope_keymap("t", "<cmd>Telescope lsp_document_symbols<CR>", { desc = "Find buffer tags" })
|
||||||
end
|
end
|
||||||
if server_capabilities.workspaceSymbolProvider then
|
if server_capabilities.workspaceSymbolProvider then
|
||||||
buf_set_keymap("n", "<leader>ft", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", opts)
|
telescope_keymap("T", "<cmd>Telescope lsp_dynamic_workspace_symbols<CR>", { desc = "Find tags" })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Replace some LSP bindings with Telescope ones
|
-- Replace some LSP bindings with Telescope ones
|
||||||
if server_capabilities.definitionProvider then
|
if server_capabilities.definitionProvider then
|
||||||
lsp_keymap("d", "<cmd>Telescope lsp_definitions<CR>")
|
lsp_keymap("d", "<cmd>Telescope lsp_definitions<CR>", { desc = "Find definition" })
|
||||||
end
|
end
|
||||||
if server_capabilities.typeDefinitionProvider then
|
if server_capabilities.typeDefinitionProvider then
|
||||||
lsp_keymap("t", "<cmd>Telescope lsp_type_definition()<CR>")
|
lsp_keymap("t", "<cmd>Telescope lsp_type_definition<CR>", { desc = "Find type definition" })
|
||||||
end
|
end
|
||||||
lsp_keymap("i", "<cmd>Telescope lsp_implementations<CR>")
|
lsp_keymap("i", "<cmd>Telescope lsp_implementations<CR>", { desc = "Find implementations" })
|
||||||
lsp_keymap("r", "<cmd>Telescope lsp_references<CR>")
|
lsp_keymap("r", "<cmd>Telescope lsp_references<CR>", { desc = "Find references" })
|
||||||
lsp_keymap("A", "<cmd>Telescope lsp_code_actions<CR>")
|
lsp_keymap("A", "<cmd>Telescope lsp_code_actions<CR>", { desc = "Select code actions" })
|
||||||
|
lsp_keymap("A", "<cmd>Telescope lsp_range_code_actions<CR>", { mode = "v", desc = "Select code actions" })
|
||||||
buf_set_keymap("n", "<leader>ca", "<cmd>Telescope lsp_code_actions<CR>", opts)
|
|
||||||
buf_set_keymap("v", "<leader>lA", "<cmd>Telescope lsp_range_code_actions<CR>", opts)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Attach navic for statusline location
|
-- Attach navic for statusline location
|
||||||
|
@ -30,7 +30,7 @@ local function disable_formatter_filetypes_for_existing_servers(sources, preserv
|
|||||||
sources = vim.tbl_map(function(builtin)
|
sources = vim.tbl_map(function(builtin)
|
||||||
if
|
if
|
||||||
builtin.method == NULL_LS_FORMATTING
|
builtin.method == NULL_LS_FORMATTING
|
||||||
or (type(builtin.method) == "table" and utils.list_contains(builtin.method, NULL_LS_FORMATTING))
|
or (type(builtin.method) == "table" and vim.tbl_contains(builtin.method, NULL_LS_FORMATTING))
|
||||||
then
|
then
|
||||||
return builtin.with({ disabled_filetypes = server_filetypes })
|
return builtin.with({ disabled_filetypes = server_filetypes })
|
||||||
end
|
end
|
||||||
|
@ -20,6 +20,28 @@ local function config_telescope()
|
|||||||
layout_strategy = "flex",
|
layout_strategy = "flex",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
local utils = require("utils")
|
||||||
|
utils.try_require("which-key", function(wk)
|
||||||
|
wk.register({
|
||||||
|
["<C-t>"] = { "<cmd>lua require('telescope.builtin').find_files()<CR>", "Find files" },
|
||||||
|
})
|
||||||
|
wk.register({
|
||||||
|
b = { "<cmd>lua require('telescope.builtin').buffers()<CR>", "Find buffers" },
|
||||||
|
t = { "<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>", "Find buffer tags" },
|
||||||
|
["*"] = { "<cmd>lua require('telescope.builtin').grep_string()<CR>", "Find buffers" },
|
||||||
|
f = {
|
||||||
|
b = { "<cmd>lua require('telescope.builtin').buffers()<CR>", "Find buffers" },
|
||||||
|
f = { "<cmd>lua require('telescope.builtin').find_files()<CR>", "Find file" },
|
||||||
|
g = { "<cmd>lua require('telescope.builtin').live_grep()<CR>", "Live grep" },
|
||||||
|
h = { "<cmd>lua require('telescope.builtin').help_tags()<CR>", "Find help tags" },
|
||||||
|
l = { "<cmd>lua require('telescope.builtin').resume()<CR>", "Resume finding" },
|
||||||
|
t = { "<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>", "Find buffer tags" },
|
||||||
|
T = { "<cmd>lua require('telescope.builtin').tags()<CR>", "Find tags" },
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
prefix = "<leader>",
|
||||||
|
})
|
||||||
|
end, function()
|
||||||
local opts = { silent = true, noremap = true }
|
local opts = { silent = true, noremap = true }
|
||||||
vim.api.nvim_set_keymap("n", "<C-t>", "<cmd>lua require('telescope.builtin').find_files()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<C-t>", "<cmd>lua require('telescope.builtin').find_files()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>ff", "<cmd>lua require('telescope.builtin').find_files()<CR>", opts)
|
||||||
@ -27,7 +49,12 @@ local function config_telescope()
|
|||||||
vim.api.nvim_set_keymap("n", "<leader>fh", "<cmd>lua require('telescope.builtin').help_tags()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>fh", "<cmd>lua require('telescope.builtin').help_tags()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>b", "<cmd>lua require('telescope.builtin').buffers()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>b", "<cmd>lua require('telescope.builtin').buffers()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>fb", "<cmd>lua require('telescope.builtin').buffers()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>fb", "<cmd>lua require('telescope.builtin').buffers()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>t", "<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>", opts)
|
vim.api.nvim_set_keymap(
|
||||||
|
"n",
|
||||||
|
"<leader>t",
|
||||||
|
"<cmd>lua require('telescope.builtin').current_buffer_tags()<CR>",
|
||||||
|
opts
|
||||||
|
)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>ft", "<cmd>lua require('telescope.builtin').tags()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>ft", "<cmd>lua require('telescope.builtin').tags()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>fg", "<cmd>lua require('telescope.builtin').live_grep()<CR>", opts)
|
||||||
vim.api.nvim_set_keymap("n", "<leader>*", "<cmd>lua require('telescope.builtin').grep_string()<CR>", opts)
|
vim.api.nvim_set_keymap("n", "<leader>*", "<cmd>lua require('telescope.builtin').grep_string()<CR>", opts)
|
||||||
@ -39,6 +66,7 @@ local function config_telescope()
|
|||||||
"<cmd>lua require('telescope.builtin').spell_suggest(require('telescope.themes').get_cursor())<CR>",
|
"<cmd>lua require('telescope.builtin').spell_suggest(require('telescope.themes').get_cursor())<CR>",
|
||||||
opts
|
opts
|
||||||
)
|
)
|
||||||
|
end)
|
||||||
|
|
||||||
load_extensions()
|
load_extensions()
|
||||||
end
|
end
|
||||||
|
@ -1,33 +1,12 @@
|
|||||||
-- luacheck: globals packer_plugins
|
-- luacheck: globals packer_plugins
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
-- Key mapping
|
|
||||||
function M.map(mode, key, result, opts)
|
|
||||||
M.try_require("which-key", function(wk)
|
|
||||||
local mappings = {}
|
|
||||||
mappings[key] = result
|
|
||||||
wk.register(mappings, {
|
|
||||||
mode = mode,
|
|
||||||
noremap = true,
|
|
||||||
silent = opts.silent or false,
|
|
||||||
expr = opts.expr or false,
|
|
||||||
script = opts.script or false,
|
|
||||||
})
|
|
||||||
end, function()
|
|
||||||
vim.fn.nvim_set_keymap(mode, key, result, {
|
|
||||||
noremap = true,
|
|
||||||
silent = opts.silent or false,
|
|
||||||
expr = opts.expr or false,
|
|
||||||
script = opts.script or false,
|
|
||||||
})
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.get_color(synID, what, mode)
|
function M.get_color(synID, what, mode)
|
||||||
return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(synID)), what, mode)
|
return vim.fn.synIDattr(vim.fn.synIDtrans(vim.fn.hlID(synID)), what, mode)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Create an autocmd
|
-- Create an autocmd
|
||||||
|
-- TODO: Remove this and use nvim_create_autocmd and nvim_create_augroup when dropping .6
|
||||||
function M.autocmd(group, cmds, clear)
|
function M.autocmd(group, cmds, clear)
|
||||||
clear = clear == nil and false or clear
|
clear = clear == nil and false or clear
|
||||||
if type(cmds) == "string" then
|
if type(cmds) == "string" then
|
||||||
@ -133,16 +112,6 @@ function M.cmp_versions(a, b)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Checks if a list contains a value
|
|
||||||
function M.list_contains(list, value)
|
|
||||||
for _, v in pairs(list) do
|
|
||||||
if v == value then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Materializes an iterator into a list
|
-- Materializes an iterator into a list
|
||||||
function M.materialize_list(list, iterator)
|
function M.materialize_list(list, iterator)
|
||||||
if iterator == nil then
|
if iterator == nil then
|
||||||
@ -156,9 +125,10 @@ function M.materialize_list(list, iterator)
|
|||||||
return list
|
return list
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Special not actually nil, but to be treated as nil value in some cases
|
||||||
M.nil_val = {}
|
M.nil_val = {}
|
||||||
|
|
||||||
-- Maps a set of version rules to a value eg. [">0.5.0"] = "has 0.5.0"
|
-- Maps a set of version rules to a value eg. [">=0.5.0"] = "has 0.5.0"
|
||||||
-- If more than one rule matches, the one with the greatest version number is used
|
-- If more than one rule matches, the one with the greatest version number is used
|
||||||
function M.map_version_rule(rules)
|
function M.map_version_rule(rules)
|
||||||
local v = vim.version()
|
local v = vim.version()
|
||||||
@ -174,15 +144,15 @@ function M.map_version_rule(rules)
|
|||||||
local matches = function(cmp, major, minor, patch)
|
local matches = function(cmp, major, minor, patch)
|
||||||
local c = M.cmp_versions(current_version, { major, minor, patch })
|
local c = M.cmp_versions(current_version, { major, minor, patch })
|
||||||
if c == 1 then
|
if c == 1 then
|
||||||
if M.list_contains({ ">", ">=" }, cmp) then
|
if vim.tbl_contains({ ">", ">=" }, cmp) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif c == 0 then
|
elseif c == 0 then
|
||||||
if M.list_contains({ "==", ">=", "<=" }, cmp) then
|
if vim.tbl_contains({ "==", ">=", "<=" }, cmp) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
elseif c == -1 then
|
elseif c == -1 then
|
||||||
if M.list_contains({ "<", "<=" }, cmp) then
|
if vim.tbl_contains({ "<", "<=" }, cmp) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -215,17 +185,65 @@ function M.swapped_map(v, func)
|
|||||||
return func
|
return func
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Returns a function used to create keymaps with consistent prefixes
|
-- Pop from table
|
||||||
function M.keymap_group(mode, prefix, opts, bufnr)
|
function M.tbl_pop(t, key)
|
||||||
local map_fn = vim.api.nvim_set_keymap
|
local v = t[key]
|
||||||
if bufnr ~= nil then
|
t[key] = nil
|
||||||
map_fn = function(...)
|
return v
|
||||||
return vim.api.nvim_buf_set_keymap(bufnr, ...)
|
end
|
||||||
|
|
||||||
|
-- Calls keymap_set with preferred defaults
|
||||||
|
function M.keymap_set(mode, lhs, rhs, opts)
|
||||||
|
opts = vim.tbl_extend("keep", opts, { noremap = true, silent = true })
|
||||||
|
-- TODO: Remove this check when dropping 0.6 support
|
||||||
|
if vim.fn.has("nvim-0.7") == 1 then
|
||||||
|
vim.keymap.set(mode, lhs, rhs, opts)
|
||||||
|
else
|
||||||
|
-- Desc is not supported in 0.6
|
||||||
|
opts["desc"] = nil
|
||||||
|
if type(mode) ~= "string" then
|
||||||
|
for _, m in pairs(mode) do
|
||||||
|
M.keymap_set(m, lhs, rhs, opts)
|
||||||
end
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
-- Buffer requires a different function
|
||||||
|
local buffer = M.tbl_pop(opts, "buffer")
|
||||||
|
if buffer == nil then
|
||||||
|
vim.api.nvim_set_keymap(mode, lhs, rhs, opts)
|
||||||
|
else
|
||||||
|
vim.api.nvim_buf_set_keymap(buffer, mode, lhs, rhs, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a curried function for passing data into vim.keymap.set
|
||||||
|
function M.curry_keymap(mode, prefix, default_opts)
|
||||||
|
default_opts = vim.tbl_extend("keep", default_opts or {}, { noremap = true, silent = true })
|
||||||
|
|
||||||
|
-- TODO: Remove when dropping 0.6
|
||||||
|
if vim.fn.has("nvim-0.7") ~= 1 then
|
||||||
|
-- NOTE: This is incompatible with a lua function on rhs and a bool buffer instead of number
|
||||||
|
return M.keymap_group(mode, prefix, default_opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(keys, rhs, new_opts)
|
return function(lhs, rhs, opts)
|
||||||
map_fn(mode, prefix .. keys, rhs, new_opts or opts)
|
opts = vim.tbl_extend("keep", opts or {}, default_opts)
|
||||||
|
local opt_mode = M.tbl_pop(opts, "mode")
|
||||||
|
vim.keymap.set(opt_mode or mode, prefix .. lhs, rhs, opts)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Returns a function used to create keymaps with consistent prefixes
|
||||||
|
function M.keymap_group(mode, prefix, default_opts)
|
||||||
|
-- TODO: Remove when dropping 0.6 since curry_keymap exists
|
||||||
|
return function(lhs, rhs, opts)
|
||||||
|
opts = opts or default_opts
|
||||||
|
if opts ~= nil and default_opts ~= nil and opts ~= default_opts then
|
||||||
|
opts = vim.tbl_extend("keep", opts, default_opts)
|
||||||
|
end
|
||||||
|
local opt_mode = M.tbl_pop(opts, "mode")
|
||||||
|
M.keymap_set(opt_mode or mode, prefix .. lhs, rhs, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user