diff --git a/.gitignore b/.gitignore index e0565af..f54f7dd 100644 --- a/.gitignore +++ b/.gitignore @@ -92,3 +92,7 @@ dist-ssr **/contents/images **/contents/fonts *kpluginindex.json + +*backup +*undo +*sessions diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua index 138fa47..9349672 100644 --- a/common/.config/nvim/init.lua +++ b/common/.config/nvim/init.lua @@ -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") - diff --git a/common/.config/nvim/lua/configs/autocommands.lua b/common/.config/nvim/lua/configs/autocommands.lua index 2a11c56..ffd4e95 100644 --- a/common/.config/nvim/lua/configs/autocommands.lua +++ b/common/.config/nvim/lua/configs/autocommands.lua @@ -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 = '*', }) - diff --git a/common/.config/nvim/lua/configs/configs.lua b/common/.config/nvim/lua/configs/configs.lua index 0ea12f3..54ec36a 100644 --- a/common/.config/nvim/lua/configs/configs.lua +++ b/common/.config/nvim/lua/configs/configs.lua @@ -1,3 +1,2 @@ vim.opt.undodir = vim.fn.stdpath("config") .. "/undo" vim.opt.backupdir = vim.fn.stdpath("config") .. "/backup/" - diff --git a/common/.config/nvim/lua/configs/keymaps.lua b/common/.config/nvim/lua/configs/keymaps.lua index 81f9304..3b7390c 100644 --- a/common/.config/nvim/lua/configs/keymaps.lua +++ b/common/.config/nvim/lua/configs/keymaps.lua @@ -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 j (easymotion-s) diff --git a/common/.config/nvim/lua/plugins/coding-highlighting.lua b/common/.config/nvim/lua/plugins/coding-highlighting.lua index 0b6e44f..e46b968 100644 --- a/common/.config/nvim/lua/plugins/coding-highlighting.lua +++ b/common/.config/nvim/lua/plugins/coding-highlighting.lua @@ -11,9 +11,9 @@ return { incremental_selection = { enable = true, keymaps = { - init_selection = "", - node_incremental = "", - scope_incremental = "", + init_selection = "", + node_incremental = "", + scope_incremental = "", node_decremental = "", } } diff --git a/common/.config/nvim/lua/plugins/coding-lsp.lua b/common/.config/nvim/lua/plugins/coding-lsp.lua index 497f322..e9f4551 100644 --- a/common/.config/nvim/lua/plugins/coding-lsp.lua +++ b/common/.config/nvim/lua/plugins/coding-lsp.lua @@ -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({ - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), - [""] = cmp.mapping.complete(), - [""] = cmp.mapping.abort(), - [""] = 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", "gd", vim.lsp.buf.definition, {}) - vim.keymap.set("n", "gr", vim.lsp.buf.references, {}) - - vim.keymap.set("n", "rr", vim.lsp.buf.rename, {}) - vim.keymap.set("n", "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", "da", vim.lsp.buf.code_action, {}) - vim.keymap.set('n', 'do', vim.diagnostic.open_float) - vim.keymap.set('n', 'dq', vim.diagnostic.setloclist) - end + vim.keymap.set("n", "ll", function () + lint.try_lint() + end, { desc = "Lint current file" }) + end, }, } diff --git a/common/.config/nvim/lua/plugins/neo-tree.lua b/common/.config/nvim/lua/plugins/neo-tree.lua index 5b5f4b8..f7d46f2 100644 --- a/common/.config/nvim/lua/plugins/neo-tree.lua +++ b/common/.config/nvim/lua/plugins/neo-tree.lua @@ -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", "e", ":Neotree filesystem toggle") - 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", "e", ":Neotree filesystem toggle") + end, + }, } diff --git a/common/.ideavimrc b/common/.ideavimrc index 347d761..b905358 100644 --- a/common/.ideavimrc +++ b/common/.ideavimrc @@ -9,6 +9,10 @@ source ~/.vim/configs.vim source ~/.vim/key_maps.vim +" Because :noh does not work in Jetbrains +nnoremap +inoremap + " Set Tabs to 4 characters set expandtab set tabstop=4 diff --git a/common/.vim/configs.vim b/common/.vim/configs.vim index 52a4867..2c2cda7 100644 --- a/common/.vim/configs.vim +++ b/common/.vim/configs.vim @@ -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 diff --git a/common/.vim/key_maps.vim b/common/.vim/key_maps.vim index db1acbd..505675f 100644 --- a/common/.vim/key_maps.vim +++ b/common/.vim/key_maps.vim @@ -36,28 +36,49 @@ nnoremap N Nzzzv vnoremap J :m '>+1gv=gv vnoremap K :m '<-2gv=gv +" Better indenting +vnoremap < >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 +" Better Up/Down +nnoremap j gj +xnoremap j gj +nnoremap k gk +xnoremap k gk + " Better window/split navigation map j map k map h map l -" Clear searches -nnoremap / :call clearmatches():noh +" Navigate buffers +nnoremap :bnext +nnoremap :bprevious -" Changes the pwd to the opened file's directory -nnoremap cd :lcd %:h +" Resize window using arrow keys +nnoremap :resize +2 +nnoremap :resize -2 +nnoremap :vertical resize -2 +nnoremap :vertical resize +2 -" Map easymotion Plugin to j -map j (easymotion-s) +" Saner search n & N +nnoremap n 'Nn'[v:searchforward] +xnoremap n 'Nn'[v:searchforward] +onoremap n 'Nn'[v:searchforward] +nnoremap N 'nN'[v:searchforward] +xnoremap N 'nN'[v:searchforward] +onoremap N 'nN'[v:searchforward] -" Map nerdtree to e -" Changes the pwd and opens the VCS root -nnoremap e :tcd %:h :NERDTreeToggleVCS +" Clear search highlights +nnoremap :nohlsearch +inoremap :nohlsearch " to save everything and quit Neovim nnoremap :wqa @@ -65,3 +86,21 @@ vnoremap :wqa nnoremap :wa vnoremap :wa +" Move cursor in insert mode +inoremap ^i +inoremap +inoremap +inoremap +inoremap +inoremap + +" Copy entire content of the current buffer +nnoremap :%y+ + +" Clear search, diff update and redraw +nnoremap / :nohlsearch:diffupdate:normal! + +" Changes the pwd to the opened file's directory +nnoremap cd :lcd %:h + +map j (easymotion-s) diff --git a/common/.vim/vimrc b/common/.vim/vimrc index bf4c38e..f46b967 100644 --- a/common/.vim/vimrc +++ b/common/.vim/vimrc @@ -33,3 +33,9 @@ autocmd! bufwritepost $VIMRC source % " Save inside vim config directory set undodir=$VIMDIR/undo// +" Map easymotion Plugin to j +map j (easymotion-s) + +" Map nerdtree to e +" Changes the pwd and opens the VCS root +nnoremap e :tcd %:h :NERDTreeToggleVCS