- Accommodating Ideavimrc with Jetbrains quirks

- VIM: New useful keymaps created
- VIM: Config refactored for better portability to many NVim distros
- NVim: Trials with LSP Autocompletion failed :(
This commit is contained in:
Pratik Tripathy
2024-01-10 22:03:06 +05:30
parent 44d124735d
commit f9688cf616
12 changed files with 216 additions and 189 deletions

View File

@@ -9,31 +9,30 @@
-- Loads the system's Vim configs: keeps the VIM & NVim configs in sync
local vimrc = vim.fn.stdpath("config") .. "/vim-sync.vim"
if vim.loop.fs_stat(vimrc) then
vim.cmd("source " .. vimrc)
vim.cmd("source " .. vimrc)
end
-- Setup Lazy.nvim package manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable",
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins", {
change_detection = {
enabled = true,
notify = false
},
change_detection = {
enabled = true,
notify = false,
},
})
require("configs.autocommands")
require("configs.configs")
require("configs.keymaps")

View File

@@ -1,4 +1,4 @@
-- [[ Highlight on yank ]]
-- Highlight on yank
local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', {
callback = function()
@@ -7,4 +7,3 @@ vim.api.nvim_create_autocmd('TextYankPost', {
group = highlight_group,
pattern = '*',
})

View File

@@ -1,3 +1,2 @@
vim.opt.undodir = vim.fn.stdpath("config") .. "/undo"
vim.opt.backupdir = vim.fn.stdpath("config") .. "/backup/"

View File

@@ -1,4 +1,5 @@
-- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
vim.keymap.set("n", "k", "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
vim.keymap.set("n", "j", "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
-- map <leader>j <Plug>(easymotion-s)

View File

@@ -11,9 +11,9 @@ return {
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<C-A-space>",
node_incremental = "<C-A-space>",
scope_incremental = "<C-A-CR>",
init_selection = "<C-space>",
node_incremental = "<C-space>",
scope_incremental = "<C-CR>",
node_decremental = "<bs>",
}
}

View File

@@ -1,24 +1,26 @@
-- TODO: Autocompletion is a hit and miss. Way too complicated at this point
-- TODO: Try doing LazyVim.nvim instead
-- TODO: Use nvim-lint for linting - newer thing
return {
-- LSP Configuration
{
"neovim/nvim-lspconfig",
lazy = false,
config = function()
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig")
lspconfig.tsserver.setup({
capabilities = capabilities,
})
lspconfig.html.setup({
capabilities = capabilities,
})
lspconfig.lua_ls.setup({
capabilities = capabilities,
})
-- local lspconfig = require("lspconfig")
-- lspconfig.tsserver.setup({
-- capabilities = capabilities,
-- })
-- lspconfig.html.setup({
-- capabilities = capabilities,
-- })
-- lspconfig.lua_ls.setup({
-- capabilities = capabilities,
-- })
end
},
{
@@ -41,108 +43,81 @@ return {
end
},
{
"hrsh7th/nvim-cmp",
lazy = false,
config = function()
local cmp = require("cmp")
require("luasnip.loaders.from_vscode").lazy_load()
cmp.setup({
window = {
documentation = cmp.config.window.bordered(),
completion = cmp.config.window.bordered(),
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources(
{
{ name = "nvim_lsp" },
{ name = "luasnip" },
},
{
{ name = "buffer" },
}),
})
end
},
{
"hrsh7th/cmp-nvim-lsp",
lazy = false,
config = true,
},
{
"L3MON4D3/LuaSnip",
version = "v2.*",
lazy = false,
dependencies = {
"rafamadriz/friendly-snippets",
"saadparwaiz1/cmp_luasnip",
-- Spawns linters, parses their outputs & reports results via nvim.diagnostic
"mfussenegger/nvim-lint",
event = {
"BufReadPre",
"BufNewFile"
},
},
{
-- Injects LSP's diagnostics, code actions & formatting
-- None-ls provides methods to add none-LSP sources to provide hooks to NeoVim
-- It also provides helpers to start and capture output of LS-CLI applications
"nvimtools/none-ls.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
-- Hover
null_ls.builtins.hover.dictionary,
local lint = require("lint")
local linters = require("lint").linters
local linterConfig = vim.fn.stdpath("config") .. "linter_configs"
-- Code Actions
null_ls.builtins.code_actions.eslint_d,
null_ls.builtins.code_actions.refactoring,
null_ls.builtins.code_actions.shellcheck,
lint.linters_by_ft = {
json = { "jsonlint" },
protobuf = { "buf", "codespell" },
-- Formattings
null_ls.builtins.formatting.prettierd,
null_ls.builtins.formatting.beautysh,
null_ls.builtins.formatting.buf,
null_ls.builtins.formatting.cs,
null_ls.builtins.formatting.jq,
null_ls.builtins.formatting.rustfmt,
text = { "vale" },
markdown = { "vale", "markdownlint" },
rst = { "vale" },
-- Completions
null_ls.builtins.completion.luasnip,
null_ls.builtins.completion.spell,
html = { "markuplint", "htmlhint" },
-- Diagnostics
null_ls.builtins.diagnostics.buf,
null_ls.builtins.diagnostics.eslint_d,
null_ls.builtins.diagnostics.jsonlint,
null_ls.builtins.diagnostics.luacheck,
null_ls.builtins.diagnostics.markdownlint,
null_ls.builtins.diagnostics.shellcheck,
null_ls.builtins.diagnostics.stylelint,
null_ls.builtins.diagnostics.tsc,
}
bash = { "shellcheck", "codespell" },
shell = { "shellcheck", "codespell" },
lua = { "compiler", "selene", "codespell" },
luau = { "compiler", "selene", "codespell" },
javascript = { "eslint_d", "codespell" },
typescript = { "eslint_d", "codespell" },
javascriptreact = { "eslint_d", "codespell" },
typescriptreact = { "eslint_d", "codespell" },
python = { "pyre", "codespell" },
}
-- use for codespell for all except css
for ft, _ in pairs(lint.linters_by_ft) do
if ft ~= "css" then table.insert(lint.linters_by_ft[ft], "codespell") end
end
linters.codespell.args = {
"--ignore-words",
linterConfig .. "/codespell-ignore.txt",
"--builtin=pratik,kumar,tripathy",
}
linters.shellcheck.args = {
"--shell=bash", -- force to work with zsh
"--format=json",
"-",
}
linters.yamllint.args = {
"--config-file",
linterConfig .. "/yamllint.yaml",
"--format=parsable",
"-",
}
linters.markdownlint.args = {
"--disable=no-trailing-spaces", -- not disabled in config, so it's enabled for formatting
"--disable=no-multiple-blanks",
"--config=" .. linterConfig .. "/markdownlint.yaml",
}
local lint_group = vim.api.nvim_create_augroup("lint", { clear = true })
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
group = lint_group,
callback = function ()
lint.try_lint()
end,
})
vim.keymap.set("n", "K", vim.lsp.buf.hover, {})
vim.keymap.set("n", "<leader>gd", vim.lsp.buf.definition, {})
vim.keymap.set("n", "<leader>gr", vim.lsp.buf.references, {})
vim.keymap.set("n", "<leader>rr", vim.lsp.buf.rename, {})
vim.keymap.set("n", "<leader>df", vim.lsp.buf.format, {})
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev)
vim.keymap.set('n', ']d', vim.diagnostic.goto_next)
vim.keymap.set("n", "<leader>da", vim.lsp.buf.code_action, {})
vim.keymap.set('n', '<leader>do', vim.diagnostic.open_float)
vim.keymap.set('n', '<leader>dq', vim.diagnostic.setloclist)
end
vim.keymap.set("n", "<leader>ll", function ()
lint.try_lint()
end, { desc = "Lint current file" })
end,
},
}

View File

@@ -1,50 +1,50 @@
return {
{
"airblade/vim-rooter",
config = function()
vim.g.rooter_cd_cmd = "tcd"
end
},
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
config = function()
require("neo-tree").setup({
filesystem = {
follow_current_file = {
enabled = true, -- Highlight the current buffer
leave_dirs_open = true,
},
use_libuv_file_watcher = true, -- Sync file system changes
filtered_items = {
visible = true,
show_hidden_count = true,
hide_dotfile = false,
hide_gitignore = false
},
},
window = {
position = "left",
width = 25, -- Saner window size
mappings = {
["s"] = "open_split", -- Default vim keymap for horizontal split
["v"] = "open_vsplit" -- Default vim keymap for vertical split
}
},
default_component_configs = {
indent = {
indent_size = 1, -- Compact tree display
padding = 0 -- Compact tree display
}
}
})
-- Keymaps for Neotree
vim.keymap.set("n", "<Leader>e", ":Neotree filesystem toggle<CR>")
end
}
{
"airblade/vim-rooter",
config = function()
vim.g.rooter_cd_cmd = "tcd"
end,
},
{
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-tree/nvim-web-devicons",
"MunifTanjim/nui.nvim",
},
config = function()
require("neo-tree").setup({
filesystem = {
follow_current_file = {
enabled = true, -- Highlight the current buffer
leave_dirs_open = true,
},
use_libuv_file_watcher = true, -- Sync file system changes
filtered_items = {
visible = true,
show_hidden_count = true,
hide_dotfile = false,
hide_gitignore = false,
},
},
window = {
position = "left",
width = 25, -- Saner window size
mappings = {
["s"] = "open_split", -- Default vim keymap for horizontal split
["v"] = "open_vsplit", -- Default vim keymap for vertical split
},
},
default_component_configs = {
indent = {
indent_size = 1, -- Compact tree display
padding = 0, -- Compact tree display
},
},
})
-- Keymaps for Neotree
vim.keymap.set("n", "<Leader>e", ":Neotree filesystem toggle<CR>")
end,
},
}