vim.keymap.set('n', '<LEADER><SPACE>', '<C-^>')
vim.keymap.set('n', 'j', 'gj')
vim.keymap.set('n', 'k', 'gk')
-vim.keymap.set('n', '<LEADER>w', 'za')
+
+-- center screen after movements
vim.keymap.set('n', 'n', 'nzz')
vim.keymap.set('n', 'N', 'Nzz')
vim.keymap.set('n', '<C-f>', '<C-f>zz')
-- quick config editing
vim.keymap.set('n', '<LEADER>=', '<CMD>tabnew ~/.config/nvim/init.lua<CR>')
vim.keymap.set('n', '<LEADER>q', '<CMD>Lazy<CR>')
-vim.keymap.set('n', '<LEADER>Q', '<CMD>so<CR>')
+vim.keymap.set('n', '<LEADER>Q', '<CMD>source %<CR>')
-- better terminal movement keys
vim.keymap.set('t', '<ESC>', [[<C-\><C-n>]])
-- quickfix navigation
vim.keymap.set('n', '<C-n>', '<CMD>cnext<CR>')
vim.keymap.set('n', '<C-p>', '<CMD>cprev<CR>')
-
--- lsp diagnostics
-vim.keymap.set('n', '<LEADER>n', vim.diagnostic.goto_next)
-vim.keymap.set('n', '<LEADER>p', vim.diagnostic.goto_prev)
-vim.keymap.set('n', '<LEADER>r', vim.lsp.buf.rename)
-vim.keymap.set('n', '<LEADER>a', vim.lsp.buf.code_action)
-vim.keymap.set('n', '<LEADER>k', vim.lsp.buf.hover)
-vim.keymap.set('n', '<LEADER>K', vim.diagnostic.open_float)
-
--- toggle lsp diagnostics
-vim.keymap.set('n', '<LEADER>d',
- function()
- if vim.g.visible_diagnostics then
- vim.diagnostic.disable()
- vim.g.visible_diagnostics = false
- else
- vim.diagnostic.enable()
- vim.g.visible_diagnostics = true
- end
- end
-)
-
--- live grep in git repo, or fall back to current directory
-vim.keymap.set('n', '<LEADER>F',
- function()
- local function is_git_repo()
- vim.fn.system("git rev-parse --is-inside-work-tree")
-
- return vim.v.shell_error == 0
- end
-
- local function get_git_root()
- local dot_git_path = vim.fn.finddir(".git", ".;")
- return vim.fn.fnamemodify(dot_git_path, ":h")
- end
-
- local opts = {}
-
- if is_git_repo() then
- opts = {
- cwd = get_git_root(),
- }
- end
-
- require("telescope.builtin").live_grep(opts)
- end
-)
-
--- fuzzy search over git files, or fall back to all files
-vim.keymap.set('n', '<LEADER>f',
- function()
- local function is_git_repo()
- vim.fn.system("git rev-parse --is-inside-work-tree")
- return vim.v.shell_error == 0
- end
- local function get_git_root()
- local dot_git_path = vim.fn.finddir(".git", ".;")
- return vim.fn.fnamemodify(dot_git_path, ":h")
- end
- local opts = {}
- if is_git_repo() then
- opts = {
- cwd = get_git_root(),
- }
- end
- require("telescope.builtin").find_files(opts)
- end
-)
+local border = {
+ { "┏", "FloatBorder" },
+ { "━", "FloatBorder" },
+ { "┓", "FloatBorder" },
+ { "┃", "FloatBorder" },
+ { "┛", "FloatBorder" },
+ { "━", "FloatBorder" },
+ { "┗", "FloatBorder" },
+ { "┃", "FloatBorder" },
+}
+
+local keybinds = function()
+ vim.keymap.set('n', '<LEADER>n', vim.diagnostic.goto_next)
+ vim.keymap.set('n', '<LEADER>p', vim.diagnostic.goto_prev)
+ vim.keymap.set('n', '<LEADER>r', vim.lsp.buf.rename)
+ vim.keymap.set('n', '<LEADER>a', vim.lsp.buf.code_action)
+ vim.keymap.set('n', '<LEADER>k', vim.lsp.buf.hover)
+ vim.keymap.set('n', '<LEADER>K', vim.diagnostic.open_float)
+ vim.keymap.set('n', '<C-]>', vim.lsp.buf.definition)
+
+ -- toggle lsp diagnostics
+ vim.keymap.set('n', '<LEADER>d',
+ function()
+ if vim.g.visible_diagnostics then
+ vim.diagnostic.disable()
+ vim.g.visible_diagnostics = false
+ else
+ vim.diagnostic.enable()
+ vim.g.visible_diagnostics = true
+ end
+ end
+ )
+end
+
return {
{
"jose-elias-alvarez/null-ls.nvim",
config = function()
-- servers to setup
local lsp = require("lspconfig")
- lsp.awk_ls.setup({})
- lsp.bashls.setup({})
- lsp.clangd.setup({})
- lsp.cssls.setup({})
- lsp.html.setup({})
- lsp.lua_ls.setup({})
- lsp.solargraph.setup({})
+
+ lsp.awk_ls.setup({ on_attach = keybinds })
+ lsp.bashls.setup({ on_attach = keybinds })
+ lsp.clangd.setup({ on_attach = keybinds })
+ lsp.cssls.setup({ on_attach = keybinds })
+ lsp.html.setup({ on_attach = keybinds })
+ lsp.lua_ls.setup({ on_attach = keybinds })
+ lsp.solargraph.setup({ on_attach = keybinds })
-- diagnostic settings
vim.lsp.diagnostics = {
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
- -- borders on windows
- local border = {
- { "┏", "FloatBorder" },
- { "━", "FloatBorder" },
- { "┓", "FloatBorder" },
- { "┃", "FloatBorder" },
- { "┛", "FloatBorder" },
- { "━", "FloatBorder" },
- { "┗", "FloatBorder" },
- { "┃", "FloatBorder" },
- }
-
local orig_util_open_floating_preview = vim.lsp.util.open_floating_preview
function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...)
opts = opts or {}
other_hints_prefix = "-> "
},
hover_actions = {
- border = {
- { "┏", "FloatBorder" },
- { "━", "FloatBorder" },
- { "┓", "FloatBorder" },
- { "┃", "FloatBorder" },
- { "┛", "FloatBorder" },
- { "━", "FloatBorder" },
- { "┗", "FloatBorder" },
- { "┃", "FloatBorder" },
- },
+ border = border,
auto_focus = true
}
},
}
},
on_attach = function(_, bufnr)
+ keybinds()
vim.keymap.set('n', '<LEADER>k', rust.hover_actions.hover_actions, { buffer = bufnr })
vim.keymap.set('n', '<LEADER>a', rust.code_action_group.code_action_group, { buffer = bufnr })
vim.keymap.set('n', '<LEADER>m', rust.expand_macro.expand_macro, { buffer = bufnr })
{ '<C-_>', '<CMD>Telescope current_buffer_fuzzy_find sorting_strategy=ascending<CR>' },
{ '<C-r>', '<CMD>Telescope command_history<CR>' },
{ '<LEADER>b', '<CMD>Telescope buffers<CR>' },
- { '<LEADER>l', '<CMD>Telescope diagnostics<CR>' },
- { '<LEADER>R', '<CMD>Telescope lsp_references<CR>' },
{ '<LEADER>tt', '<CMD>Telescope resume<CR>' },
{ '<LEADER>tc', '<CMD>Telescope commands<CR>' },
{ '<LEADER>th', '<CMD>Telescope help_tags<CR>' },
{ '<LEADER>tgb', '<CMD>Telescope git_branches<CR>' },
{ '<LEADER>tgs', '<CMD>Telescope git_status<CR>' },
{ '<LEADER>tft', '<CMD>Telescope filetypes<CR>' },
- { '<LEADER>tld', '<CMD>Telescope lsp_type_definitions<CR>' },
- { '<LEADER>tlt', '<CMD>Telescope lsp_definitions<CR>' },
- { '<LEADER>tli', '<CMD>Telescope lsp_implementations<CR>' },
- { '<LEADER>tls', '<CMD>Telescope lsp_document_symbols<CR>' },
- { '<LEADER>tlS', '<CMD>Telescope lsp_workspace_symbols<CR>' },
+ { '<LEADER>ll', '<CMD>Telescope diagnostics<CR>' },
+ { '<LEADER>lr', '<CMD>Telescope lsp_references<CR>' },
+ { '<LEADER>lt', '<CMD>Telescope lsp_type_definitions<CR>' },
+ { '<LEADER>ld', '<CMD>Telescope lsp_definitions<CR>' },
+ { '<LEADER>li', '<CMD>Telescope lsp_implementations<CR>' },
+ { '<LEADER>ls', '<CMD>Telescope lsp_document_symbols<CR>' },
+ { '<LEADER>lS', '<CMD>Telescope lsp_workspace_symbols<CR>' },
},
config = function()
local actions = require('telescope.actions')
require('telescope').load_extension('fzf')
+
+ -- live grep in git repo, or fall back to current directory
+ vim.keymap.set('n', '<LEADER>F',
+ function()
+ local function is_git_repo()
+ vim.fn.system("git rev-parse --is-inside-work-tree")
+
+ return vim.v.shell_error == 0
+ end
+
+ local function get_git_root()
+ local dot_git_path = vim.fn.finddir(".git", ".;")
+ return vim.fn.fnamemodify(dot_git_path, ":h")
+ end
+
+ local opts = {}
+
+ if is_git_repo() then
+ opts = {
+ cwd = get_git_root(),
+ }
+ end
+
+ require("telescope.builtin").live_grep(opts)
+ end
+ )
+
+ -- fuzzy search over git files, or fall back to all files
+ vim.keymap.set('n', '<LEADER>f',
+ function()
+ local function is_git_repo()
+ vim.fn.system("git rev-parse --is-inside-work-tree")
+ return vim.v.shell_error == 0
+ end
+ local function get_git_root()
+ local dot_git_path = vim.fn.finddir(".git", ".;")
+ return vim.fn.fnamemodify(dot_git_path, ":h")
+ end
+ local opts = {}
+ if is_git_repo() then
+ opts = {
+ cwd = get_git_root(),
+ }
+ end
+ require("telescope.builtin").find_files(opts)
+ end
+ )
+
+
-- give telescope window if opened with no command
vim.api.nvim_create_autocmd('VimEnter', {
pattern = '*',