فهرست منبع

Updated/fixed config

Alexey Dorokhov 1 سال پیش
والد
کامیت
7dd0faecf7
2فایلهای تغییر یافته به همراه126 افزوده شده و 94 حذف شده
  1. 5 0
      after/ftplugin/lua.lua
  2. 121 94
      init.lua

+ 5 - 0
after/ftplugin/lua.lua

@@ -0,0 +1,5 @@
+vim.bo.tabstop = 2
+vim.bo.shiftwidth = 2 
+vim.bo.expandtab = true
+vim.bo.softtabstop = 2
+

+ 121 - 94
init.lua

@@ -4,110 +4,139 @@ vim.g.loaded_netrwPlugin = 1
 
 -- package manager
 local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
-if not vim.loop.fs_stat(lazypath) then
-  vim.fn.system({
+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",
-    "https://github.com/folke/lazy.nvim.git",
     "--branch=stable", -- latest stable release
+    lazyrepo,
     lazypath,
   })
+  if vim.v.shell_error ~= 0 then
+    vim.api.nvim_echo({
+      { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
+      { out, "WarningMsg" },
+      { "\nPress any key to exit..." },
+    }, true, {})
+    vim.fn.getchar()
+    os.exit(1)
+  end
 end
 vim.opt.rtp:prepend(lazypath)
 
+-- set space key as a leader key,
+-- this has to be done before loading lazy.nvim
+vim.g.mapleader = ' '
+vim.g.maplocalleader = ' '
+
 require("lazy").setup({
-  "nvim-tree/nvim-tree.lua",
-  "nvim-tree/nvim-web-devicons",
-  "nvim-lualine/lualine.nvim",
-
-	-- color theme
-  {
-    "catppuccin/nvim",
-    name = "catppuccin",
-    priority = 1000,
-  },
+  spec = {
+    "nvim-tree/nvim-tree.lua",
+    "nvim-tree/nvim-web-devicons",
+    "nvim-lualine/lualine.nvim",
+    -- color theme
+    {
+      "catppuccin/nvim",
+      name = "catppuccin",
+      -- make sure to load this during startup
+      lazy = false,
+      -- make sure to load this beofre all other plugins
+      priority = 1000,
+      config = function()
+        vim.cmd.colorscheme("catppuccin-macchiato")
+      end,
+    },
 
-  -- LSP
-  "neovim/nvim-lspconfig", -- repo of language server configs
-  "mason-org/mason.nvim", -- package manager (needed for language server)
-  -- mason lspconfig automatically installs language servers mentioned in 
-  -- nvim-lspconfig using mason package manager.
-  "mason-org/mason-lspconfig.nvim",
-	-- configure lua language server for nvim config file
-	{
-		"folke/lazydev.nvim",
-		ft = "lua", -- only load for lua files
-	},
-
-  -- Autocompletion
-	-- TODO: look into github.com/ms-jpq/coq_nvim
-  {
-    'hrsh7th/nvim-cmp',
-    dependencies = {
-      -- Snippet Engine & its associated nvim-cmp source
-      'L3MON4D3/LuaSnip',
-      'saadparwaiz1/cmp_luasnip',
-
-      -- Adds LSP completion capabilities
-      'hrsh7th/cmp-nvim-lsp',
-
-      -- Adds a number of user-friendly snippets
-      'rafamadriz/friendly-snippets',
+    -- LSP
+    {
+      "mason-org/mason-lspconfig.nvim",
+      opts = {
+        ensure_installed = {
+          "lua_ls",
+          "rust_analyzer",
+          "pyright",
+          "clangd",
+        },
+      },
+      dependencies = {
+        { "mason-org/mason.nvim", opts = {} },
+        "neovim/nvim-lspconfig",
+      }
     },
-  },
+    -- configure lua language server for nvim config file
+    {
+      "folke/lazydev.nvim",
+      ft = "lua", -- only load for lua files
+      opts = {},
+    },
+
+    -- Autocompletion
+    -- TODO: look into github.com/ms-jpq/coq_nvim
+    {
+      'hrsh7th/nvim-cmp',
+      dependencies = {
+        -- Snippet Engine & its associated nvim-cmp source
+        'L3MON4D3/LuaSnip',
+        'saadparwaiz1/cmp_luasnip',
 
-  -- Useful plugin to show you pending keybinds.
-  "folke/which-key.nvim",
-
-  -- "gc" to comment visual regions/lines
-  "numToStr/Comment.nvim",
-
-  -- Fuzzy Finder (files, lsp, etc)
-  {
-    'nvim-telescope/telescope.nvim',
-    branch = '0.1.x',
-    dependencies = {
-      'nvim-lua/plenary.nvim',
-      -- Fuzzy Finder Algorithm which requires local dependencies to be built.
-      -- Only load if `make` is available. Make sure you have the system
-      -- requirements installed.
-      {
-        'nvim-telescope/telescope-fzf-native.nvim',
-        -- NOTE: If you are having trouble with this installation,
-        --       refer to the README for telescope-fzf-native for more instructions.
-        build = 'make',
-        cond = function()
-          return vim.fn.executable 'make' == 1
-        end,
+        -- Adds LSP completion capabilities
+        'hrsh7th/cmp-nvim-lsp',
+
+        -- Adds a number of user-friendly snippets
+        'rafamadriz/friendly-snippets',
       },
     },
-  },
 
-  -- Highlight, edit, and navigate code
-  {
-    'nvim-treesitter/nvim-treesitter',
-    dependencies = {
-      'nvim-treesitter/nvim-treesitter-textobjects',
+    -- Useful plugin to show you pending keybinds.
+    "folke/which-key.nvim",
+
+    -- "gc" to comment visual regions/lines
+    "numToStr/Comment.nvim",
+
+    -- Fuzzy Finder (files, lsp, etc)
+    {
+      'nvim-telescope/telescope.nvim',
+      branch = '0.1.x',
+      dependencies = {
+        'nvim-lua/plenary.nvim',
+        -- Fuzzy Finder Algorithm which requires local dependencies to be built.
+        -- Only load if `make` is available. Make sure you have the system
+        -- requirements installed.
+        {
+          'nvim-telescope/telescope-fzf-native.nvim',
+          -- NOTE: If you are having trouble with this installation,
+          --       refer to the README for telescope-fzf-native for more instructions.
+          build = 'make',
+          cond = function()
+            return vim.fn.executable 'make' == 1
+          end,
+        },
+      },
     },
-    build = ':TSUpdate',
-  },
 
-  -- Cut text without populating unnamed register
-  {
-    "gbprod/cutlass.nvim",
-    opts = {
-      cut_key = "<Leader>x",
-    }
-  },
-})
+    -- Highlight, edit, and navigate code
+    {
+      'nvim-treesitter/nvim-treesitter',
+      dependencies = {
+        'nvim-treesitter/nvim-treesitter-textobjects',
+      },
+      build = ':TSUpdate',
+    },
 
--- set space key as a leader key
-vim.g.mapleader = ' '
-vim.g.maplocalleader = ' '
+    -- Cut text without populating unnamed register
+    {
+      "gbprod/cutlass.nvim",
+      opts = {
+        cut_key = "<Leader>x",
+      }
+    },
+  },
 
--- set the colorscheme
-vim.cmd.colorscheme("catppuccin-macchiato")
+  -- automatically check for plugin updates
+  checker = { enabled = true },
+})
 
 -- copy to system clipboard by default
 vim.o.clipboard = "unnamedplus"
@@ -146,10 +175,6 @@ vim.api.nvim_set_keymap("n", "<Leader>w", "<C-w>", {noremap=true, silent=true})
 vim.api.nvim_set_keymap("n", "<Leader>ft", ":NvimTreeToggle<CR>", {noremap=true, silent=true})
 vim.api.nvim_set_keymap("n", "<BS>", ":NvimTreeFocus<CR>", {noremap=true, silent=true})
 
--- configure LSP
-require("mason").setup()
-require("mason-lspconfig").setup()
-
 -- configure telescope
 -- See `:help telescope` and `:help telescope.setup()`
 require('telescope').setup {
@@ -264,14 +289,16 @@ require('nvim-treesitter.configs').setup {
 }
 
 -- Diagnostic keymaps
-vim.keymap.set('n', '<Leader>dp', vim.diagnostic.goto_prev,
-	{ desc = 'Go to previous diagnostic message' })
-vim.keymap.set('n', '<Leader>dn', vim.diagnostic.goto_next,
-	{ desc = 'Go to next diagnostic message' })
+vim.keymap.set('n', '<Leader>dp',
+  function() vim.diagnostic.jump({count=-1, float=true}) end,
+  { desc = 'Go to previous diagnostic message' })
+vim.keymap.set('n', '<Leader>dn',
+  function() vim.diagnostic.jump({count=1, float=true}) end,
+  { desc = 'Go to next diagnostic message' })
 vim.keymap.set('n', '<Leader>de', vim.diagnostic.open_float,
-	{ desc = 'Open floating diagnostic message' })
+  { desc = 'Open floating diagnostic message' })
 vim.keymap.set('n', '<Leader>dl', vim.diagnostic.setloclist,
-	{ desc = 'Open diagnostics list' })
+  { desc = 'Open diagnostics list' })
 
 -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
 local capabilities = vim.lsp.protocol.make_client_capabilities()