From 0c0583579cae62a01575d7bdbc556ab2c58822a3 Mon Sep 17 00:00:00 2001 From: Subhadip Ghosh Date: Fri, 13 Sep 2024 13:00:08 +0530 Subject: [PATCH] added custom config --- init.lua | 357 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 247 insertions(+), 110 deletions(-) diff --git a/init.lua b/init.lua index 13c8143d..a498cc09 100644 --- a/init.lua +++ b/init.lua @@ -90,8 +90,8 @@ P.S. You can delete this when you're done too. It's your config now! :) vim.g.mapleader = ' ' vim.g.maplocalleader = ' ' --- Set to true if you have a Nerd Font installed and selected in the terminal -vim.g.have_nerd_font = false +-- Set to true if you have a Nerd Font installed +vim.g.have_nerd_font = true -- [[ Setting options ]] -- See `:help vim.opt` @@ -102,7 +102,7 @@ vim.g.have_nerd_font = false vim.opt.number = true -- You can also add relative line numbers, to help with jumping. -- Experiment for yourself to see if you like it! --- vim.opt.relativenumber = true +vim.opt.relativenumber = true -- Enable mouse mode, can be useful for resizing splits for example! vim.opt.mouse = 'a' @@ -111,12 +111,9 @@ vim.opt.mouse = 'a' vim.opt.showmode = false -- Sync clipboard between OS and Neovim. --- Schedule the setting after `UiEnter` because it can increase startup-time. -- Remove this option if you want your OS clipboard to remain independent. -- See `:help 'clipboard'` -vim.schedule(function() - vim.opt.clipboard = 'unnamedplus' -end) +vim.opt.clipboard = 'unnamedplus' -- Enable break indent vim.opt.breakindent = true @@ -145,7 +142,7 @@ vim.opt.splitbelow = true -- Sets how neovim will display certain whitespace characters in the editor. -- See `:help 'list'` -- and `:help 'listchars'` -vim.opt.list = true +vim.opt.list = false vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' } -- Preview substitutions live, as you type! @@ -157,16 +154,27 @@ vim.opt.cursorline = true -- Minimal number of screen lines to keep above and below the cursor. vim.opt.scrolloff = 10 +vim.opt.tabstop = 4 +vim.opt.shiftwidth = 4 + +-- vim.opt.background = 'light' + -- [[ Basic Keymaps ]] -- See `:help vim.keymap.set()` --- Clear highlights on search when pressing in normal mode --- See `:help hlsearch` +-- Set highlight on search, but clear on pressing in normal mode +vim.opt.hlsearch = true vim.keymap.set('n', '', 'nohlsearch') -- Diagnostic keymaps +vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' }) +vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' }) +vim.keymap.set('n', 'e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' }) vim.keymap.set('n', 'q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' }) +vim.keymap.set('n', 'th', ':Telescope colorscheme', { desc = 'Colorschemes ' }) +vim.keymap.set('n', 'tb', ':Telescope buffers', { desc = 'Open Buffers ' }) + -- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier -- for people to discover. Otherwise, you normally need to press , which -- is not what someone will guess without a bit more experience. @@ -190,6 +198,35 @@ vim.keymap.set('n', '', '', { desc = 'Move focus to the right win vim.keymap.set('n', '', '', { desc = 'Move focus to the lower window' }) vim.keymap.set('n', '', '', { desc = 'Move focus to the upper window' }) +-- Keybindings to split windows +vim.keymap.set('n', '|', ':vsplit', { desc = 'split vertically' }) +vim.keymap.set('n', '-', ':split', { desc = 'split horizontally' }) + +-- Misc keybindings +vim.keymap.set('n', 'w', ':q', { desc = 'quit buffer' }) + +-- Height of window +vim.keymap.set('n', 'h', ':vertical resize -10', { desc = 'vertically resize low' }) +vim.keymap.set('n', 'l', ':vertical resize +10', { desc = 'vertically resize high' }) +vim.keymap.set('n', 'j', ':resize +10', { desc = 'resize more' }) +vim.keymap.set('n', 'k', ':resize +10', { desc = 'resize less' }) + +-- Nvimtree +vim.keymap.set('n', 'n', ':NvimTreeFindFileToggle', { desc = 'nvim tree' }) + +-- Git Diff View +vim.keymap.set('n', 'gd', ':DiffviewOpen', { desc = 'diff view open' }) +vim.keymap.set('n', 'gcd', ':DiffviewClose', { desc = 'diff view close' }) + +vim.keymap.set('n', 'rh', ':Gitsigns reset_hunk', { desc = 'Reset Hunk' }) + +-- Tab nav +vim.keymap.set('n', '', ':bNext', { desc = 'next buffer' }) +vim.keymap.set('n', '', ':bprevious', { desc = 'previous buffer' }) + +-- colorscheme +-- vim.cmd.colorscheme = 'flow' + -- [[ Basic Autocommands ]] -- See `:help lua-guide-autocommands` @@ -209,10 +246,7 @@ vim.api.nvim_create_autocmd('TextYankPost', { local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim' if not (vim.uv or vim.loop).fs_stat(lazypath) then local lazyrepo = 'https://github.com/folke/lazy.nvim.git' - local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } - if vim.v.shell_error ~= 0 then - error('Error cloning lazy.nvim:\n' .. out) - end + vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath } end ---@diagnostic disable-next-line: undefined-field vim.opt.rtp:prepend(lazypath) @@ -237,6 +271,11 @@ require('lazy').setup({ -- -- Use `opts = {}` to force a plugin to be loaded. -- + -- This is equivalent to: + -- require('Comment').setup({}) + + -- "gc" to comment visual regions/lines + { 'numToStr/Comment.nvim', opts = {} }, -- Here is a more advanced example where we pass configuration -- options to `gitsigns.nvim`. This is equivalent to the following Lua: @@ -253,6 +292,7 @@ require('lazy').setup({ topdelete = { text = '‾' }, changedelete = { text = '~' }, }, + current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame` }, }, @@ -401,15 +441,15 @@ require('lazy').setup({ -- See `:help telescope.builtin` local builtin = require 'telescope.builtin' - vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) - vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) - vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) - vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) - vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) - vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) - vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) - vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) - vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) + vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[F]earch [H]elp' }) + vim.keymap.set('n', 'fk', builtin.keymaps, { desc = '[F]earch [K]eymaps' }) + vim.keymap.set('n', 'ff', builtin.find_files, { desc = '[F]earch [F]iles' }) + vim.keymap.set('n', 'fs', builtin.builtin, { desc = '[F]earch [S]elect Telescope' }) + vim.keymap.set('n', 'fw', builtin.grep_string, { desc = '[F]earch current [W]ord' }) + vim.keymap.set('n', 'fg', builtin.live_grep, { desc = '[F]earch by [G]rep' }) + vim.keymap.set('n', 'fd', builtin.diagnostics, { desc = '[F]earch [D]iagnostics' }) + vim.keymap.set('n', 'fr', builtin.resume, { desc = '[F]earch [R]esume' }) + vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[F]earch Recent Files ("." for repeat)' }) vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) -- Slightly advanced example of overriding default behavior and theme @@ -437,26 +477,11 @@ require('lazy').setup({ end, }, - -- LSP Plugins - { - -- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins - -- used for completion, annotations and signatures of Neovim apis - 'folke/lazydev.nvim', - ft = 'lua', - opts = { - library = { - -- Load luvit types when the `vim.uv` word is found - { path = 'luvit-meta/library', words = { 'vim%.uv' } }, - }, - }, - }, - { 'Bilal2453/luvit-meta', lazy = true }, - { - -- Main LSP Configuration + { -- LSP Configuration & Plugins 'neovim/nvim-lspconfig', dependencies = { -- Automatically install LSPs and related tools to stdpath for Neovim - { 'williamboman/mason.nvim', config = true }, -- NOTE: Must be loaded before dependants + 'williamboman/mason.nvim', 'williamboman/mason-lspconfig.nvim', 'WhoIsSethDaniel/mason-tool-installer.nvim', @@ -464,8 +489,9 @@ require('lazy').setup({ -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})` { 'j-hui/fidget.nvim', opts = {} }, - -- Allows extra capabilities provided by nvim-cmp - 'hrsh7th/cmp-nvim-lsp', + -- `neodev` configures Lua LSP for your Neovim config, runtime and plugins + -- used for completion, annotations and signatures of Neovim apis + { 'folke/neodev.nvim', opts = {} }, }, config = function() -- Brief aside: **What is LSP?** @@ -541,7 +567,11 @@ require('lazy').setup({ -- Execute a code action, usually your cursor needs to be on top of an error -- or a suggestion from your LSP for this to activate. - map('ca', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) + map('cs', vim.lsp.buf.code_action, '[C]ode [A]ction', { 'n', 'x' }) + + -- Opens a popup that displays documentation about the word under your cursor + -- See `:help K` for why this keymap. + map('K', vim.lsp.buf.hover, 'Hover Documentation') -- WARN: This is not Goto Definition, this is Goto Declaration. -- For example, in C this would take you to the header. @@ -553,37 +583,16 @@ require('lazy').setup({ -- -- When you move your cursor, the highlights will be cleared (the second autocommand). local client = vim.lsp.get_client_by_id(event.data.client_id) - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight) then - local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false }) + if client and client.server_capabilities.documentHighlightProvider then vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { buffer = event.buf, - group = highlight_augroup, callback = vim.lsp.buf.document_highlight, }) vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { buffer = event.buf, - group = highlight_augroup, callback = vim.lsp.buf.clear_references, }) - - vim.api.nvim_create_autocmd('LspDetach', { - group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }), - callback = function(event2) - vim.lsp.buf.clear_references() - vim.api.nvim_clear_autocmds { group = 'kickstart-lsp-highlight', buffer = event2.buf } - end, - }) - end - - -- The following code creates a keymap to toggle inlay hints in your - -- code, if the language server you are using supports them - -- - -- This may be unwanted, since they displace some of your code - if client and client.supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint) then - map('th', function() - vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) - end, '[T]oggle Inlay [H]ints') end end, }) @@ -615,7 +624,9 @@ require('lazy').setup({ -- https://github.com/pmizio/typescript-tools.nvim -- -- But for many setups, the LSP (`tsserver`) will work just fine - -- tsserver = {}, + tsserver = { + auto_format = false, + }, -- lua_ls = { @@ -667,11 +678,10 @@ require('lazy').setup({ { -- Autoformat 'stevearc/conform.nvim', - event = { 'BufWritePre' }, - cmd = { 'ConformInfo' }, + lazy = false, keys = { { - 'f', + 'fm', function() require('conform').format { async = true, lsp_format = 'fallback' } end, @@ -692,6 +702,10 @@ require('lazy').setup({ else lsp_format_opt = 'fallback' end + local disable_global = { javascript = true, javascriptreact = true, typescript = true, typescriptreact = true } + if disable_global[vim.bo[bufnr].filetype] then + return + end return { timeout_ms = 500, lsp_format = lsp_format_opt, @@ -702,8 +716,12 @@ require('lazy').setup({ -- Conform can also run multiple formatters sequentially -- python = { "isort", "black" }, -- - -- You can use 'stop_after_first' to run the first available formatter from the list - -- javascript = { "prettierd", "prettier", stop_after_first = true }, + -- You can use a sub-list to tell conform to run *until* a formatter + -- is found. + javascript = { { 'prettier' } }, + typescript = { { 'prettier' } }, + javascriptreact = { { 'prettier' } }, + typescriptreact = { { 'prettier' } }, }, }, }, @@ -777,12 +795,6 @@ require('lazy').setup({ -- This will expand snippets if the LSP sent a snippet. [''] = cmp.mapping.confirm { select = true }, - -- If you prefer more traditional completion keymaps, - -- you can uncomment the following lines - --[''] = cmp.mapping.confirm { select = true }, - --[''] = cmp.mapping.select_next_item(), - --[''] = cmp.mapping.select_prev_item(), - -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display -- completions whenever it has completion options available. @@ -806,16 +818,13 @@ require('lazy').setup({ luasnip.jump(-1) end end, { 'i', 's' }), + -- select on pressing enter + [''] = cmp.mapping.confirm { select = true }, -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps }, sources = { - { - name = 'lazydev', - -- set group index to 0 to skip loading LuaLS completions as lazydev recommends it - group_index = 0, - }, { name = 'nvim_lsp' }, { name = 'luasnip' }, { name = 'path' }, @@ -824,23 +833,23 @@ require('lazy').setup({ end, }, - { -- You can easily change to a different colorscheme. - -- Change the name of the colorscheme plugin below, and then - -- change the command in the config to whatever the name of that colorscheme is. - -- - -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. - 'folke/tokyonight.nvim', - priority = 1000, -- Make sure to load this before all the other start plugins. - init = function() - -- Load the colorscheme here. - -- Like many other themes, this one has different styles, and you could load - -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. - vim.cmd.colorscheme 'tokyonight-night' - - -- You can configure highlights by doing something like: - vim.cmd.hi 'Comment gui=none' - end, - }, + -- { -- You can easily change to a different colorscheme. + -- -- Change the name of the colorscheme plugin below, and then + -- -- change the command in the config to whatever the name of that colorscheme is. + -- -- + -- -- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`. + -- 'folke/tokyonight.nvim', + -- priority = 1000, -- Make sure to load this before all the other start plugins. + -- init = function() + -- -- Load the colorscheme here. + -- -- Like many other themes, this one has different styles, and you could load + -- -- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'. + -- vim.cmd.colorscheme 'tokyonight' + -- + -- -- You can configure highlights by doing something like: + -- vim.cmd.hi 'Comment gui=none' + -- end, + -- }, -- Highlight todo, notes, etc in comments { 'folke/todo-comments.nvim', event = 'VimEnter', dependencies = { 'nvim-lua/plenary.nvim' }, opts = { signs = false } }, @@ -852,7 +861,7 @@ require('lazy').setup({ -- -- Examples: -- - va) - [V]isually select [A]round [)]paren - -- - yinq - [Y]ank [I]nside [N]ext [Q]uote + -- - yinq - [Y]ank [I]nside [N]ext [']quote -- - ci' - [C]hange [I]nside [']quote require('mini.ai').setup { n_lines = 500 } @@ -888,7 +897,7 @@ require('lazy').setup({ main = 'nvim-treesitter.configs', -- Sets main module to use for opts -- [[ Configure Treesitter ]] See `:help nvim-treesitter` opts = { - ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' }, + ensure_installed = { 'bash', 'c', 'html', 'lua', 'luadoc', 'markdown', 'vim', 'vimdoc' }, -- Autoinstall languages that are not installed auto_install = true, highlight = { @@ -900,12 +909,143 @@ require('lazy').setup({ }, indent = { enable = true, disable = { 'ruby' } }, }, - -- There are additional nvim-treesitter modules that you can use to interact - -- with nvim-treesitter. You should go explore a few and see what interests you: - -- - -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` - -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context - -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects + config = function(_, opts) + -- [[ Configure Treesitter ]] See `:help nvim-treesitter` + + ---@diagnostic disable-next-line: missing-fields + require('nvim-treesitter.configs').setup(opts) + + -- There are additional nvim-treesitter modules that you can use to interact + -- with nvim-treesitter. You should go explore a few and see what interests you: + -- + -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod` + -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context + -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects + end, + }, + { + 'tjdevries/colorbuddy.vim', + }, + { + 'deparr/tairiki.nvim', + lazy = false, + -- priority = 1001, + -- init = function() + -- vim.cmd.colorscheme 'tairiki' + -- end, + }, + { + 'nvim-tree/nvim-tree.lua', + lazy = false, + dependencies = { + 'kyazdani42/nvim-web-devicons', + }, + config = function() + require('nvim-tree').setup { + sort = { + sorter = 'case_sensitive', + }, + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = true, + }, + update_focused_file = { + enable = true, + }, + } + end, + }, + { + 'tanvirtin/vgit.nvim', + dependencies = { + 'nvim-lua/plenary.nvim', + }, + }, + { + 'oxfist/night-owl.nvim', + lazy = false, -- make sure we load this during startup if it is your main colorscheme + -- priority = 1000, -- make sure to load this before all the other start plugins + config = function() + -- load the colorscheme here + -- vim.o.background = 'dark' + -- vim.cmd.colorscheme 'night-owl' + end, + }, + { + 'xiyaowong/transparent.nvim', + lazy = false, + config = function() + require('transparent').setup { -- Optional, you don't have to run setup. + groups = { -- table: default groups + 'Normal', + 'NormalNC', + 'Comment', + 'Constant', + 'Special', + 'Identifier', + 'Statement', + 'PreProc', + 'Type', + 'Underlined', + 'Todo', + 'String', + 'Function', + 'Conditional', + 'Repeat', + 'Operator', + 'Structure', + 'LineNr', + 'NonText', + 'SignColumn', + 'CursorLine', + 'CursorLineNr', + 'StatusLine', + 'StatusLineNC', + 'EndOfBuffer', + }, + extra_groups = {}, -- table: additional groups that should be cleared + exclude_groups = {}, -- table: groups you don't want to clear + } + end, + }, + { + 'windwp/nvim-autopairs', + event = 'InsertEnter', + config = true, + }, + { + 'sindrets/diffview.nvim', + config = true, + lazy = false, + opts = { + enhanced_diff_hl = false, + view = { + merge_tool = { + layout = 'diff3_mixed', + }, + }, + }, + }, + { + 'Mofiqul/vscode.nvim', + lazy = false, + -- priority = 1001, + -- init = function() + -- vim.cmd.colorscheme 'vscode' + -- end, + }, + { + 'Yazeed1s/minimal.nvim', + lazy = false, + priority = 1001, + init = function() + vim.cmd.colorscheme 'minimal' + end, }, -- The following two comments only work if you have downloaded the kickstart repo, not just copy pasted the @@ -920,9 +1060,6 @@ require('lazy').setup({ -- require 'kickstart.plugins.debug', -- require 'kickstart.plugins.indent_line', -- require 'kickstart.plugins.lint', - -- require 'kickstart.plugins.autopairs', - -- require 'kickstart.plugins.neo-tree', - -- require 'kickstart.plugins.gitsigns', -- adds gitsigns recommend keymaps -- NOTE: The import below can automatically add your own plugins, configuration, etc from `lua/custom/plugins/*.lua` -- This is the easiest way to modularize your config.