add whichkey and more lsps/formaters

This commit is contained in:
Nydragon 2024-05-06 13:36:26 +09:00
parent 4f8db4d933
commit 3e6d75998c
13 changed files with 119 additions and 128 deletions

View file

@ -63,13 +63,16 @@ vim.api.nvim_set_option("updatetime", 300)
-- Show autodiagnostic popup on cursor hover_range -- Show autodiagnostic popup on cursor hover_range
-- Goto previous / next diagnostic warning / error -- Goto previous / next diagnostic warning / error
-- Show inlay_hints more frequently -- Show inlay_hints more frequently
vim.cmd([[ vim.api.nvim_create_autocmd("CursorHold", {
set signcolumn=yes callback = function()
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false }) vim.diagnostic.open_float(nil, { focusable = false })
]]) end,
})
vim.cmd("set signcolumn=yes")
-- Enable filetype plugins -- Enable filetype plugins
vim.cmd("filetype plugin on") vim.cmd("filetype plugin on")
vim.g.mapleader = "," vim.g.mapleader = " "
require("plugins") require("plugins")

View file

@ -1,14 +0,0 @@
vim.g.ale_fixers = {
["*"] = {
"remove_trailing_lines",
"trim_whitespace",
},
["lua"] = {
"lua-format",
},
["rust"] = {
"rustfmt",
},
}
vim.g.ale_fix_on_save = 1

View file

@ -14,8 +14,8 @@ return {
["`"] = { escape = true, close = true, pair = "``" }, ["`"] = { escape = true, close = true, pair = "``" },
}, },
options = { options = {
disabled_filetypes = { "text" }, disabled_filetypes = { "TelescopePrompt", "text", "markdown" },
disable_when_touch = false, disable_when_touch = true,
touch_regex = "[%w(%[{]", touch_regex = "[%w(%[{]",
pair_spaces = false, pair_spaces = false,
auto_indent = true, auto_indent = true,

View file

@ -1,16 +0,0 @@
local map = vim.api.nvim_set_keymap
local opts = { noremap = true, silent = true }
-- Move to previous/next
map("n", "<A-,>", "<Cmd>BufferPrevious<CR>", opts)
-- Goto buffer in position...
map("n", "<A-1>", "<Cmd>BufferGoto 1<CR>", opts)
map("n", "<A-2>", "<Cmd>BufferGoto 2<CR>", opts)
map("n", "<A-3>", "<Cmd>BufferGoto 3<CR>", opts)
map("n", "<A-4>", "<Cmd>BufferGoto 4<CR>", opts)
map("n", "<A-5>", "<Cmd>BufferGoto 5<CR>", opts)
map("n", "<A-6>", "<Cmd>BufferGoto 6<CR>", opts)
map("n", "<A-7>", "<Cmd>BufferGoto 7<CR>", opts)
map("n", "<A-8>", "<Cmd>BufferGoto 8<CR>", opts)
map("n", "<A-9>", "<Cmd>BufferGoto 9<CR>", opts)
map("n", "<A-0>", "<Cmd>BufferLast<CR>", opts)

View file

@ -1,7 +1,22 @@
-- https://github.com/mhartington/formatter.nvim/tree/master/lua/formatter/filetypes
local util = require("formatter.util") local util = require("formatter.util")
local M = {} local M = {}
local function prettier()
return {
exe = "prettier",
args = {
"--stdin-filepath",
util.escape_path(util.get_current_buffer_file_path()),
"--tab-width",
"4",
},
stdin = true,
try_node_modules = true,
}
end
local function build() local function build()
return { return {
logging = true, logging = true,
@ -25,12 +40,33 @@ local function build()
c = { c = {
require("formatter.filetypes.c").clangformat, require("formatter.filetypes.c").clangformat,
}, },
cpp = {
require("formatter.filetypes.cpp").clangformat,
},
r = { r = {
require("formatter.filetypes.r").styler, require("formatter.filetypes.r").styler,
}, },
python = { python = {
require("formatter.filetypes.python").black, require("formatter.filetypes.python").black,
}, },
json = {
prettier,
},
typescript = {
prettier,
},
javascript = {
prettier,
},
fish = {
require("formatter.filetypes.fish").fishindent,
},
markdown = {
require("formatter.filetypes.markdown").prettier,
},
toml = {
require("formatter.filetypes.toml").taplo,
},
["*"] = { ["*"] = {
require("formatter.filetypes.any").remove_trailing_whitespace, require("formatter.filetypes.any").remove_trailing_whitespace,
}, },

View file

@ -1,21 +0,0 @@
local ht = require("haskell-tools")
local def_opts = { noremap = true, silent = true }
ht.setup({
hls = {
on_attach = function(client, bufnr)
local opts = vim.tbl_extend("keep", def_opts, { buffer = bufnr })
-- haskell-language-server relies heavily on codeLenses,
-- so auto-refresh (see advanced configuration) is enabled by default
vim.keymap.set("n", "<space>ca", vim.lsp.codelens.run, opts)
vim.keymap.set("n", "<space>hs", ht.hoogle.hoogle_signature, opts)
end,
},
})
-- Suggested keymaps that do not depend on haskell-language-server
-- Toggle a GHCi repl for the current package
vim.keymap.set("n", "<leader>rr", ht.repl.toggle, def_opts)
-- Toggle a GHCi repl for the current buffer
vim.keymap.set("n", "<leader>rf", function()
ht.repl.toggle(vim.api.nvim_buf_get_name(0))
end, def_opts)
vim.keymap.set("n", "<leader>rq", ht.repl.quit, def_opts)

View file

@ -1,29 +0,0 @@
-- default config
require("image").setup({
backend = "kitty",
integrations = {
markdown = {
enabled = true,
clear_in_insert_mode = false,
download_remote_images = true,
only_render_image_at_cursor = false,
filetypes = { "markdown", "vimwiki" }, -- markdown extensions (ie. quarto) can go here
},
neorg = {
enabled = true,
clear_in_insert_mode = false,
download_remote_images = true,
only_render_image_at_cursor = false,
filetypes = { "norg" },
},
},
max_width = nil,
max_height = nil,
max_width_window_percentage = nil,
max_height_window_percentage = 50,
window_overlap_clear_enabled = false, -- toggles images when windows are overlapped
window_overlap_clear_ft_ignore = { "cmp_menu", "cmp_docs", "" },
editor_only_render_when_focused = false, -- auto show/hide images when the editor gains/looses focus
tmux_show_only_in_active_window = false, -- auto show/hide images in the correct Tmux window (needs visual-activity off)
hijack_file_patterns = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp" }, -- render image files as images when opened
})

View file

@ -1,7 +0,0 @@
local opts = { noremap = true, silent = true }
local keymap = vim.api.nvim_set_keymap
vim.g.mapleader = ","
keymap("n", "<C-p>", ":Telescope find_files<CR>", opts)
keymap("n", "<S-C-p>", ":Telescope<CR>", opts)

View file

@ -1,9 +1,3 @@
local has_words_before = function()
unpack = unpack or table.unpack
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end
local cmp = require("cmp") local cmp = require("cmp")
cmp.setup({ cmp.setup({

View file

@ -50,3 +50,39 @@ require("lspconfig").rust_analyzer.setup({})
require("lspconfig").nixd.setup({}) require("lspconfig").nixd.setup({})
require("lspconfig").r_language_server.setup({}) require("lspconfig").r_language_server.setup({})
require("lspconfig").lua_ls.setup({
on_init = function(client)
local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. "/.luarc.json") or vim.loop.fs_stat(path .. "/.luarc.jsonc") then
return
end
client.config.settings.Lua = vim.tbl_deep_extend("force", client.config.settings.Lua, {
runtime = {
-- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim)
version = "LuaJIT",
},
-- Make the server aware of Neovim runtime files
workspace = {
checkThirdParty = false,
library = {
vim.env.VIMRUNTIME,
-- Depending on the usage, you might want to add additional paths here.
-- "${3rd}/luv/library"
-- "${3rd}/busted/library",
},
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
-- library = vim.api.nvim_get_runtime_file("", true)
},
})
end,
settings = {
Lua = {},
},
})
require("lspconfig").bashls.setup({})
require("lspconfig").zls.setup({})

View file

@ -15,7 +15,7 @@ local function open_nvim_tree(data)
local path = data.file local path = data.file
if vim.fn.isdirectory(data.file) == 0 then if vim.fn.isdirectory(data.file) == 0 then
_, _, i = path:find(".*()/.*") local _, _, i = path:find(".*()/.*")
path = path:sub(0, i) path = path:sub(0, i)
end end

View file

@ -21,6 +21,7 @@ require("lazy").setup({
require("nvim-tree-config") require("nvim-tree-config")
end, end,
opts = { opts = {
update_focused_file = { enable = true },
filters = { filters = {
dotfiles = false, dotfiles = false,
git_ignored = false, git_ignored = false,
@ -33,11 +34,18 @@ require("lazy").setup({
"nvim-tree/nvim-web-devicons", -- optional, for file icons "nvim-tree/nvim-web-devicons", -- optional, for file icons
"lewis6991/gitsigns.nvim", "lewis6991/gitsigns.nvim",
}, },
init = function() opts = {
require("barbar-config") -- lazy.nvim will automatically call setup for you. put your options here, anything missing will use the default:
end, animation = true,
-- insert_at_start = true,
-- …etc.
},
},
{
"nvim-treesitter/nvim-treesitter",
build = ":TSUpdate",
enabled = false,
}, },
{ "nvim-treesitter/nvim-treesitter", enabled = false },
{ {
"neovim/nvim-lspconfig", -- Configurations for Nvim LSP "neovim/nvim-lspconfig", -- Configurations for Nvim LSP
init = function() init = function()
@ -78,7 +86,8 @@ require("lazy").setup({
name = "catppuccin", name = "catppuccin",
priority = 1000, priority = 1000,
}, },
"lukas-reineke/virt-column.nvim", -- thin bar indicating an arbitray character limit { "lukas-reineke/virt-column.nvim", opts = { virtcolumn = "120" } }, -- thin bar indicating an arbitray character limit
{ {
"nvim-telescope/telescope.nvim", -- fuzzy file finder "nvim-telescope/telescope.nvim", -- fuzzy file finder
}, },
@ -102,7 +111,7 @@ require("lazy").setup({
"mhartington/formatter.nvim", "mhartington/formatter.nvim",
--opts = require("formatter-config").build(), --opts = require("formatter-config").build(),
config = function() config = function()
opts = require("formatter-config").build() local opts = require("formatter-config").build()
require("formatter").setup(opts) require("formatter").setup(opts)
end, end,
@ -125,7 +134,7 @@ require("lazy").setup({
local Terminal = require("toggleterm.terminal").Terminal local Terminal = require("toggleterm.terminal").Terminal
local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" }) local lazygit = Terminal:new({ cmd = "lazygit", hidden = true, direction = "float" })
function _lazygit_toggle() function _Lazygit_toggle()
lazygit:toggle() lazygit:toggle()
end end
@ -140,6 +149,7 @@ require("lazy").setup({
vim.o.timeoutlen = 300 vim.o.timeoutlen = 300
end, end,
opts = { opts = {
hidden = { "<silent>", "<cmd>", "<Cmd>", "<CR>", "^:", "^ ", "^call ", "^lua " },
-- your configuration comes here -- your configuration comes here
-- or leave it empty to use the default settings -- or leave it empty to use the default settings
-- refer to the configuration section below -- refer to the configuration section below
@ -159,15 +169,6 @@ autocmd("BufWritePost", {
command = ":FormatWrite", command = ":FormatWrite",
}) })
-- LSP Diagnostics Options Setup
local sign = function(opts)
vim.fn.sign_define(opts.name, {
texthl = opts.name,
text = opts.text,
numhl = "",
})
end
vim.diagnostic.config({ vim.diagnostic.config({
virtual_text = false, virtual_text = false,
signs = true, signs = true,
@ -182,11 +183,6 @@ vim.diagnostic.config({
}, },
}) })
vim.cmd([[
set signcolumn=yes
autocmd CursorHold * lua vim.diagnostic.open_float(nil, { focusable = false })
]])
vim.cmd("colorscheme catppuccin") vim.cmd("colorscheme catppuccin")
--vim.api.nvim_create_autocmd({ "VimLeave" }, { --vim.api.nvim_create_autocmd({ "VimLeave" }, {

View file

@ -1,37 +1,50 @@
local wk = require("which-key") local wk = require("which-key")
wk.register({ wk.register({
t = {
["1"] = {
"<Cmd>BufferGoto 1<CR>",
},
d = {
"<Cmd>BufferClose<CR>",
"Close Current Buffer",
},
},
f = { f = {
"Telescope - Finder", "Telescope - Finder",
f = { f = {
"<cmd>Telescope find_files<cr>", "<cmd>Telescope find_files<CR>",
"Find File", "Find File",
}, },
g = { g = {
"<cmd>Telescope live_grep<cr>", "<cmd>Telescope live_grep<CR>",
"Live Grep", "Live Grep",
}, },
b = { b = {
"<cmd>Telescope buffers<cr>", "<cmd>Telescope buffers<CR>",
"Find Open Buffers", "Find Open Buffers",
}, },
h = { h = {
"<cmd>Telescope help_tags<cr>", "<cmd>Telescope help_tags<CR>",
"Find Help", "Find Help",
}, },
}, },
n = { n = {
"Terminal", "Terminal",
b = { b = {
"<cmd>lua _lazygit_toggle()<CR>", "<cmd>lua _Lazygit_toggle()<CR>",
"Open Lazygit", "Open Lazygit",
}, },
j = { j = {
"<cmd>ToggleTerm<cr>", "<cmd>ToggleTerm<CR>",
"Open Terminal", "Open Terminal",
}, },
}, },
c = { c = {
"NerdCommenter", "NerdCommenter",
}, },
r = {
"<cmd>lua vim.lsp.buf.rename()<CR>",
"Rename a token",
},
}, { prefix = "<leader>" }) }, { prefix = "<leader>" })