Advertisement
VladNitu

nvim init lua Vlad

Jun 4th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.11 KB | None | 0 0
  1. --[[
  2.  
  3. =====================================================================
  4. ==================== READ THIS BEFORE CONTINUING ====================
  5. =====================================================================
  6.  
  7. Kickstart.nvim is *not* a distribution.
  8.  
  9. Kickstart.nvim is a template for your own configuration.
  10. The goal is that you can read every line of code, top-to-bottom, and understand
  11. what your configuration is doing.
  12.  
  13. Once you've done that, you should start exploring, configuring and tinkering to
  14. explore Neovim!
  15.  
  16. If you don't know anything about Lua, I recommend taking some time to read through
  17. a guide. One possible example:
  18. - https://learnxinyminutes.com/docs/lua/
  19.  
  20. And then you can explore or search through `:help lua-guide`
  21.  
  22.  
  23. Kickstart Guide:
  24.  
  25. I have left several `:help X` comments throughout the init.lua
  26. You should run that command and read that help section for more information.
  27.  
  28. In addition, I have some `NOTE:` items throughout the file.
  29. These are for you, the reader to help understand what is happening. Feel free to delete
  30. them once you know what you're doing, but they should serve as a guide for when you
  31. are first encountering a few different constructs in your nvim config.
  32.  
  33. I hope you enjoy your Neovim journey,
  34. - TJ
  35.  
  36. P.S. You can delete this when you're done too. It's your config now :)
  37. --]]
  38. -- Set <space> as the leader key
  39. -- See `:help mapleader`
  40. -- NOTE: Must happen before plugins are required (otherwise wrong leader will be used)
  41. vim.g.mapleader = ' '
  42. vim.g.maplocalleader = ' '
  43. vim.wo.relativenumber = true
  44.  
  45. vim.cmd('autocmd FileType * setlocal expandtab')
  46. vim.cmd('autocmd FileType * setlocal shiftwidth=2')
  47. vim.cmd('autocmd FileType * setlocal softtabstop=2')
  48.  
  49.  
  50.  
  51. -- Install package manager
  52. -- https://github.com/folke/lazy.nvim
  53. -- `:help lazy.nvim.txt` for more info
  54. local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
  55. if not vim.loop.fs_stat(lazypath) then
  56. vim.fn.system {
  57. 'git',
  58. 'clone',
  59. '--filter=blob:none',
  60. 'https://github.com/folke/lazy.nvim.git',
  61. '--branch=stable', -- latest stable release
  62. lazypath,
  63. }
  64. end
  65. vim.opt.rtp:prepend(lazypath)
  66.  
  67. -- NOTE: Here is where you install your plugins.
  68. -- You can configure plugins using the `config` key.
  69. --
  70. -- You can also configure plugins after the setup call,
  71. -- as they will be available in your neovim runtime.
  72. require('lazy').setup({
  73. -- NOTE: First, some plugins that don't require any configuration
  74. -- Mongo neovim
  75. { 'jrop/mongo.nvim' },
  76.  
  77. -- markdown preview
  78. {
  79. "iamcco/markdown-preview.nvim",
  80. config = function()
  81. vim.fn["mkdp#util#install"]()
  82. end,
  83. },
  84. -- tmux vim
  85. { "christoomey/vim-tmux-navigator" },
  86.  
  87. -- markdown support
  88. { "godlygeek/tabular" }, -- required by vim-markdown
  89. { "plasticboy/vim-markdown" },
  90.  
  91. -- Git related plugins
  92. 'tpope/vim-fugitive',
  93. 'tpope/vim-rhubarb',
  94.  
  95. -- Detect tabstop and shiftwidth automatically
  96. 'tpope/vim-sleuth',
  97.  
  98. -- NOTE: This is where your plugins related to LSP can be installed.
  99. -- The configuration is done below. Search for lspconfig to find it below.
  100. {
  101. -- LSP Configuration & Plugins
  102. 'neovim/nvim-lspconfig',
  103. dependencies = {
  104. -- Automatically install LSPs to stdpath for neovim
  105. { 'williamboman/mason.nvim', config = true },
  106. 'williamboman/mason-lspconfig.nvim',
  107.  
  108. -- Useful status updates for LSP
  109. -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
  110. -- [LEGACY] { 'j-hui/fidget.nvim', opts = {} },
  111.  
  112. -- Additional lua configuration, makes nvim stuff amazing!
  113. 'folke/neodev.nvim',
  114. },
  115. },
  116.  
  117. {
  118. -- Autocompletion
  119. 'hrsh7th/nvim-cmp',
  120. dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' },
  121. },
  122.  
  123. -- Useful plugin to show you pending keybinds.
  124. { 'folke/which-key.nvim', opts = {} },
  125. {
  126. -- Adds git releated signs to the gutter, as well as utilities for managing changes
  127. 'lewis6991/gitsigns.nvim',
  128. opts = {
  129. -- See `:help gitsigns.txt`
  130. signs = {
  131. add = { text = '+' },
  132. change = { text = '~' },
  133. delete = { text = '_' },
  134. topdelete = { text = '‾' },
  135. changedelete = { text = '~' },
  136. },
  137. },
  138. },
  139.  
  140. {
  141. -- Theme inspired by Atom
  142. 'rebelot/kanagawa.nvim',
  143. priority = 1000,
  144. config = function()
  145. vim.cmd.colorscheme 'kanagawa-wave'
  146. end,
  147. },
  148.  
  149.  
  150. {
  151. -- Set lualine as statusline
  152. 'nvim-lualine/lualine.nvim',
  153. -- See `:help lualine.txt`
  154. opts = {
  155. options = {
  156. icons_enabled = false,
  157. theme = 'onedark',
  158. component_separators = '|',
  159. section_separators = '',
  160. },
  161. },
  162. },
  163.  
  164. {
  165. -- Add indentation guides even on blank lines
  166. 'lukas-reineke/indent-blankline.nvim',
  167. -- Enable `lukas-reineke/indent-blankline.nvim`
  168. -- See `:help indent_blankline.txt`
  169. opts = {
  170. char = '┊',
  171. show_trailing_blankline_indent = false,
  172. },
  173. },
  174.  
  175. -- "gc" to comment visual regions/lines
  176. { 'numToStr/Comment.nvim', opts = {} },
  177.  
  178. -- Fuzzy Finder (files, lsp, etc)
  179. { 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } },
  180.  
  181. -- Fuzzy Finder Algorithm which requires local dependencies to be built.
  182. -- Only load if `make` is available. Make sure you have the system
  183. -- requirements installed.
  184. {
  185. 'nvim-telescope/telescope-fzf-native.nvim',
  186. -- NOTE: If you are having trouble with this installation,
  187. -- refer to the README for telescope-fzf-native for more instructions.
  188. build = 'make',
  189. cond = function()
  190. return vim.fn.executable 'make' == 1
  191. end,
  192. },
  193.  
  194. {
  195. -- Highlight, edit, and navigate code
  196. 'nvim-treesitter/nvim-treesitter',
  197. dependencies = {
  198. 'nvim-treesitter/nvim-treesitter-textobjects',
  199. },
  200. build = ":TSUpdate",
  201. },
  202.  
  203. -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
  204. -- These are some example plugins that I've included in the kickstart repository.
  205. -- Uncomment any of the lines below to enable them.
  206. -- require 'kickstart.plugins.autoformat',
  207. require 'kickstart.plugins.debug',
  208.  
  209. -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
  210. -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
  211. -- up-to-date with whatever is in the kickstart repo.
  212. --
  213. -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
  214. --
  215. -- An additional note is that if you only copied in the `init.lua`, you can just comment this line
  216. -- to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`.
  217. { import = 'custom.plugins' },
  218.  
  219. -- LSPSaga plugin
  220. "glepnir/lspsaga.nvim",
  221. event = "LspAttach",
  222. config = function()
  223. require("lspsaga").setup({})
  224. end,
  225. dependencies = {
  226. { "nvim-tree/nvim-web-devicons" },
  227. --Please make sure you install markdown and markdown_inline parser
  228. { "nvim-treesitter/nvim-treesitter" }
  229. },
  230.  
  231. -- DiffView plugin
  232. "sindrets/diffview.nvim",
  233.  
  234. "nvim-tree/nvim-tree.lua",
  235. "nvim-tree/nvim-web-devicons",
  236.  
  237. {
  238. "jose-elias-alvarez/null-ls.nvim",
  239. event="VeryLazy",
  240. opts = function()
  241. return require "custom.configs.null-ls"
  242. end,
  243. },
  244. -- Mason Nvim DAP -> Debugger
  245. {
  246. "williamboman/mason.nvim",
  247. "mfussenegger/nvim-dap",
  248. "jay-babu/mason-nvim-dap.nvim",
  249. },
  250. -- NVIM DAP UI for debbuger, automatically start UI when running debugger
  251. {
  252. "rcarriga/nvim-dap-ui",
  253. event = "VeryLazy",
  254. dependencies = "mfussenegger/nvim-dap",
  255. config = function()
  256. local dap = require("dap")
  257. local dapui = require("dapui")
  258. dapui.setup()
  259. dap.listeners.after.event_initialized["dapui_config"] = function()
  260. dapui.open()
  261. end
  262. dap.listeners.before.event_terminated["dapui_config"] = function()
  263. dapui.close()
  264. end
  265. dap.listeners.before.event_exited["dapui_config"] = function()
  266. dapui.close()
  267. end
  268. end
  269. },
  270.  
  271. }, {})
  272.  
  273. -- [[ Setting options ]]
  274. -- See `:help vim.o`
  275.  
  276. -- Set highlight on search
  277. vim.o.hlsearch = false
  278.  
  279. -- Make line numbers default
  280. vim.wo.number = true
  281.  
  282. -- Enable mouse mode
  283. vim.o.mouse = 'a'
  284.  
  285. -- Sync clipboard between OS and Neovim.
  286. -- Remove this option if you want your OS clipboard to remain independent.
  287. -- See `:help 'clipboard'`
  288. vim.o.clipboard = 'unnamedplus'
  289.  
  290. -- Enable break indent
  291. vim.o.breakindent = true
  292.  
  293. -- Save undo history
  294. vim.o.undofile = true
  295.  
  296. -- Case insensitive searching UNLESS /C or capital in search
  297. vim.o.ignorecase = true
  298. vim.o.smartcase = true
  299.  
  300. -- Keep signcolumn on by default
  301. vim.wo.signcolumn = 'yes'
  302.  
  303. -- Decrease update time
  304. vim.o.updatetime = 250
  305. vim.o.timeout = true
  306. vim.o.timeoutlen = 300
  307.  
  308. -- Set completeopt to have a better completion experience
  309. vim.o.completeopt = 'menuone,noselect'
  310.  
  311. -- NOTE: You should make sure your terminal supports this
  312. vim.o.termguicolors = true
  313.  
  314. -- [[ Basic Keymaps ]]
  315.  
  316. -- Keymaps for better default experience
  317. -- See `:help vim.keymap.set()`
  318. vim.keymap.set({ 'n', 'v' }, '<Space>', '<Nop>', { silent = true })
  319.  
  320. -- Remap for dealing with word wrap
  321. vim.keymap.set('n', 'k', "v:count == 0 ? 'gk' : 'k'", { expr = true, silent = true })
  322. vim.keymap.set('n', 'j', "v:count == 0 ? 'gj' : 'j'", { expr = true, silent = true })
  323.  
  324. -- [[ Highlight on yank ]]
  325. -- See `:help vim.highlight.on_yank()`
  326. local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
  327. vim.api.nvim_create_autocmd('TextYankPost', {
  328. callback = function()
  329. vim.highlight.on_yank()
  330. end,
  331. group = highlight_group,
  332. pattern = '*',
  333. })
  334.  
  335. -- [[ Configure Telescope ]]
  336. -- See `:help telescope` and `:help telescope.setup()`
  337. require('telescope').setup {
  338. defaults = {
  339. mappings = {
  340. i = {
  341. ['<C-u>'] = false,
  342. ["<C-h>"] = "which_key",
  343. ['<C-d>'] = require('telescope.actions').delete_buffer,
  344. },
  345. n = {
  346. ['<C-d>'] = require('telescope.actions').delete_buffer,
  347. },
  348. },
  349. },
  350. }
  351.  
  352. -- OR setup with some options
  353. require("nvim-tree").setup({
  354. vim.api.nvim_set_keymap('n', '<C-n>', ':NvimTreeToggle<CR>', { noremap = true, silent = true }),
  355. sort_by = "case_sensitive",
  356. view = {
  357. width = 30,
  358. },
  359. renderer = {
  360. group_empty = true,
  361. },
  362. filters = {
  363. dotfiles = true,
  364. },
  365. })
  366.  
  367.  
  368. -- Enable telescope fzf native, if installed
  369. pcall(require('telescope').load_extension, 'fzf')
  370.  
  371. -- See `:help telescope.builtin`
  372. vim.keymap.set('n', '<leader>?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' })
  373. vim.keymap.set('n', '<leader><space>', require('telescope.builtin').buffers, { desc = '[ ] Find existing buffers' })
  374. vim.keymap.set('n', '<leader>/', function()
  375. -- You can pass additional configuration to telescope to change theme, layout, etc.
  376. require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
  377. winblend = 10,
  378. previewer = false,
  379. })
  380. end, { desc = '[/] Fuzzily search in current buffer' })
  381.  
  382. vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
  383. vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
  384. vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
  385. vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
  386. vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
  387.  
  388. -- [[ Configure Treesitter ]]
  389. -- See `:help nvim-treesitter`
  390. require('nvim-treesitter.configs').setup {
  391. -- Add languages to be installed here that you want installed for treesitter
  392. ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' },
  393.  
  394. -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
  395. auto_install = false,
  396.  
  397. highlight = { enable = true },
  398. indent = { enable = true, disable = { 'python' } },
  399. incremental_selection = {
  400. enable = true,
  401. keymaps = {
  402. init_selection = '<c-space>',
  403. node_incremental = '<c-space>',
  404. scope_incremental = '<c-s>',
  405. node_decremental = '<M-space>',
  406. },
  407. },
  408. textobjects = {
  409. select = {
  410. enable = true,
  411. lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
  412. keymaps = {
  413. -- You can use the capture groups defined in textobjects.scm
  414. ['aa'] = '@parameter.outer',
  415. ['ia'] = '@parameter.inner',
  416. ['af'] = '@function.outer',
  417. ['if'] = '@function.inner',
  418. ['ac'] = '@class.outer',
  419. ['ic'] = '@class.inner',
  420. },
  421. },
  422. move = {
  423. enable = true,
  424. set_jumps = true, -- whether to set jumps in the jumplist
  425. goto_next_start = {
  426. [']m'] = '@function.outer',
  427. [']]'] = '@class.outer',
  428. },
  429. goto_next_end = {
  430. [']M'] = '@function.outer',
  431. [']['] = '@class.outer',
  432. },
  433. goto_previous_start = {
  434. ['[m'] = '@function.outer',
  435. ['[['] = '@class.outer',
  436. },
  437. goto_previous_end = {
  438. ['[M'] = '@function.outer',
  439. ['[]'] = '@class.outer',
  440. },
  441. },
  442. swap = {
  443. enable = true,
  444. swap_next = {
  445. ['<leader>a'] = '@parameter.inner',
  446. },
  447. swap_previous = {
  448. ['<leader>A'] = '@parameter.inner',
  449. },
  450. },
  451. },
  452. }
  453.  
  454. -- Diagnostic keymaps
  455. vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" })
  456. vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" })
  457. vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
  458. vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
  459.  
  460. -- LSP settings.
  461. -- This function gets run when an LSP connects to a particular buffer.
  462. local on_attach = function(_, bufnr)
  463. -- NOTE: Remember that lua is a real programming language, and as such it is possible
  464. -- to define small helper and utility functions so you don't have to repeat yourself
  465. -- many times.
  466. --
  467. -- In this case, we create a function that lets us more easily define mappings specific
  468. -- for LSP related items. It sets the mode, buffer and description for us each time.
  469. local nmap = function(keys, func, desc)
  470. if desc then
  471. desc = 'LSP: ' .. desc
  472. end
  473.  
  474. vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
  475. end
  476.  
  477. nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
  478. nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
  479.  
  480. nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
  481. nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
  482. nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
  483. nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
  484. nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
  485. nmap('<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
  486.  
  487. -- See `:help K` for why this keymap
  488. nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
  489. nmap('<C-k>', vim.lsp.buf.signature_help, 'Signature Documentation')
  490.  
  491. -- Lesser used LSP functionality
  492. nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
  493. nmap('<leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
  494. nmap('<leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
  495. nmap('<leader>wl', function()
  496. print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
  497. end, '[W]orkspace [L]ist Folders')
  498.  
  499. -- Create a command `:Format` local to the LSP buffer
  500. vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
  501. vim.lsp.buf.format()
  502. end, { desc = 'Format current buffer with LSP' })
  503. end
  504.  
  505. -- Enable the following language servers
  506. -- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
  507. --
  508. -- Add any additional override configuration in the following tables. They will be passed to
  509. -- the `settings` field of the server config. You must look up that documentation yourself.
  510. local servers = {
  511. clangd = {
  512. cmd = { "clangd", "-std=c++20" },
  513. },
  514.  
  515. hls = {
  516. cmd = { "haskell-language-server-wrapper", "--lsp"}
  517. },
  518. -- gopls = {},
  519. -- rust_analyzer = {},
  520. -- tsserver = {},
  521. -- pyright = {},
  522.  
  523. pylsp = {
  524. pylsp = {
  525. plugins = {
  526. pycodestyle = {
  527. count = true,
  528. ignore = 'E302, W291, E251, E402',
  529. maxLineLength = 120,
  530. statistics = true
  531. }
  532. }
  533. }
  534. },
  535.  
  536. lua_ls = {
  537. Lua = {
  538. workspace = { checkThirdParty = false },
  539. telemetry = { enable = false },
  540. },
  541. },
  542. }
  543.  
  544. -- Setup neovim lua configuration
  545. require('neodev').setup()
  546.  
  547. -- nvim-cmp supports additional completion capabilities, so broadcast that to servers
  548. local capabilities = vim.lsp.protocol.make_client_capabilities()
  549. capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
  550.  
  551. -- Ensure the servers above are installed
  552. local mason_lspconfig = require 'mason-lspconfig'
  553.  
  554. require('lspconfig')['hls'].setup{
  555. filetypes = {'haskell', 'lhaskell', 'cabal', 'stack' }
  556. }
  557. require'lspconfig'.hls.setup{}-- default
  558.  
  559.  
  560. mason_lspconfig.setup{
  561. ensure_installed = {"hls"},
  562. }
  563.  
  564. mason_lspconfig.setup_handlers {
  565. function(server_name)
  566. require('lspconfig')[server_name].setup {
  567. capabilities = capabilities,
  568. on_attach = on_attach,
  569. settings = servers[server_name],
  570. }
  571. end,
  572.  
  573. }
  574.  
  575. -- nvim-cmp setup
  576. local cmp = require 'cmp'
  577. local luasnip = require 'luasnip'
  578.  
  579. luasnip.config.setup {}
  580.  
  581. cmp.setup {
  582. snippet = {
  583. expand = function(args)
  584. luasnip.lsp_expand(args.body)
  585. end,
  586. },
  587. mapping = cmp.mapping.preset.insert {
  588. ['<C-d>'] = cmp.mapping.scroll_docs(-4),
  589. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  590. ['<C-Space>'] = cmp.mapping.complete {},
  591. ['<CR>'] = cmp.mapping.confirm {
  592. behavior = cmp.ConfirmBehavior.Replace,
  593. select = true,
  594. },
  595. ['<Tab>'] = cmp.mapping(function(fallback)
  596. if cmp.visible() then
  597. cmp.select_next_item()
  598. elseif luasnip.expand_or_jumpable() then
  599. luasnip.expand_or_jump()
  600. else
  601. fallback()
  602. end
  603. end, { 'i', 's' }),
  604. ['<S-Tab>'] = cmp.mapping(function(fallback)
  605. if cmp.visible() then
  606. cmp.select_prev_item()
  607. elseif luasnip.jumpable(-1) then
  608. luasnip.jump(-1)
  609. else
  610. fallback()
  611. end
  612. end, { 'i', 's' }),
  613. },
  614. sources = {
  615. { name = 'nvim_lsp' },
  616. { name = 'luasnip' },
  617. },
  618.  
  619. }
  620.  
  621.  
  622. -- The line beneath this is called `modeline`. See `:help modeline`
  623. -- vim: ts=2 sts=2 sw=2 et
  624.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement