summaryrefslogtreecommitdiff
path: root/.config/nvim/init.lua
blob: 9f3718dd44f88ebbbe1373756c92d1c7a7c0705d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
-- general settings
local vim = vim
vim.opt.number = true                       -- show line numbers
vim.opt.relativenumber = true               -- relative line numbers for navigation
vim.opt.clipboard:append { 'unnamedplus' }  -- use clipboard
vim.opt.mouse = "a"                         -- enable mouse support
vim.opt.updatetime = 250                    -- Faster updates (e.g., for LSP diagnostics)
vim.opt.timeoutlen = 500                    -- Shorter timeout for key sequences
vim.opt.splitright = true                   -- vsplit opens new buffer on the right side

-- tab and indentation settings
vim.opt.expandtab = true            -- tabs are converted to spaces
vim.opt.shiftwidth = 4              -- 4 spaces for indentation
vim.opt.tabstop = 4                 -- 4 spaces for tabs
vim.opt.softtabstop = 4             -- 4 spaces for tab key
vim.opt.autoindent = true           -- Copy indent from previous line
vim.opt.cindent = true
vim.opt.cino = ":0l1(0"

-- plugin preparation
vim.opt.signcolumn = "yes"                              -- LSP diagnostics
vim.opt.termguicolors = true                            -- enable true colors
vim.opt.completeopt = { "menu", "menuone", "noselect" } -- required for nvim-cmp
vim.g.mapleader = " "               -- Set leader to space
vim.g.maplocalleader = "\\"         -- Set local leader to backslash


-- keymap
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, { desc = 'Go to definition' })


-- packages 
vim.pack.add({
    -- colorscheme
    { src = 'https://github.com/sainnhe/gruvbox-material' },

    -- status line
    { src = 'https://github.com/nvim-tree/nvim-web-devicons' },
    { src = 'https://github.com/nvim-lualine/lualine.nvim' },

    -- enhance language server capabilities (i guess)
    { src = 'https://github.com/nvim-treesitter/nvim-treesitter', version = 'main' },

    -- autoconfigure language servers
    { src = 'https://github.com/neovim/nvim-lspconfig' },

    -- install language servers
    { src = 'https://github.com/mason-org/mason.nvim' },
    { src = 'https://github.com/mason-org/mason-lspconfig.nvim' },

    -- autocomplete
    { src = 'https://github.com/hrsh7th/cmp-nvim-lsp' },
    { src = 'https://github.com/hrsh7th/cmp-buffer' },
    { src = 'https://github.com/hrsh7th/cmp-path' },
    { src = 'https://github.com/hrsh7th/cmp-cmdline' },
    { src = 'https://github.com/hrsh7th/nvim-cmp' },
    { src = 'https://github.com/hrsh7th/cmp-vsnip' },
    { src = 'https://github.com/hrsh7th/vim-vsnip' },

    -- telescope
    { src = 'https://github.com/nvim-lua/plenary.nvim' },
    { src = 'https://github.com/nvim-telescope/telescope.nvim', tag = 'v0.1.9' },

    -- latex support
    { src = 'https://github.com/lervag/vimtex' },
})



-- init plugin gruvbox-material
vim.g.gruvbox_material_background             = 'hard'
vim.g.gruvbox_material_foreground             = 'material'
vim.g.gruvbox_material_enable_italic          = true
vim.g.gruvbox_material_disable_italic_comment = false
vim.g.gruvbox_material_better_performance     = 1
vim.cmd.colorscheme('gruvbox-material')


-- init plugin lualine
require('lualine').setup({
  options = {
    icons_enabled = true,
    theme = 'auto',
    component_separators = { left = '', right = ''},
    section_separators = { left = '', right = ''},
    disabled_filetypes = {
      statusline = {},
      winbar = {},
    },
    ignore_focus = {},
    always_divide_middle = true,
    always_show_tabline = true,
    globalstatus = false,
    refresh = {
      statusline = 1000,
      tabline = 1000,
      winbar = 1000,
      refresh_time = 16, -- ~60fps
      events = {
        'WinEnter',
        'BufEnter',
        'BufWritePost',
        'SessionLoadPost',
        'FileChangedShellPost',
        'VimResized',
        'Filetype',
        'CursorMoved',
        'CursorMovedI',
        'ModeChanged',
      },
    }
  },
  sections = {
    lualine_a = {'mode'},
    lualine_b = {'branch', 'diff', 'diagnostics'},
    lualine_c = {'filename'},
    lualine_x = {'encoding', 'fileformat', 'filetype'},
    lualine_y = {'progress'},
    lualine_z = {'location'}
  },
  inactive_sections = {
    lualine_a = {},
    lualine_b = {},
    lualine_c = {'filename'},
    lualine_x = {'location'},
    lualine_y = {},
    lualine_z = {}
  },
  tabline = {},
  winbar = {},
  inactive_winbar = {},
  extensions = {}
})


-- treesitter
require'nvim-treesitter'.install { 'cpp' }


-- cmp
local cmp = require("cmp")
cmp.setup({
    snippet = {
        expand = function(args)
            vim.fn["vsnip#anonymous"](args.body)
        end,
    },
    window = {
        -- completion = cmp.config.window.bordered(),
        -- documentation = cmp.config.window.bordered(),
    },
    mapping = cmp.mapping.preset.insert({
        ['<C-b>'] = cmp.mapping.scroll_docs(-4),
        ['<C-f>'] = cmp.mapping.scroll_docs(4),
        ['<C-Space>'] = cmp.mapping.complete(),
        ['<C-e>'] = cmp.mapping.abort(),
        ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
    }),
    sources = cmp.config.sources({
        { name = 'nvim_lsp' },
        { name = 'vsnip' },
    }, {
        { name = 'buffer' },
    })
})

-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline({ '/', '?' }, {
    mapping = cmp.mapping.preset.cmdline(),
    sources = {
        { name = 'buffer' }
    }
})

-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
    mapping = cmp.mapping.preset.cmdline(),
    sources = cmp.config.sources(
    {
        { name = 'path' }
    },
    {
        { name = 'cmdline' }
    }
    ),
    matching = { disallow_symbol_nonprefix_matching = false }
})


-- language server installation (via mason)
local capabilities = require('cmp_nvim_lsp').default_capabilities()
require("mason").setup()
require("mason-lspconfig").setup({
    ensure_installed = { "lua_ls", "clangd", "pyright", "djlsp" },
    automatic_installation = true,
    handlers = {
        function(server_name)
            require("lspconfig")[server_name].setup({
                capabilities = capabilities,
                -- on_attach = your_on_attach,  -- if you have one
                -- settings = {...},            -- per-server overrides go here if needed
            })
        end,
    },
    -- Optional: override specific servers if you really need something special
    -- ["rust_analyzer"] = function()
        --   require("rust-tools").setup({})
        -- end,
})


-- language server enabling
vim.lsp.enable({
    'lua_ls',
    'clangd',
    'pyright',
    'djlsp'
})



local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = 'Telescope buffers' })
vim.keymap.set('n', '<leader>fh', builtin.help_tags, { desc = 'Telescope help tags' })



-- vimtex (latex support)
require('lualine').setup({
    ft = { "tex", "bib" },
    dependencies = { "nvim-treesitter/nvim-treesitter" },
    config = function()
        vim.g.vimtex_view_method = "mupdf"
    end
})