Browse Source

feat: add keymaps to open telescope without ctrl

master
Tovi Jaeschke-Rogers 5 months ago
parent
commit
15f9c6d63e
5 changed files with 201 additions and 198 deletions
  1. +5
    -5
      .config/nvim/lua/tovi/core/remaps.lua
  2. +1
    -1
      .config/nvim/lua/tovi/plugins/formatting.lua
  3. +12
    -12
      .config/nvim/lua/tovi/plugins/lsp/lspconfig.lua
  4. +7
    -11
      .config/nvim/lua/tovi/plugins/nvim-cmp.lua
  5. +176
    -169
      .config/nvim/lua/tovi/plugins/telescope.lua

+ 5
- 5
.config/nvim/lua/tovi/core/remaps.lua View File

@ -11,7 +11,7 @@ vim.keymap.set("n", "<leader>vs", "<cmd>vsplit<cr>", { desc = "Open vertical spi
-- Spell-check -- Spell-check
vim.keymap.set("n", "<leader>o", function() vim.keymap.set("n", "<leader>o", function()
vim.cmd("setlocal spell! spelllang=en_au")
vim.cmd("setlocal spell! spelllang=en_au")
end, { desc = "Toggle spell check" }) end, { desc = "Toggle spell check" })
-- Map Q to nop -- Map Q to nop
@ -43,10 +43,10 @@ vim.keymap.set("n", "<leader>j", "<cmd>cnext<CR>zz", { desc = "Next item in quic
-- Easily run global search and replace -- Easily run global search and replace
vim.keymap.set( vim.keymap.set(
"n",
"<leader>rr",
[[:%s/\<<C-r><C-w>\>//gI<Left><Left><Left>]],
{ desc = "Search and replace for word under cursor" }
"n",
"<leader>rr",
[[:%s/\<<C-r><C-w>\>//gI<Left><Left><Left>]],
{ desc = "Search and replace for word under cursor" }
) )
vim.keymap.set("t", "<C-space>", "<C-\\><C-n>", { silent = true }) vim.keymap.set("t", "<C-space>", "<C-\\><C-n>", { silent = true })

+ 1
- 1
.config/nvim/lua/tovi/plugins/formatting.lua View File

@ -32,7 +32,7 @@ return {
notify_on_error = false, notify_on_error = false,
}) })
vim.keymap.set({ "n", "v" }, "<leader>ff", function()
vim.keymap.set({ "n", "v" }, "<leader>F", function()
conform.format({ conform.format({
lsp_fallback = true, lsp_fallback = true,
async = false, async = false,


+ 12
- 12
.config/nvim/lua/tovi/plugins/lsp/lspconfig.lua View File

@ -50,34 +50,34 @@ return {
opts.desc = "Go to previous diagnostic" opts.desc = "Go to previous diagnostic"
keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer keymap.set("n", "[d", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer
opts.desc = "Go to previous diagnostic"
keymap.set("n", "<leader>pd", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer
-- opts.desc = "Go to previous diagnostic"
-- keymap.set("n", "<leader>pd", vim.diagnostic.goto_prev, opts) -- jump to previous diagnostic in buffer
opts.desc = "Go to next diagnostic" opts.desc = "Go to next diagnostic"
keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer keymap.set("n", "]d", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer
opts.desc = "Go to next diagnostic"
keymap.set("n", "<leader>nd", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer
-- opts.desc = "Go to next diagnostic"
-- keymap.set("n", "<leader>nd", vim.diagnostic.goto_next, opts) -- jump to next diagnostic in buffer
opts.desc = "Go to previous diagnostic (error only)" opts.desc = "Go to previous diagnostic (error only)"
keymap.set("n", "[e", function() keymap.set("n", "[e", function()
vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR }) vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR })
end, opts) end, opts)
opts.desc = "Go to previous diagnostic (error only)"
keymap.set("n", "<leader>pe", function()
vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR })
end, opts)
-- opts.desc = "Go to previous diagnostic (error only)"
-- keymap.set("n", "<leader>pe", function()
-- vim.diagnostic.goto_prev({ severity = vim.diagnostic.severity.ERROR })
-- end, opts)
opts.desc = "Go to next diagnostic (error only)" opts.desc = "Go to next diagnostic (error only)"
keymap.set("n", "]e", function() keymap.set("n", "]e", function()
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR }) vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })
end, opts) end, opts)
opts.desc = "Go to next diagnostic (error only)"
keymap.set("n", "<leader>ne", function()
vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })
end, opts)
-- opts.desc = "Go to next diagnostic (error only)"
-- keymap.set("n", "<leader>ne", function()
-- vim.diagnostic.goto_next({ severity = vim.diagnostic.severity.ERROR })
-- end, opts)
opts.desc = "Show documentation for what is under cursor" opts.desc = "Show documentation for what is under cursor"
keymap.set("n", "<leader>ld", vim.diagnostic.setqflist, opts) -- show documentation for what is under cursor keymap.set("n", "<leader>ld", vim.diagnostic.setqflist, opts) -- show documentation for what is under cursor


+ 7
- 11
.config/nvim/lua/tovi/plugins/nvim-cmp.lua View File

@ -35,10 +35,7 @@ return {
luasnip.lsp_expand(args.body) luasnip.lsp_expand(args.body)
end, end,
}, },
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
window = {},
mapping = cmp.mapping.preset.insert({ mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion ["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion ["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
@ -77,7 +74,6 @@ return {
-- sources for autocompletion -- sources for autocompletion
sources = cmp.config.sources({ sources = cmp.config.sources({
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "copilot" },
{ name = "luasnip" }, { name = "luasnip" },
{ name = "buffer" }, { name = "buffer" },
{ name = "path" }, { name = "path" },
@ -88,12 +84,12 @@ return {
format = lspkind.cmp_format({ format = lspkind.cmp_format({
mode = "symbol_text", mode = "symbol_text",
menu = { menu = {
nvim_lua = "[api]",
nvim_lsp = "[LSP]",
luasnip = "[snip]",
vim_dadbod_completion = "[DB]",
path = "[path]",
buffer = "[Buffer]",
nvim_lua = "[API ]",
nvim_lsp = "[LSP ]",
luasnip = "[SNIP]",
vim_dadbod_completion = "[DBUI]",
path = "[PATH]",
buffer = "[BUFF]",
}, },
}), }),
}, },


+ 176
- 169
.config/nvim/lua/tovi/plugins/telescope.lua View File

@ -1,171 +1,178 @@
return { return {
"nvim-telescope/telescope.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
"nvim-tree/nvim-web-devicons",
"debugloop/telescope-undo.nvim",
"nvim-telescope/telescope-ui-select.nvim",
},
config = function()
local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
local previewers_utils = require("telescope.previewers.utils")
local sorters = require("telescope.sorters")
local builtin = require("telescope.builtin")
local max_size = 100000
local truncate_large_files = function(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
---@diagnostic disable-next-line: undefined-field
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then
return
end
if stat.size > max_size then
local cmd = { "head", "-c", max_size, filepath }
previewers_utils.job_maker(cmd, bufnr, opts)
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end
telescope.setup({
defaults = {
file_sorter = sorters.get_fzy_sorter,
color_devicons = true,
buffer_previewer_maker = truncate_large_files,
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "ascending",
layout_strategy = "horizontal",
layout_config = {
horizontal = {
prompt_position = "top",
preview_width = 0.55,
results_width = 0.8,
},
vertical = {
mirror = false,
},
width = 0.87,
height = 0.80,
preview_cutoff = 120,
},
path_display = { "truncate" },
winblend = 0,
border = {},
mappings = {
i = {
["<C-k>"] = actions.move_selection_previous,
["<C-j>"] = actions.move_selection_next,
["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
},
},
},
extensions = {
undo = {
side_by_side = true,
mappings = {
i = {
["<CR>"] = require("telescope-undo.actions").restore,
},
n = {
["<CR>"] = require("telescope-undo.actions").restore,
["y"] = require("telescope-undo.actions").yank_additions,
["Y"] = require("telescope-undo.actions").yank_deletions,
["u"] = require("telescope-undo.actions").restore,
},
},
},
["ui-select"] = {
require("telescope.themes").get_dropdown({}),
},
},
})
telescope.load_extension("fzf")
telescope.load_extension("undo")
telescope.load_extension("ui-select")
-- We cache the results of "git rev-parse"
-- Process creation is expensive in Windows, so this reduces latency
local is_inside_work_tree = {}
local project_files = function()
local cwd = vim.fn.getcwd()
if is_inside_work_tree[cwd] == nil then
vim.fn.system("git rev-parse --is-inside-work-tree")
is_inside_work_tree[cwd] = vim.v.shell_error == 0
end
if is_inside_work_tree[cwd] then
builtin.git_files({ show_untracked = true, hidden = true })
else
builtin.find_files({})
end
end
-- set keymaps
local keymap = vim.keymap -- for conciseness
keymap.set("n", "<C-g>", function()
builtin.live_grep({ hidden = true })
end, {})
keymap.set("n", "<C-p>", project_files, {})
keymap.set("n", "<leader>fr", builtin.resume, {})
keymap.set("n", "<leader>fb", builtin.buffers, {})
keymap.set("n", "<leader>fo", builtin.oldfiles, {})
keymap.set("n", "<leader>m", builtin.marks, {})
keymap.set("n", "<leader>cc", builtin.commands, {})
keymap.set("n", "<leader>ch", builtin.command_history, {})
keymap.set("n", "<leader>gb", function()
builtin.git_branches({
attach_mappings = function(_, map)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
return true
end,
})
end, {})
keymap.set("n", "<leader>gc", builtin.git_commits, {})
keymap.set("n", "<leader>vh", builtin.help_tags, {})
keymap.set("n", "<leader>ds", builtin.lsp_document_symbols, {})
keymap.set("n", "<leader>ws", builtin.lsp_workspace_symbols, {})
keymap.set("n", "<leader>dws", builtin.lsp_dynamic_workspace_symbols, {})
keymap.set("n", "<leader>gf", function()
builtin.grep_string({
search = vim.fn.expand("<cword>"),
})
end)
keymap.set("n", "<leader>gF", function()
builtin.grep_string({
search = vim.fn.expand("<cWORD>"),
})
end)
keymap.set("n", "<leader>gD", function()
builtin.find_files({
search_file = vim.fn.expand("<cword>"),
})
end)
vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>")
end,
"nvim-telescope/telescope.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", build = "make" },
"nvim-tree/nvim-web-devicons",
"debugloop/telescope-undo.nvim",
"nvim-telescope/telescope-ui-select.nvim",
},
config = function()
local telescope = require("telescope")
local actions = require("telescope.actions")
local previewers = require("telescope.previewers")
local previewers_utils = require("telescope.previewers.utils")
local sorters = require("telescope.sorters")
local builtin = require("telescope.builtin")
local max_size = 100000
local truncate_large_files = function(filepath, bufnr, opts)
opts = opts or {}
filepath = vim.fn.expand(filepath)
---@diagnostic disable-next-line: undefined-field
vim.loop.fs_stat(filepath, function(_, stat)
if not stat then
return
end
if stat.size > max_size then
local cmd = { "head", "-c", max_size, filepath }
previewers_utils.job_maker(cmd, bufnr, opts)
else
previewers.buffer_previewer_maker(filepath, bufnr, opts)
end
end)
end
telescope.setup({
defaults = {
file_sorter = sorters.get_fzy_sorter,
color_devicons = true,
buffer_previewer_maker = truncate_large_files,
initial_mode = "insert",
selection_strategy = "reset",
sorting_strategy = "ascending",
layout_strategy = "horizontal",
layout_config = {
horizontal = {
prompt_position = "top",
preview_width = 0.55,
results_width = 0.8,
},
vertical = {
mirror = false,
},
width = 0.87,
height = 0.80,
preview_cutoff = 120,
},
path_display = { "truncate" },
winblend = 0,
border = {},
mappings = {
i = {
["<C-k>"] = actions.move_selection_previous,
["<C-j>"] = actions.move_selection_next,
["<C-q>"] = actions.send_to_qflist + actions.open_qflist,
},
},
},
extensions = {
undo = {
side_by_side = true,
mappings = {
i = {
["<CR>"] = require("telescope-undo.actions").restore,
},
n = {
["<CR>"] = require("telescope-undo.actions").restore,
["y"] = require("telescope-undo.actions").yank_additions,
["Y"] = require("telescope-undo.actions").yank_deletions,
["u"] = require("telescope-undo.actions").restore,
},
},
},
["ui-select"] = {
require("telescope.themes").get_dropdown({}),
},
},
})
telescope.load_extension("fzf")
telescope.load_extension("undo")
telescope.load_extension("ui-select")
-- We cache the results of "git rev-parse"
-- Process creation is expensive in Windows, so this reduces latency
local is_inside_work_tree = {}
local project_files = function()
local cwd = vim.fn.getcwd()
if is_inside_work_tree[cwd] == nil then
vim.fn.system("git rev-parse --is-inside-work-tree")
is_inside_work_tree[cwd] = vim.v.shell_error == 0
end
if is_inside_work_tree[cwd] then
builtin.git_files({ show_untracked = true, hidden = true })
else
builtin.find_files({})
end
end
-- set keymaps
local keymap = vim.keymap -- for conciseness
keymap.set("n", "<C-g>", function()
builtin.live_grep({ hidden = true })
end, {})
keymap.set("n", "<leader>ff", function()
builtin.live_grep({ hidden = true })
end, {})
keymap.set("n", "<C-p>", project_files, {})
keymap.set("n", "<leader>p", project_files, {})
keymap.set("n", "<leader>fr", builtin.resume, {})
keymap.set("n", "<leader>fb", builtin.buffers, {})
keymap.set("n", "<leader>fo", builtin.oldfiles, {})
keymap.set("n", "<leader>m", builtin.marks, {})
keymap.set("n", "<leader>cc", builtin.commands, {})
keymap.set("n", "<leader>ch", builtin.command_history, {})
keymap.set("n", "<leader>gb", function()
builtin.git_branches({
attach_mappings = function(_, map)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
return true
end,
})
end, {})
keymap.set("n", "<leader>gc", builtin.git_commits, {})
keymap.set("n", "<leader>vh", builtin.help_tags, {})
keymap.set("n", "<leader>ds", builtin.lsp_document_symbols, {})
keymap.set("n", "<leader>ws", builtin.lsp_workspace_symbols, {})
keymap.set("n", "<leader>dws", builtin.lsp_dynamic_workspace_symbols, {})
keymap.set("n", "<leader>gf", function()
builtin.grep_string({
search = vim.fn.expand("<cword>"),
})
end)
keymap.set("n", "<leader>gF", function()
builtin.grep_string({
search = vim.fn.expand("<cWORD>"),
})
end)
keymap.set("n", "<leader>gD", function()
builtin.find_files({
search_file = vim.fn.expand("<cword>"),
})
end)
vim.keymap.set("n", "<leader>u", "<cmd>Telescope undo<cr>")
end,
} }

Loading…
Cancel
Save