aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
authorMax Christian Pohle2024-09-01 02:00:46 +0200
committerMax Christian Pohle2024-09-01 02:00:46 +0200
commitfe0e677564995c25119beb8238234c24ef6e592c (patch)
treee33fef58ae6a906ae89382c82ebcb541e3f3a997 /init.lua
parent7172c36d4508510ad844fcbea1bd3bc496da809e (diff)
downloadvim-fe0e677564995c25119beb8238234c24ef6e592c.tar.bz2
vim-fe0e677564995c25119beb8238234c24ef6e592c.zip
refactored the entire config
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua242
1 files changed, 34 insertions, 208 deletions
diff --git a/init.lua b/init.lua
index 5152093..a68778d 100644
--- a/init.lua
+++ b/init.lua
@@ -1,59 +1,46 @@
1-------------------------------------------------------------------------------- 1--------------------------------------------------------------------------------
2-- lazy plugin manager 2-- vim options, first sourced from vimrc, then appended by Neovim specific stuff
3--------------------------------------------------------------------------------
4local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h")
5vim.cmd('source ' .. configdir .. '/vimrc')
6
7vim.opt.encoding='utf-8'
8vim.opt.inccommand = "nosplit" -- Neovim only: preview substitute and such things in real time
9vim.opt.shadafile = configdir .. "/shada.file"
10
11--------------------------------------------------------------------------------
12-- Bootstrap lazy.nvim
3-------------------------------------------------------------------------------- 13--------------------------------------------------------------------------------
4local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" 14local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
5if not (vim.uv or vim.loop).fs_stat(lazypath) then 15if not (vim.uv or vim.loop).fs_stat(lazypath) then
6 vim.fn.system({ 16 local lazyrepo = "https://github.com/folke/lazy.nvim.git"
7 "git", 17 local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
8 "clone", 18 if vim.v.shell_error ~= 0 then
9 "--filter = blob:none", 19 vim.api.nvim_echo({
10 "https://github.com/folke/lazy.nvim.git", 20 { "Failed to clone lazy.nvim:\n", "ErrorMsg" },
11 "--branch = stable", -- latest stable release 21 { out, "WarningMsg" },
12 lazypath, 22 { "\nPress any key to exit..." },
13 }) 23 }, true, {})
24 vim.fn.getchar()
25 os.exit(1)
26 end
14end 27end
15vim.opt.rtp:prepend(lazypath) 28vim.opt.rtp:prepend(lazypath)
16 29
17require("lazy").setup({ 30require("lazy").setup({
18 spec = { 31 spec = {
19 { import = "plugins", }, 32 { import = "plugins", },
20 'nvim-tree/nvim-web-devicons',
21 'lewis6991/gitsigns.nvim',
22 'folke/neodev.nvim',
23 -- treesitter is experimental and breaks indentation on xml, html with `=`
24 'nvim-treesitter/nvim-treesitter',
25 'nvim-lua/popup.nvim',
26 'nvim-lua/plenary.nvim',
27 'coderonline/vim-fancy-line', 33 'coderonline/vim-fancy-line',
28 'coderonline/vim-recently-used', 34 'coderonline/vim-recently-used',
29 'norcalli/nvim-colorizer.lua',
30 'folke/trouble.nvim',
31 } 35 }
32}) 36})
33 37
34--------------------------------------------------------------------------------
35-- vim options, first sourced from vimrc, then appended by Neovim specific stuff
36--------------------------------------------------------------------------------
37local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h")
38vim.cmd('source ' .. configdir .. '/vimrc')
39-- vim.cmd.colorscheme "base16-rebecca"
40-- vim.cmd.colorscheme "base16-katy"
41
42vim.opt.encoding = 'utf-8'
43vim.opt.number = true
44vim.opt.number = true
45vim.opt.shiftwidth = 2
46vim.opt.tabstop = 2
47vim.opt.softtabstop = 2
48vim.opt.inccommand = "nosplit" -- Neovim only: preview substitute and such things in real time
49vim.opt.termguicolors = true
50vim.opt.shadafile = configdir .. "/shada.file"
51
52-- Restore cursor position 38-- Restore cursor position
53vim.api.nvim_create_autocmd({ "BufReadPost" }, { 39vim.api.nvim_create_autocmd({ "BufReadPost" }, {
54 callback = function() vim.cmd('silent! normal! g`"zv') end 40 callback = function() vim.cmd('silent! normal! g`"zv') end
55}) 41})
56 42
43-- LSP says 'fix available', but there is no such command? Let us fix that:
57vim.api.nvim_create_user_command( 44vim.api.nvim_create_user_command(
58 'LspFix', 45 'LspFix',
59 function() 46 function()
@@ -61,13 +48,21 @@ vim.api.nvim_create_user_command(
61 end, {} 48 end, {}
62) 49)
63 50
51-- speaking of lsp, lets enable logging (TODO: remove if you remove
52-- `lua/cmp.lua`, but why would you?)
53vim.g.lsp_log_verbose = 1
54vim.g.lsp_log_file = configdir .. ('/vim-lsp.log')
55vim.lsp.set_log_level 'error'
56if vim.fn.has 'nvim-0.5.1' == 1 then
57 require('vim.lsp.log').set_format_func(vim.inspect)
58end
59
60-- If you need scoop for some dependencies on Windows machines this may come
61-- handy:
64if vim.fn.has("win32") then 62if vim.fn.has("win32") then
65 vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims")) 63 vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims"))
66end 64end
67 65
68vim.g.lsp_log_verbose = 1
69vim.g.lsp_log_file = configdir .. ('/vim-lsp.log')
70
71if vim.g.neovide then 66if vim.g.neovide then
72 vim.guifont = "monospace:h11:b" 67 vim.guifont = "monospace:h11:b"
73 vim.g.neovide_cursor_animation_length = 0.03 68 vim.g.neovide_cursor_animation_length = 0.03
@@ -82,173 +77,4 @@ if vim.g.neovide then
82 vim.g.neovide_scale_factor = 1.0 77 vim.g.neovide_scale_factor = 1.0
83end 78end
84 79
85--------------------------------------------------------------------------------
86-- plugin setup and options
87--------------------------------------------------------------------------------
88-- require'nvim-treesitter.configs'.setup {
89-- -- A list of parser names, or "all" (the five listed parsers should always be installed)
90-- ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
91-- modules = {},
92-- -- Install parsers synchronously (only applied to `ensure_installed`)
93-- sync_install = false,
94-- -- Automatically install missing parsers when entering buffer
95-- -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
96-- auto_install = true,
97-- ignore_install = { "javascript" },
98-- highlight = {
99-- enable = true,
100-- -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
101-- -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
102-- -- the name of the parser)
103-- -- list of language that will be disabled
104-- disable = function(_, buf)
105-- local max_filesize = 100 * 1024 -- 100 KB
106-- local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
107-- if ok and stats and stats.size > max_filesize then
108-- return true
109-- end
110-- end,
111-- -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
112-- -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
113-- -- Using this option may slow down your editor, and you may see some duplicate highlights.
114-- -- Instead of true it can also be a list of languages
115-- additional_vim_regex_highlighting = false,
116-- },
117-- }
118
119-- vim.wo.foldtext = 'v:lua.vim.treesitter.foldtext()' -- not available yet in my installation
120vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
121vim.wo.foldlevel = 1
122
123require('telescope').load_extension('media_files')
124
125vim.lsp.set_log_level 'error'
126if vim.fn.has 'nvim-0.5.1' == 1 then
127 require('vim.lsp.log').set_format_func(vim.inspect)
128end
129require'nvim-web-devicons'.setup {
130 color_icons = true;
131 default = true;
132 strict = true;
133}
134require('colorizer').setup()
135require('gitsigns').setup()
136require('trouble').setup()
137require('neodev').setup()
138
139local builtin = require('telescope.builtin')
140vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
141vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
142vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
143vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
144
145vim.keymap.set({"i", "s"}, "<leader><Tab>", function() require('luasnip').jump(1) end, {silent = true})
146vim.keymap.set({"i", "s"}, "<leader><S-Tab>", function() require('luasnip').jump(-1) end, {silent = true})
147
148local cmp = require'cmp'
149cmp.setup({
150 snippet = {
151 -- REQUIRED - you must specify a snippet engine
152 expand = function(args)
153 require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
154 -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
155 end,
156 },
157 window = {
158 completion = cmp.config.window.bordered(),
159 documentation = cmp.config.window.bordered(),
160 },
161 mapping = cmp.mapping.preset.insert({
162 ['<C-b>'] = cmp.mapping.scroll_docs(-4),
163 ['<C-f>'] = cmp.mapping.scroll_docs(4),
164 ['<C-Space>'] = cmp.mapping.complete(),
165 ['<C-e>'] = cmp.mapping.abort(),
166 ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
167 }),
168 sources = cmp.config.sources({
169 { name = 'nvim_lsp' },
170 { name = 'luasnip' }, -- For luasnip users.
171 }, {
172 { name = 'buffer' },
173 })
174})
175
176-- Set up lspconfig.
177local cmp_nvim_lsp = require "cmp_nvim_lsp"
178
179require("lspconfig").clangd.setup {
180 on_attach = on_attach,
181 capabilities = cmp_nvim_lsp.default_capabilities(),
182 cmd = {
183 "clangd",
184 "--offset-encoding=utf-16",
185 },
186}
187-- local capabilities = require('cmp_nvim_lsp').default_capabilities()
188
189-- # Language Servers
190-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
191
192-- C/C++ | clang
193-- require('lspconfig')['bitbake_language_server'].setup{}
194-- require('lspconfig')['clangd'].setup{}
195-- -- lua (but not init.lua entirely, hence why neodev)
196-- require('lspconfig')['lua_ls'].setup { }
197-- -- require('lspconfig')['java_language_server'].setup{ cmd = { "/usr/share/java/java-language-server/lang_server_linux.sh" }, root_dir = function () return vim.fn.getcwd() end }
198-- require'lspconfig'.jdtls.setup{}
199-- -- bash | bash-language-server
200-- require('lspconfig')['bashls'].setup{}
201-- -- ccs | vscode-css-languageserver
202-- require('lspconfig')['cssls'].setup{}
203-- -- rust | rust-analyzer
204-- require('lspconfig')['rust_analyzer'].setup{}
205-- -- javascript | eslint
206-- require('lspconfig')['eslint'].setup{}
207-- -- javascript | typescript-language-server
208-- require('lspconfig')['tsserver'].setup{}
209-- -- vimscript | vim-language-server
210-- require('lspconfig')['vimls'].setup{}
211-- -- html
212-- require('lspconfig')['html'].setup{}
213-- -- jsonls
214-- require('lspconfig')['jsonls'].setup{}
215-- -- C/C++ | clang
216-- require('lspconfig')['clangd'].setup{}
217-- -- bash | bash-language-server
218-- require('lspconfig')['bashls'].setup{}
219-- -- ccs | vscode-css-languageserver
220-- require('lspconfig')['cssls'].setup{}
221-- -- rust | rust-analyzer
222-- require('lspconfig')['rust_analyzer'].setup{}
223-- -- javascript | eslint
224-- require('lspconfig')['eslint'].setup{}
225-- -- javascript | typescript-language-server
226-- require('lspconfig')['tsserver'].setup{}
227-- -- vimscript | vim-language-server
228-- require('lspconfig')['vimls'].setup{}
229-- -- configure html server
230-- require('lspconfig')["html"].setup({
231-- -- on_attach = on_attach,
232-- init_options = {
233-- configurationSection = { "html", "css", "javascript" },
234-- embeddedLanguages = {
235-- css = true,
236-- javascript = true,
237-- },
238-- provideFormatter = true,
239-- },
240-- })
241-- require('lspconfig')['pylsp'].setup{
242-- settings = {
243-- pylsp = {
244-- plugins = {
245-- pycodestyle = {
246-- ignore = {'W391'},
247-- maxLineLength = 100
248-- }
249-- }
250-- }
251-- }
252-- }
253
254-- vim: tabstop=2 shiftwidth=2 softtabstop=2 80-- vim: tabstop=2 shiftwidth=2 softtabstop=2
..