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