- 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

4
.gitignore vendored
View File

@@ -92,3 +92,7 @@ dist-ssr
**/contents/images **/contents/images
**/contents/fonts **/contents/fonts
*kpluginindex.json *kpluginindex.json
*backup
*undo
*sessions

View File

@@ -9,31 +9,30 @@
-- Loads the system's Vim configs: keeps the VIM & NVim configs in sync -- Loads the system's Vim configs: keeps the VIM & NVim configs in sync
local vimrc = vim.fn.stdpath("config") .. "/vim-sync.vim" local vimrc = vim.fn.stdpath("config") .. "/vim-sync.vim"
if vim.loop.fs_stat(vimrc) then if vim.loop.fs_stat(vimrc) then
vim.cmd("source " .. vimrc) vim.cmd("source " .. vimrc)
end end
-- Setup Lazy.nvim package manager -- Setup Lazy.nvim package manager
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then if not vim.loop.fs_stat(lazypath) then
vim.fn.system({ vim.fn.system({
"git", "git",
"clone", "clone",
"--filter=blob:none", "--filter=blob:none",
"https://github.com/folke/lazy.nvim.git", "https://github.com/folke/lazy.nvim.git",
"--branch=stable", "--branch=stable",
lazypath, lazypath,
}) })
end end
vim.opt.rtp:prepend(lazypath) vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins", { require("lazy").setup("plugins", {
change_detection = { change_detection = {
enabled = true, enabled = true,
notify = false notify = false,
}, },
}) })
require("configs.autocommands") require("configs.autocommands")
require("configs.configs") require("configs.configs")
require("configs.keymaps") 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 }) local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
vim.api.nvim_create_autocmd('TextYankPost', { vim.api.nvim_create_autocmd('TextYankPost', {
callback = function() callback = function()
@@ -7,4 +7,3 @@ vim.api.nvim_create_autocmd('TextYankPost', {
group = highlight_group, group = highlight_group,
pattern = '*', pattern = '*',
}) })

View File

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

View File

@@ -1,4 +1,5 @@
-- Remap for dealing with word wrap -- Remap for dealing with word wrap
vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { 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 }) 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 = { incremental_selection = {
enable = true, enable = true,
keymaps = { keymaps = {
init_selection = "<C-A-space>", init_selection = "<C-space>",
node_incremental = "<C-A-space>", node_incremental = "<C-space>",
scope_incremental = "<C-A-CR>", scope_incremental = "<C-CR>",
node_decremental = "<bs>", node_decremental = "<bs>",
} }
} }

View File

@@ -1,24 +1,26 @@
-- TODO: Autocompletion is a hit and miss. Way too complicated at this point -- TODO: Autocompletion is a hit and miss. Way too complicated at this point
-- TODO: Try doing LazyVim.nvim instead -- TODO: Try doing LazyVim.nvim instead
-- TODO: Use nvim-lint for linting - newer thing
return { return {
-- LSP Configuration -- LSP Configuration
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
lazy = false, lazy = false,
config = function() config = function()
local capabilities = require("cmp_nvim_lsp").default_capabilities() -- local capabilities = require("cmp_nvim_lsp").default_capabilities()
local lspconfig = require("lspconfig") -- local lspconfig = require("lspconfig")
lspconfig.tsserver.setup({ -- lspconfig.tsserver.setup({
capabilities = capabilities, -- capabilities = capabilities,
}) -- })
lspconfig.html.setup({ -- lspconfig.html.setup({
capabilities = capabilities, -- capabilities = capabilities,
}) -- })
lspconfig.lua_ls.setup({ -- lspconfig.lua_ls.setup({
capabilities = capabilities, -- capabilities = capabilities,
}) -- })
end end
}, },
{ {
@@ -41,108 +43,81 @@ return {
end end
}, },
{ {
"hrsh7th/nvim-cmp", -- Spawns linters, parses their outputs & reports results via nvim.diagnostic
lazy = false, "mfussenegger/nvim-lint",
config = function() event = {
local cmp = require("cmp") "BufReadPre",
require("luasnip.loaders.from_vscode").lazy_load() "BufNewFile"
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",
}, },
},
{
-- 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() config = function()
local null_ls = require("null-ls") local lint = require("lint")
null_ls.setup({ local linters = require("lint").linters
sources = { local linterConfig = vim.fn.stdpath("config") .. "linter_configs"
-- Hover
null_ls.builtins.hover.dictionary,
-- Code Actions lint.linters_by_ft = {
null_ls.builtins.code_actions.eslint_d, json = { "jsonlint" },
null_ls.builtins.code_actions.refactoring, protobuf = { "buf", "codespell" },
null_ls.builtins.code_actions.shellcheck,
-- Formattings text = { "vale" },
null_ls.builtins.formatting.prettierd, markdown = { "vale", "markdownlint" },
null_ls.builtins.formatting.beautysh, rst = { "vale" },
null_ls.builtins.formatting.buf,
null_ls.builtins.formatting.cs,
null_ls.builtins.formatting.jq,
null_ls.builtins.formatting.rustfmt,
-- Completions html = { "markuplint", "htmlhint" },
null_ls.builtins.completion.luasnip,
null_ls.builtins.completion.spell,
-- Diagnostics bash = { "shellcheck", "codespell" },
null_ls.builtins.diagnostics.buf, shell = { "shellcheck", "codespell" },
null_ls.builtins.diagnostics.eslint_d, lua = { "compiler", "selene", "codespell" },
null_ls.builtins.diagnostics.jsonlint, luau = { "compiler", "selene", "codespell" },
null_ls.builtins.diagnostics.luacheck,
null_ls.builtins.diagnostics.markdownlint, javascript = { "eslint_d", "codespell" },
null_ls.builtins.diagnostics.shellcheck, typescript = { "eslint_d", "codespell" },
null_ls.builtins.diagnostics.stylelint, javascriptreact = { "eslint_d", "codespell" },
null_ls.builtins.diagnostics.tsc, 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>ll", function ()
vim.keymap.set("n", "<leader>gd", vim.lsp.buf.definition, {}) lint.try_lint()
vim.keymap.set("n", "<leader>gr", vim.lsp.buf.references, {}) end, { desc = "Lint current file" })
end,
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
}, },
} }

View File

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

View File

@@ -9,6 +9,10 @@
source ~/.vim/configs.vim source ~/.vim/configs.vim
source ~/.vim/key_maps.vim source ~/.vim/key_maps.vim
" Because :noh does not work in Jetbrains
nnoremap <esc> <esc>
inoremap <esc> <esc>
" Set Tabs to 4 characters " Set Tabs to 4 characters
set expandtab set expandtab
set tabstop=4 set tabstop=4

View File

@@ -17,13 +17,13 @@ set cursorline " Hightlight cursor line
set showmatch " Highlight matching braces set showmatch " Highlight matching braces
set noshowmode " Donot write "--INSERT--" etc. set noshowmode " Donot write "--INSERT--" etc.
set showcmd " Write out commands on status line set showcmd " Write out commands on status line
set ls=2 " Show a status line set laststatus=2 " Show a status line
set wrap " Wrap text set wrap " Wrap text
set number " Show line numbers set number " Show line numbers
set ruler set ruler
set relativenumber " Relative line numbers set relativenumber " Relative line numbers
set shortmess+=I " Disable the default Vim startup message. set shortmess+=I " Disable the default Vim startup message.
set noerrorbells visualbell t_vb= " Disable audible bell because it's annoying. set noerrorbells novisualbell t_vb= " Disable audible bell because it's annoying.
set mouse+=a " Enable mouse support set mouse+=a " Enable mouse support
set encoding=utf-8 " Encoding set encoding=utf-8 " Encoding
set autoread set autoread
@@ -46,6 +46,7 @@ set noswapfile
set undofile set undofile
set undolevels=10000 set undolevels=10000
set undoreload=100000 set undoreload=100000
set timeoutlen=500
" Vim, by default, won't let you jump to a different file without saving the " Vim, by default, won't let you jump to a different file without saving the
" current one. With the below, unsaved files are just hidden. " current one. With the below, unsaved files are just hidden.
@@ -58,8 +59,8 @@ set incsearch hlsearch ignorecase smartcase
hi Comment guifg=#5C6370 ctermfg=50 cterm=italic hi Comment guifg=#5C6370 ctermfg=50 cterm=italic
" Highlight and remove trailing blank spaces on save " Highlight and remove trailing blank spaces on save
highlight ExtraWhitespace ctermbg=red guibg=red " highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/ " match ExtraWhitespace /\s\+$/
autocmd BufWritePre * %s/\s\+$//e autocmd BufWritePre * %s/\s\+$//e
" Vim is based on Vi. Setting `nocompatible` switches from the default " Vim is based on Vi. Setting `nocompatible` switches from the default

View File

@@ -36,28 +36,49 @@ nnoremap N Nzzzv
vnoremap J :m '>+1<CR>gv=gv vnoremap J :m '>+1<CR>gv=gv
vnoremap K :m '<-2<CR>gv=gv vnoremap K :m '<-2<CR>gv=gv
" Better indenting
vnoremap < <gv
vnoremap > >gv
xnoremap < <gv
xnoremap > >gv
" Keeps the cursor at the same place when doing J " Keeps the cursor at the same place when doing J
" And not move to end of the line " And not move to end of the line
nnoremap J mzJ`z:delmarks z<CR> nnoremap J mzJ`z:delmarks z<CR>
" Better Up/Down
nnoremap j gj
xnoremap j gj
nnoremap k gk
xnoremap k gk
" Better window/split navigation " Better window/split navigation
map <C-j> <C-w>j map <C-j> <C-w>j
map <C-k> <C-w>k map <C-k> <C-w>k
map <C-h> <C-w>h map <C-h> <C-w>h
map <C-l> <C-w>l map <C-l> <C-w>l
" Clear searches " Navigate buffers
nnoremap <leader>/ :call clearmatches()<CR>:noh<CR> nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>
" Changes the pwd to the opened file's directory " Resize window using <ctrl> arrow keys
nnoremap <leader>cd :lcd %:h<CR> nnoremap <C-Up> :resize +2<CR>
nnoremap <C-Down> :resize -2<CR>
nnoremap <C-Left> :vertical resize -2<CR>
nnoremap <C-Right> :vertical resize +2<CR>
" Map easymotion Plugin to <Leader>j " Saner search n & N
map <leader>j <Plug>(easymotion-s) nnoremap <expr> n 'Nn'[v:searchforward]
xnoremap <expr> n 'Nn'[v:searchforward]
onoremap <expr> n 'Nn'[v:searchforward]
nnoremap <expr> N 'nN'[v:searchforward]
xnoremap <expr> N 'nN'[v:searchforward]
onoremap <expr> N 'nN'[v:searchforward]
" Map nerdtree to <Leader>e " Clear search highlights
" Changes the pwd and opens the VCS root nnoremap <esc> :nohlsearch<CR><esc>
nnoremap <leader>e :tcd %:h<CR> :NERDTreeToggleVCS<CR> inoremap <esc> :nohlsearch<CR><esc>
" <ctrl-q> to save everything and quit Neovim " <ctrl-q> to save everything and quit Neovim
nnoremap <C-q> :wqa<CR> nnoremap <C-q> :wqa<CR>
@@ -65,3 +86,21 @@ vnoremap <C-q> :wqa<CR>
nnoremap <C-s> :wa<CR> nnoremap <C-s> :wa<CR>
vnoremap <C-s> :wa<CR> vnoremap <C-s> :wa<CR>
" Move cursor in insert mode
inoremap <C-b> <ESC>^i
inoremap <C-e> <END>
inoremap <C-h> <Left>
inoremap <C-l> <Right>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
" Copy entire content of the current buffer
nnoremap <C-c> :%y+<CR>
" Clear search, diff update and redraw
nnoremap <leader>/ :nohlsearch<CR>:diffupdate<CR>:normal! <C-L><CR>
" Changes the pwd to the opened file's directory
nnoremap <leader>cd :lcd %:h<CR>
map <leader>j <Plug>(easymotion-s)

View File

@@ -33,3 +33,9 @@ autocmd! bufwritepost $VIMRC source %
" Save inside vim config directory " Save inside vim config directory
set undodir=$VIMDIR/undo// set undodir=$VIMDIR/undo//
" Map easymotion Plugin to <Leader>j
map <leader>j <Plug>(easymotion-s)
" Map nerdtree to <Leader>e
" Changes the pwd and opens the VCS root
nnoremap <leader>e :tcd %:h<CR> :NERDTreeToggleVCS<CR>