- 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/fonts
*kpluginindex.json
*backup
*undo
*sessions

View File

@@ -29,11 +29,10 @@ vim.opt.rtp:prepend(lazypath)
require("lazy").setup("plugins", {
change_detection = {
enabled = true,
notify = false
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(),
-- Spawns linters, parses their outputs & reports results via nvim.diagnostic
"mfussenegger/nvim-lint",
event = {
"BufReadPre",
"BufNewFile"
},
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
config = function()
local lint = require("lint")
local linters = require("lint").linters
local linterConfig = vim.fn.stdpath("config") .. "linter_configs"
lint.linters_by_ft = {
json = { "jsonlint" },
protobuf = { "buf", "codespell" },
text = { "vale" },
markdown = { "vale", "markdownlint" },
rst = { "vale" },
html = { "markuplint", "htmlhint" },
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", "<leader>ll", function ()
lint.try_lint()
end, { desc = "Lint current file" })
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()
local null_ls = require("null-ls")
null_ls.setup({
sources = {
-- Hover
null_ls.builtins.hover.dictionary,
-- Code Actions
null_ls.builtins.code_actions.eslint_d,
null_ls.builtins.code_actions.refactoring,
null_ls.builtins.code_actions.shellcheck,
-- 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,
-- Completions
null_ls.builtins.completion.luasnip,
null_ls.builtins.completion.spell,
-- 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,
}
})
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
},
}

View File

@@ -3,7 +3,7 @@ return {
"airblade/vim-rooter",
config = function()
vim.g.rooter_cd_cmd = "tcd"
end
end,
},
{
"nvim-neo-tree/neo-tree.nvim",
@@ -25,7 +25,7 @@ return {
visible = true,
show_hidden_count = true,
hide_dotfile = false,
hide_gitignore = false
hide_gitignore = false,
},
},
window = {
@@ -33,18 +33,18 @@ return {
width = 25, -- Saner window size
mappings = {
["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 = {
indent = {
indent_size = 1, -- Compact tree display
padding = 0 -- Compact tree display
}
}
padding = 0, -- Compact tree display
},
},
})
-- Keymaps for Neotree
vim.keymap.set("n", "<Leader>e", ":Neotree filesystem toggle<CR>")
end
}
end,
},
}

View File

@@ -9,6 +9,10 @@
source ~/.vim/configs.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 expandtab
set tabstop=4

View File

@@ -17,13 +17,13 @@ set cursorline " Hightlight cursor line
set showmatch " Highlight matching braces
set noshowmode " Donot write "--INSERT--" etc.
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 number " Show line numbers
set ruler
set relativenumber " Relative line numbers
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 encoding=utf-8 " Encoding
set autoread
@@ -46,6 +46,7 @@ set noswapfile
set undofile
set undolevels=10000
set undoreload=100000
set timeoutlen=500
" 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.
@@ -58,8 +59,8 @@ set incsearch hlsearch ignorecase smartcase
hi Comment guifg=#5C6370 ctermfg=50 cterm=italic
" Highlight and remove trailing blank spaces on save
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
" highlight ExtraWhitespace ctermbg=red guibg=red
" match ExtraWhitespace /\s\+$/
autocmd BufWritePre * %s/\s\+$//e
" 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 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
" And not move to end of the line
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
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-h> <C-w>h
map <C-l> <C-w>l
" Clear searches
nnoremap <leader>/ :call clearmatches()<CR>:noh<CR>
" Navigate buffers
nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>
" Changes the pwd to the opened file's directory
nnoremap <leader>cd :lcd %:h<CR>
" Resize window using <ctrl> arrow keys
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
map <leader>j <Plug>(easymotion-s)
" Saner search n & N
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
" Changes the pwd and opens the VCS root
nnoremap <leader>e :tcd %:h<CR> :NERDTreeToggleVCS<CR>
" Clear search highlights
nnoremap <esc> :nohlsearch<CR><esc>
inoremap <esc> :nohlsearch<CR><esc>
" <ctrl-q> to save everything and quit Neovim
nnoremap <C-q> :wqa<CR>
@@ -65,3 +86,21 @@ vnoremap <C-q> :wqa<CR>
nnoremap <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
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>