Guest User

Nvim config

a guest
Oct 16th, 2024
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.97 KB | None | 0 0
  1. --[[  ~/.config/nvim/init.lua                                               ]|--
  2.  
  3. Table of content:
  4.   [--first_configs--]: vim opts with that should be set first
  5.   [--pluging_configs--]: plugin configuration with Lazy.nvim
  6.   [--vim.opt--]: regular vim options
  7.   [--keymaps--]: custom keymaps, can also be keymaps for plugins
  8.   [--hi_groups--]: custom highlight groups / colors
  9.  
  10. [[------------------------------- Header end ---------------------------------]]
  11.  
  12. ---------- First configs ----------------------------------- |--first_configs--|
  13. -- Set leaderkey
  14. vim.g.mapleader = ' '
  15.  
  16. -- disable netrw
  17. vim.g.loaded_netrw = 1
  18. vim.g.loaded_netrwPlugin = 1
  19.  
  20. ---------- Plugins config -------------------------------- |--pluging_configs--|
  21. -- Get Lazy.nvim 󰒲
  22. local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
  23. if not (vim.uv or vim.loop).fs_stat(lazypath) then
  24.   local lazyrepo = "https://github.com/folke/lazy.nvim.git"
  25.   local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
  26.   if vim.v.shell_error ~= 0 then
  27.     vim.api.nvim_echo({
  28.       { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
  29.       { out, "WarningMsg" },
  30.       { "\nPress any key to exit..." },
  31.     }, true, {})
  32.     vim.fn.getchar()
  33.     os.exit(1)
  34.   end
  35. end
  36. vim.opt.rtp:prepend(lazypath)
  37.  
  38. -- Setup plugins with lazy.nvim 󰒲
  39. require("lazy").setup({
  40.   spec = {
  41.     {
  42.       "catppuccin/nvim",
  43.       name = "catppuccin",
  44.       priority = 1000,
  45.       opts = {
  46.         background = {
  47.             light = "latte",
  48.             dark = "macchiato",
  49.         },
  50.         show_end_of_buffer = false, -- shows the '~' on empty lines
  51.         default_integrations = true,
  52.         integrations = {
  53.           telescope = { style = "nvchad"}
  54.         }
  55.       }
  56.     },
  57.  
  58.     {
  59.       "karb94/neoscroll.nvim",
  60.       keys = {"<C-d>", "<C-u>", "<C-f>", "<C-b>", "zz", "zt", "zb"},
  61.       opts = {
  62.         hide_cursor = false,
  63.         easing = "sine"
  64.       }
  65.     },
  66.  
  67.     {
  68.       "nvim-treesitter/nvim-treesitter",
  69.       event = { "BufRead" },
  70.       build = ":TSUpdate",
  71.       config = function ()
  72.         require("nvim-treesitter.configs").setup({
  73.           -- https://github.com/nvim-treesitter/nvim-treesitter?tab=readme-ov-file#modules
  74.  
  75.           ensure_installed = { "c", "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline", "html", "javascript", "css" },
  76.           auto_install = false,
  77.  
  78.           -- List of parsers to ignore installing (or "all")
  79.           ignore_install = {},
  80.  
  81.           highlight = {
  82.             enable = true,
  83.             disable = function(lang, buf)
  84.                 local max_filesize = 500 * 1024 -- 500 KB
  85.                 local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
  86.                 if ok and stats and stats.size > max_filesize then
  87.                     return true
  88.                 end
  89.             end,
  90.             additional_vim_regex_highlighting = false,
  91.           },
  92.         })
  93.       end
  94.     },
  95.  
  96.     {
  97.       'nvim-lualine/lualine.nvim',
  98.       opts = {
  99.         options = {
  100.           theme = 'palenight',
  101.           component_separators = { left = '', right = ''},
  102.           section_separators = { left = '', right = ''},
  103.           disabled_filetypes = {
  104.             statusline = {},
  105.             winbar = {},
  106.           },
  107.           always_divide_middle = false,
  108.           globalstatus = true,
  109.           refresh = {
  110.             statusline = 1000,
  111.             tabline = 1000,
  112.             winbar = 1000,
  113.           }
  114.         },
  115.         sections = {
  116.           lualine_a = {'mode'},
  117.           lualine_b = {},
  118.           lualine_c = {'filename'},
  119.           lualine_x = {'encoding', 'fileformat', 'filetype'},
  120.           lualine_y = {'progress'},
  121.           lualine_z = {'location'}
  122.         }
  123.       }
  124.     },
  125.  
  126.     {
  127.       'nvimdev/dashboard-nvim',
  128.       event = 'VimEnter',
  129.       opts = {
  130.         theme = 'doom',
  131.         hide = {
  132.           statusline = false,
  133.           tabline = false,
  134.           winbar = false
  135.         },
  136.         config = {
  137.           header = {
  138.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  139.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  140.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  141.             '⠀⠀⡠⡪⢀⠀⠀⠀⠀⠀⠀⢈⠢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  142.             '⣠⣮⢎⢎⠠⠠⠀⠀⠀⠀⠀⢠⢣⡌⢢⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣶⣶⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  143.             '⡇⡙⣖⢕⠀⠔⠐⠀⠀⠀⠀⠸⢶⡹⢦⡅⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⡀⠀⠀⠀⠀⣀⣀⣛⣛⡃⢀⣀⡀⢀⣀⡀⠀⠀⣀⣀⣀⡀⠀',
  144.             '⢧⡕⢬⣳⡁⠐⢈⠈⢀⠀⠀⢸⢧⡹⡖⡅⠀⠀⠀⢸⣧⠖⠛⠛⠻⣦⡀⢀⡴⠚⠛⠛⢲⡄⠀⣴⠞⠛⠛⠻⣦⠈⣿⣿⡄⠀⠀⣼⣿⡏⣿⣿⡇⢸⣿⣿⡿⠿⣿⣷⣿⡿⠿⣿⣿⣆',
  145.             '⢧⡚⡵⣊⠃⡈⠀⠌⡀⠠⠀⢸⢧⡻⣝⡆⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⣾⣥⣤⣤⣤⣤⣿⢸⡇⠀⠀⠀⠀⢹⡇⠸⣿⣿⡀⣰⣿⡿⠀⣿⣿⡇⢸⣿⣿⠀⠀⢸⣿⣿⠀⠀⢸⣿⣿',
  146.             '⣎⠷⣥⢏⠀⠡⡂⠄⡁⢂⠱⣼⣞⣧⢿⡅⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⣿⠀⠀⠀⠀⠀⠀⢸⡇⠀⠀⠀⠀⢸⡇⠀⢹⣿⣧⣿⣿⠁⠀⣿⣿⡇⢸⣿⣿⠀⠀⢸⣿⣿⠀⠀⢸⣿⣿',
  147.             '⣭⣻⡜⣯⠀⠀⠐⠔⠠⣁⢂⢹⣾⣽⣿⡇⠀⠀⠀⢸⣿⠀⠀⠀⠀⣿⡇⠘⣧⣄⣀⣀⣠⡄⠈⢷⣄⣀⣀⣠⡿⠁⠀⠀⢿⣿⣿⠇⠀⠀⣿⣿⡇⢸⣿⣿⠀⠀⢸⣿⣿⠀⠀⢸⣿⣿',
  148.             '⣷⣳⢿⡵⠀⠀⠀⠈⠢⢂⢌⢾⣞⣿⣿⡇⠀⠀⠀⠈⠉⠀⠀⠀⠀⠉⠁⠀⠀⠉⠉⠉⠉⠀⠀⠀⠈⠉⠉⠉⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠉⠉⠁⠈⠉⠉⠀⠀⠈⠉⠉⠀ ⠈⠉⠉',
  149.             '⠘⢿⣟⣿⠀⠀⠀⠀⠀⠑⡢⣺⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  150.             '⠀⠀⠙⢿⠀⠀⠀⠀⠀⠀⠈⢼⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  151.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  152.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀',
  153.             '⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀'
  154.  
  155.           },
  156.           center = {
  157.             {
  158.               icon = ' ',
  159.               icon_hl = 'Normal',
  160.               desc = 'Empty File                                ',
  161.               key = 'e',
  162.               key_format = ' %s',
  163.               action = 'bd'
  164.             },
  165.             {
  166.               icon = ' ',
  167.               desc = 'Find File',
  168.               key = 'f',
  169.               key_format = ' %s',
  170.               action = 'Telescope find_files'
  171.             },
  172.             {
  173.               icon = ' ',
  174.               icon_hl = 'Normal',
  175.               desc = 'Recent Files',
  176.               key = 'r',
  177.               key_format = ' %s',
  178.               action = 'Telescope oldfiles'
  179.             },
  180.             {
  181.               icon = ' ',
  182.               icon_hl = 'DashboardCustomYellow',
  183.               desc = 'Notes Folder',
  184.               key = 'n',
  185.               key_format = ' %s',
  186.               action = 'e /home/tiago/Documents/Sync/Note/'
  187.             },
  188.             {
  189.               icon = ' ',
  190.               icon_hl = 'Normal',
  191.               desc = 'Temporary Files',
  192.               key = 't',
  193.               key_format = ' %s',
  194.               action = 'OpenTemp'
  195.             },
  196.             {
  197.               icon = ' ',
  198.               icon_hl = 'DashboardCustomGreen',
  199.               desc = 'Quit',
  200.               key = 'q',
  201.               key_format = ' %s',
  202.               action = 'q'
  203.             },
  204.             {
  205.               icon = '',
  206.               desc = '',
  207.               key = 'i',
  208.               action = 'lua vim.cmd("bd"); vim.api.nvim_feedkeys("i", "n", false)'
  209.             },
  210.           },
  211.           footer = {'Wait, what is  called !?'},
  212.         }
  213.       },
  214.       dependencies = { {'nvim-tree/nvim-web-devicons'}}
  215.     },
  216.  
  217.     {
  218.       "folke/which-key.nvim",
  219.       event = "VeryLazy",
  220.       opts = {},
  221.       keys = {
  222.         {
  223.           "<leader>?",
  224.           function()
  225.             require("which-key").show({ global = false })
  226.           end,
  227.           desc = "Local Keymaps",
  228.         }
  229.       }
  230.     },
  231.  
  232.     {
  233.       "nvim-tree/nvim-tree.lua",
  234.       keys = {
  235.         { "<leader>e", ":NvimTreeOpen<CR>", desc = "Open NvimTree" },
  236.       },
  237.       event = { "BufAdd" },
  238.       dependencies = {
  239.         "nvim-tree/nvim-web-devicons",
  240.       },
  241.       opts = {
  242.         renderer = {
  243.           icons = {
  244.             symlink_arrow = "  ",
  245.             glyphs = {
  246.               folder = {
  247.                 arrow_closed = "",
  248.                 arrow_open = "",
  249.                 default = "",
  250.                 open = "",
  251.                 empty = "",
  252.                 empty_open = "",
  253.                 symlink = "󱧮",
  254.                 symlink_open = "󱧨",
  255.               }
  256.             }
  257.           }
  258.         }
  259.       }
  260.     },
  261.  
  262.     {
  263.       "gerazov/toggle-bool.nvim",
  264.       keys = { "<leader><leader>" },
  265.       opts = {
  266.         mapping = "<leader><leader>",
  267.         additional_toggles = {
  268.           Yes = 'No',
  269.           On = 'Off',
  270.           ["0"] = "1",
  271.           Enable = 'Disable',
  272.           Enabled = 'Disabled',
  273.           First = 'Last',
  274.           Before = 'After',
  275.           Persistent = 'Ephemeral',
  276.           Allow = 'Deny',
  277.           All = 'None',
  278.         },
  279.       }
  280.     },
  281.  
  282.     { 'nvim-telescope/telescope-fzf-native.nvim', lazy = true, build = 'cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release && cmake --build build --config Release' },
  283.  
  284.     {
  285.       'nvim-telescope/telescope.nvim', branch = '0.1.x',
  286.       cmd = { "Telescope" },
  287.       dependencies = {
  288.         'nvim-lua/plenary.nvim',
  289.         'nvim-telescope/telescope-fzf-native.nvim'
  290.       },
  291.       -- TELESCOPE DOESN'T WORK WITH OPTS = {}
  292.       config = function ()
  293.         require('telescope').setup({
  294.           defaults = {
  295.             layout_config = {
  296.               prompt_position = 'top',
  297.             },
  298.             sorting_strategy = 'ascending',
  299.           }
  300.         })
  301.         require('telescope').load_extension('fzf')
  302.       end
  303.     },
  304.  
  305.     { "nvim-tree/nvim-web-devicons", opts = {} },
  306.  
  307.     {
  308.       "ggandor/leap.nvim",
  309.       event = { "BufRead", "TextChangedI" },
  310.       config = function ()
  311.         vim.keymap.set('n', 's', '<Plug>(leap)')
  312.       end
  313.     }
  314.   },
  315.  
  316.   -- Other Lazy.nvim settings --
  317.  
  318.   -- colorscheme that will be used when installing plugins.
  319.   install = { colorscheme = { "catppuccin" } },
  320.   change_detection = {
  321.     enabled = false -- doesn't seam to work anyway
  322.   },
  323. })
  324.  
  325. ---------- End of plugin config ---------------------------------- |--vim.opt--|
  326.  
  327. -- Set color scheme
  328. vim.cmd.colorscheme("catppuccin")
  329.  
  330. -- set command timeout
  331. vim.opt.timeoutlen = 400
  332.  
  333. -- set Scroll margin
  334. vim.opt.scrolloff = 6
  335.  
  336. -- Incrementally highlight characters while typing.
  337. vim.opt.incsearch = true
  338.  
  339. -- Smart case while searching
  340. vim.opt.ignorecase = true
  341. vim.opt.smartcase = true
  342.  
  343. -- Line break on words
  344. vim.opt.linebreak = true
  345.  
  346. -- Chars to use with vim list
  347. vim.opt.list = true
  348. vim.opt.listchars = { tab = '» ', trail = '·', nbsp = '␣' }
  349.  
  350. -- Vim folds
  351. vim.opt.foldmethod = "indent"
  352. vim.opt.foldlevelstart = 99
  353.  
  354. -- Indentation to 2 spaces
  355. vim.opt.tabstop=2
  356. vim.opt.shiftwidth=2
  357. vim.opt.smartindent = true
  358. vim.opt.expandtab = true -- Replaces '  '(tab) with '  '(spaces)
  359.  
  360. -- Hybrid line number
  361. vim.opt.number = true
  362. vim.opt.relativenumber = true
  363.  
  364. -- Hide mode in command line (mode shown in lualine.nvim)
  365. vim.opt.showmode = false
  366.  
  367. -- Hide command line
  368. vim.opt.cmdheight = 0
  369.  
  370. -- Auto change dir
  371. vim.opt.autochdir = true
  372.  
  373. -- Remove 'How to disable mouse' :help link in mouse popup menu
  374. vim.cmd.aunmenu('PopUp.-1-')
  375. vim.cmd.aunmenu('PopUp.How-to\\ disable\\ mouse')
  376.  
  377. ---------- Keymaps ----------------------------------------------- |--keymaps--|
  378. -- Resize splits with alt
  379. vim.api.nvim_set_keymap("n", "<A-h>", ":vertical resize -2<CR>", { noremap = true, silent = true })
  380. vim.api.nvim_set_keymap("n", "<A-l>", ":vertical resize +2<CR>", { noremap = true, silent = true })
  381. vim.api.nvim_set_keymap("n", "<A-j>", ":resize +1<CR>", { noremap = true, silent = true })
  382. vim.api.nvim_set_keymap("n", "<A-k>", ":resize -1<CR>", { noremap = true, silent = true })
  383.  
  384. -- Map <C-n> and <C-w> in :term
  385. vim.api.nvim_set_keymap("t", "<C-n>", "<C-\\><C-N>", { noremap = true, silent = true })
  386. vim.api.nvim_set_keymap("t", "<C-w>", "<C-\\><C-N><C-w>", { noremap = true, silent = true })
  387.  
  388. -- Buffers management keymaps
  389. vim.api.nvim_set_keymap("n", "<tab>", ":bn<CR>", { noremap = true, silent = true })
  390. vim.api.nvim_set_keymap("n", "<S-tab>", ":bp<CR>", { noremap = true, silent = true })
  391. vim.api.nvim_set_keymap("n", "<leader>x", ":bd<CR>", { noremap = true, silent = true, desc = 'Delete current buffer' })
  392.  
  393. -- Open / preview with Vivaldi
  394. vim.api.nvim_set_keymap("n", "<leader>p", ":silent !vivaldi '%'<CR>", { noremap = true, silent = true, desc = 'Preview with Vivaldi' })
  395.  
  396. -- leader + c -> "+ register
  397. vim.api.nvim_set_keymap("n", "<leader>c", "\"+", { noremap = true, desc = 'System clipboard register' })
  398. vim.api.nvim_set_keymap("v", "<leader>c", "\"+", { noremap = true, desc = 'System clipboard register' })
  399.  
  400. -- Telescope keymap
  401. vim.keymap.set('n', '<leader>ff', ':Telescope find_files<CR>', { silent = true, desc = 'Telescope find files' })
  402. vim.keymap.set('n', '<leader>fg', ':Telescope live_grep<CR>',  { silent = true, desc = 'Telescope live grep' })
  403. vim.keymap.set('n', '<leader>fb', ':Telescope buffers<CR>',    { silent = true, desc = 'Telescope buffers' })
  404. vim.keymap.set('n', '<leader>fh', ':Telescope help_tags<CR>',  { silent = true, desc = 'Telescope help tags' })
  405. vim.keymap.set('n', '<leader>fr', ':Telescope oldfiles<CR>',   { silent = true, desc = 'Telescope recent files' })
  406. vim.keymap.set('n', '<leader>fc', ':Telescope commands<CR>',   { silent = true, desc = 'Telescope commands' })
  407. vim.keymap.set('n', '<leader>ft', ':Telescope<CR>',            { silent = true, desc = 'Telescope' })
  408.  
  409. ---------- Custom colors --------------------------------------- |--hi_groups--|
  410.  
  411. -- Set tabline colors
  412. vim.cmd.highlight({"TabLineFill", "guifg=#697098", "guibg=#292d3e"})
  413. vim.cmd.highlight({"TabLine", "guifg=#697098", "guibg=#3e4452"})
  414. vim.cmd.highlight({"TabLineSel", "guifg=#292d3e", "guibg=#c792ea"})
  415.  
  416. -- Dashboard colors
  417. vim.cmd.highlight({"DashboardHeader", "guifg=#4dd28b"})
  418. vim.cmd("hi! link DashboardIcon DashboardDesc") -- blend icon color with text
  419. vim.cmd("hi! link DashboardKey Normal") -- blend icon color with text
  420.  
  421. -- Dashboard custom highlight groups
  422. vim.cmd.highlight({"DashboardCustomYellow", "guifg=#f0c70f"})
  423. vim.cmd.highlight({"DashboardCustomGreen", "guifg=#00c34a"})
  424.  
Advertisement
Add Comment
Please, Sign In to add comment