diff options
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 271 |
1 files changed, 69 insertions, 202 deletions
@@ -1,213 +1,80 @@ | |||
1 | vim.cmd('source ~/.vim/vimrc') | 1 | -------------------------------------------------------------------------------- |
2 | 2 | -- vim options, first sourced from vimrc, then appended by Neovim specific stuff | |
3 | vim.opt.termguicolors = true | 3 | -------------------------------------------------------------------------------- |
4 | vim.opt.exrc = true | 4 | local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h") |
5 | vim.opt.foldmethod = 'syntax' | 5 | vim.cmd('source ' .. configdir .. '/vimrc') |
6 | 6 | ||
7 | if vim.fn.has("win32") then | 7 | vim.opt.encoding='utf-8' |
8 | vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims")) | 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 | ||
13 | -------------------------------------------------------------------------------- | ||
14 | local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" | ||
15 | if not (vim.uv or vim.loop).fs_stat(lazypath) then | ||
16 | local lazyrepo = "https://github.com/folke/lazy.nvim.git" | ||
17 | local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath }) | ||
18 | if vim.v.shell_error ~= 0 then | ||
19 | vim.api.nvim_echo({ | ||
20 | { "Failed to clone lazy.nvim:\n", "ErrorMsg" }, | ||
21 | { out, "WarningMsg" }, | ||
22 | { "\nPress any key to exit..." }, | ||
23 | }, true, {}) | ||
24 | vim.fn.getchar() | ||
25 | os.exit(1) | ||
26 | end | ||
9 | end | 27 | end |
28 | vim.opt.rtp:prepend(lazypath) | ||
10 | 29 | ||
11 | vim.opt.runtimepath:remove("/usr/share/vim/vimfiles") | 30 | require("lazy").setup({ |
12 | vim.keymap.set('n', '<F12>', ':Buffers<CR>') | 31 | spec = { |
13 | 32 | { import = "plugins", }, | |
14 | 33 | 'coderonline/vim-fancy-line', | |
15 | 34 | 'coderonline/vim-recently-used', | |
16 | -- vim.o.shadafile = "/tmp/shada" | ||
17 | |||
18 | -- only on Linux... | ||
19 | -- vim.o.shadafile = (os.getenv("XDG_CACHE_HOME") or | ||
20 | -- os.getenv("HOME") .. "/.cache" | ||
21 | -- ) .. "/vim.shada" | ||
22 | -- vimscript: get(environ(), "XDG_CACHE_HOME", "~/.cache")."/vim.shada" | ||
23 | -- require'man' | ||
24 | |||
25 | require'colorizer'.setup() | ||
26 | |||
27 | -- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers.. | ||
28 | require('cmp_nvim_lsp').setup{} | ||
29 | local capabilities = require('cmp_nvim_lsp').default_capabilities() | ||
30 | |||
31 | |||
32 | local cmp = require('cmp'); | ||
33 | cmp.setup({ | ||
34 | snippet = { | ||
35 | -- REQUIRED - you must specify a snippet engine | ||
36 | expand = function(args) | ||
37 | vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users. | ||
38 | -- require('luasnip').lsp_expand(args.body) -- For `luasnip` users. | ||
39 | -- require('snippy').expand_snippet(args.body) -- For `snippy` users. | ||
40 | -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users. | ||
41 | end, | ||
42 | }, | ||
43 | window = { | ||
44 | completion = cmp.config.window.bordered(), | ||
45 | documentation = cmp.config.window.bordered(), | ||
46 | }, | ||
47 | mapping = cmp.mapping.preset.insert({ | ||
48 | ['<C-b>'] = cmp.mapping.scroll_docs(-4), | ||
49 | ['<C-f>'] = cmp.mapping.scroll_docs(4), | ||
50 | ["<Tab>"] = cmp.mapping.select_next_item({behavior=cmp.SelectBehavior.Insert}), | ||
51 | ["<S-Tab>"] = cmp.mapping.select_prev_item({behavior=cmp.SelectBehavior.Insert}), | ||
52 | ['<C-Space>'] = cmp.mapping.complete(), | ||
53 | ['<C-e>'] = cmp.mapping.abort(), | ||
54 | -- ['<CR>'] = cmp.mapping.confirm({ select = false }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | ||
55 | |||
56 | ["<CR>"] = cmp.mapping.confirm({ | ||
57 | behavior = cmp.ConfirmBehavior.Replace, | ||
58 | select = true, | ||
59 | }), | ||
60 | |||
61 | ['<C-s>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. | ||
62 | }), | ||
63 | sources = cmp.config.sources({ | ||
64 | { name = 'nvim_lsp' }, | ||
65 | { name = 'vsnip' }, -- For vsnip users. | ||
66 | -- { name = 'luasnip' }, -- For luasnip users. | ||
67 | -- { name = 'ultisnips' }, -- For ultisnips users. | ||
68 | -- { name = 'snippy' }, -- For snippy users. | ||
69 | }, { | ||
70 | { name = 'buffer' }, | ||
71 | }) | ||
72 | }) | ||
73 | |||
74 | -- Set configuration for specific filetype. | ||
75 | cmp.setup.filetype('gitcommit', { | ||
76 | sources = cmp.config.sources({ | ||
77 | { name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it. | ||
78 | }, { | ||
79 | { name = 'buffer' }, | ||
80 | }) | ||
81 | }) | ||
82 | |||
83 | -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore). | ||
84 | cmp.setup.cmdline({ '/', '?' }, { | ||
85 | -- mapping = cmp.mapping.preset.cmdline(), | ||
86 | sources = { | ||
87 | { name = 'buffer' } | ||
88 | } | 35 | } |
89 | }) | 36 | }) |
90 | 37 | ||
91 | -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore). | 38 | -- Restore cursor position |
92 | cmp.setup.cmdline(':', { | 39 | vim.api.nvim_create_autocmd({ "BufReadPost" }, { |
93 | -- mapping = cmp.mapping.preset.cmdline(), | 40 | callback = function() vim.cmd('silent! normal! g`"zv') end |
94 | sources = cmp.config.sources({ | ||
95 | { name = 'cmdline' } | ||
96 | }) | ||
97 | }) | 41 | }) |
98 | 42 | ||
43 | -- LSP says 'fix available', but there is no such command? Let us fix that: | ||
44 | vim.api.nvim_create_user_command( | ||
45 | 'LspFix', | ||
46 | function() | ||
47 | vim.lsp.buf.code_action() | ||
48 | end, {} | ||
49 | ) | ||
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 | ||
99 | 59 | ||
100 | -- # Language Servers | 60 | -- If you need scoop for some dependencies on Windows machines this may come |
101 | -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md | 61 | -- handy: |
102 | 62 | if vim.fn.has("win32") then | |
103 | -- The following example advertise capabilities to `clangd`. | 63 | vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims")) |
104 | -- C/C++ | clang | 64 | end |
105 | require('lspconfig')['clangd'].setup{capabilities = capabilities} | ||
106 | |||
107 | -- bash | bash-language-server | ||
108 | require('lspconfig')['bashls'].setup{capabilities = capabilities} | ||
109 | |||
110 | -- ccs | vscode-css-languageserver | ||
111 | require('lspconfig')['cssls'].setup{capabilities = capabilities} | ||
112 | |||
113 | -- rust | rust-analyzer | ||
114 | require('lspconfig')['rust_analyzer'].setup{capabilities = capabilities} | ||
115 | |||
116 | -- javascript | eslint | ||
117 | require('lspconfig')['eslint'].setup{capabilities = capabilities} | ||
118 | |||
119 | -- javascript | typescript-language-server | ||
120 | require('lspconfig')['tsserver'].setup{capabilities = capabilities} | ||
121 | |||
122 | -- vimscript | vim-language-server | ||
123 | require('lspconfig')['vimls'].setup{capabilities = capabilities} | ||
124 | |||
125 | require('lspconfig')['html'].setup{capabilities = capabilities} | ||
126 | |||
127 | require('lspconfig')['jsonls'].setup{capabilities = capabilities} | ||
128 | |||
129 | -- C/C++ | clang | ||
130 | require('lspconfig')['clangd'].setup{capabilities = capabilities} | ||
131 | |||
132 | -- bash | bash-language-server | ||
133 | require('lspconfig')['bashls'].setup{capabilities = capabilities} | ||
134 | |||
135 | -- ccs | vscode-css-languageserver | ||
136 | require('lspconfig')['cssls'].setup{capabilities = capabilities} | ||
137 | |||
138 | -- rust | rust-analyzer | ||
139 | require('lspconfig')['rust_analyzer'].setup{capabilities = capabilities} | ||
140 | |||
141 | -- javascript | eslint | ||
142 | require('lspconfig')['eslint'].setup{capabilities = capabilities} | ||
143 | |||
144 | -- javascript | typescript-language-server | ||
145 | require('lspconfig')['tsserver'].setup{capabilities = capabilities} | ||
146 | |||
147 | -- vimscript | vim-language-server | ||
148 | require('lspconfig')['vimls'].setup{capabilities = capabilities} | ||
149 | |||
150 | require('lspconfig')['html'].setup{capabilities = capabilities} | ||
151 | |||
152 | require('lspconfig')['jsonls'].setup{capabilities = capabilities} | ||
153 | |||
154 | require('lspconfig')['pylsp'].setup{ | ||
155 | settings = { | ||
156 | pylsp = { | ||
157 | plugins = { | ||
158 | pycodestyle = { | ||
159 | ignore = {'W391'}, | ||
160 | maxLineLength = 100 | ||
161 | } | ||
162 | } | ||
163 | } | ||
164 | } | ||
165 | } | ||
166 | |||
167 | -- lua | ||
168 | require('lspconfig')['lua_ls'].setup{ | ||
169 | settings = { | ||
170 | Lua = { | ||
171 | diagnostics = { | ||
172 | globals = { 'vim', 'require', 'cmp' } | ||
173 | } | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | |||
178 | |||
179 | require'nvim-treesitter.configs'.setup { | ||
180 | -- A list of parser names, or "all" | ||
181 | ensure_installed = { "c", "bash", "javascript" }, | ||
182 | |||
183 | -- Install parsers synchronously (only applied to `ensure_installed`) | ||
184 | sync_install = false, | ||
185 | |||
186 | -- Automatically install missing parsers when entering buffer | ||
187 | -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally | ||
188 | auto_install = true, | ||
189 | |||
190 | -- List of parsers to ignore installing (for "all") | ||
191 | ignore_install = { "javascript" }, | ||
192 | |||
193 | ---- If you need to change the installation directory of the parsers (see -> Advanced Setup) | ||
194 | -- parser_install_dir = "/some/path/to/store/parsers", -- Remember to run vim.opt.runtimepath:append("/some/path/to/store/parsers")! | ||
195 | |||
196 | highlight = { | ||
197 | -- `false` will disable the whole extension | ||
198 | enable = true, | ||
199 | |||
200 | -- Setting this to true will run `:h syntax` and tree-sitter at the same time. | ||
201 | -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation). | ||
202 | -- Using this option may slow down your editor, and you may see some duplicate highlights. | ||
203 | -- Instead of true it can also be a list of languages | ||
204 | additional_vim_regex_highlighting = false, | ||
205 | }, | ||
206 | } | ||
207 | |||
208 | -- vim.wo.foldtext = 'v:lua.vim.treesitter.foldtext()' -- not available yet in my installation | ||
209 | vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()' | ||
210 | vim.wo.foldlevel = 1 | ||
211 | 65 | ||
66 | if vim.g.neovide then | ||
67 | vim.guifont = "monospace:h11:b" | ||
68 | vim.g.neovide_cursor_animation_length = 0.03 | ||
69 | vim.g.neovide_cursor_trail_size = 0.8 | ||
70 | vim.g.neovide_scroll_animation_length = 0.05 | ||
71 | vim.g.neovide_transparency = 0.9 | ||
72 | vim.g.neovide_cursor_animation_length=0 | ||
73 | vim.g.neovide_cursor_vfx_mode = "" | ||
74 | vim.g.neovide_floating_blur_amount_x = 4.0 | ||
75 | vim.g.neovide_floating_blur_amount_y = 4.0 | ||
76 | vim.g.neovide_background_color = '#383a62' | ||
77 | vim.g.neovide_scale_factor = 1.0 | ||
78 | end | ||
212 | 79 | ||
213 | -- vim: tabstop=2 shiftwidth=2 softtabstop=2 | 80 | -- vim: tabstop=2 shiftwidth=2 softtabstop=2 |