aboutsummaryrefslogtreecommitdiff
path: root/init.lua
blob: ce9d58436eb4b5259a2b516f6e9bdb4f702863c0 (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
--------------------------------------------------------------------------------
-- lazy plugin manager
--------------------------------------------------------------------------------
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter = blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch = stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)
require("lazy").setup({
  'nvim-tree/nvim-web-devicons',
  'lewis6991/gitsigns.nvim',
  'folke/neodev.nvim',
  'neovim/nvim-lspconfig',
  'hrsh7th/cmp-nvim-lsp',
  'hrsh7th/cmp-buffer',
  'hrsh7th/cmp-path',
  'hrsh7th/cmp-cmdline',
  'hrsh7th/nvim-cmp',
  'hrsh7th/vim-vsnip',
  'octaltree/cmp-look',
  'L3MON4D3/LuaSnip',
  'saadparwaiz1/cmp_luasnip',
  'RRethy/base16-nvim',
  'nvim-treesitter/nvim-treesitter',
  'nvim-lua/popup.nvim',
  'nvim-lua/plenary.nvim',
  'nvim-telescope/telescope.nvim',
  'nvim-telescope/telescope-media-files.nvim',
  'coderonline/vim-fancy-line',
  'coderonline/vim-recently-used',
  'norcalli/nvim-colorizer.lua',
  'folke/trouble.nvim',
})

--------------------------------------------------------------------------------
-- vim options, first sourced from vimrc, then appended by Neovim specific stuff
--------------------------------------------------------------------------------
local configdir = vim.fn.fnamemodify(vim.fn.expand("$MYVIMRC"), ":p:h")
vim.cmd('source ' .. configdir .. '/vimrc')
vim.cmd.colorscheme "base16-rebecca"
-- vim.cmd.colorscheme "base16-katy"

vim.opt.encoding = 'utf-8'
vim.opt.number = true
vim.opt.number = true
vim.opt.shiftwidth = 2
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.inccommand = "nosplit" -- Neovim only: preview substitute and such things in real time 
vim.opt.termguicolors = true
vim.opt.shadafile = configdir .. "/shada.file"

-- Restore cursor position
vim.api.nvim_create_autocmd({ "BufReadPost" }, {
    callback = function() vim.cmd('silent! normal! g`"zv') end
})

vim.api.nvim_create_user_command(
  'LspFix',
  function()
    vim.lsp.buf.code_action()
  end, {}
)

if vim.fn.has("win32") then
  vim.opt.rtp:append(vim.fn.expand("$HOME\\scoop\\shims"))
end

vim.g.lsp_log_verbose = 1
vim.g.lsp_log_file = configdir .. ('/vim-lsp.log')

if vim.g.neovide then
  vim.guifont = "monospace:h11:b"
  vim.g.neovide_cursor_animation_length = 0.03
  vim.g.neovide_cursor_trail_size = 0.8
  vim.g.neovide_scroll_animation_length = 0.05
  vim.g.neovide_transparency = 0.9
  vim.g.neovide_cursor_animation_length=0
  vim.g.neovide_cursor_vfx_mode = ""
  vim.g.neovide_floating_blur_amount_x = 4.0
  vim.g.neovide_floating_blur_amount_y = 4.0
  vim.g.neovide_background_color = '#383a62'
  vim.g.neovide_scale_factor = 1.0
end

--------------------------------------------------------------------------------
-- plugin setup and options
--------------------------------------------------------------------------------
require'nvim-treesitter.configs'.setup {
  -- A list of parser names, or "all" (the five listed parsers should always be installed)
  ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
  modules = {},
  -- Install parsers synchronously (only applied to `ensure_installed`)
  sync_install = false,
  -- Automatically install missing parsers when entering buffer
  -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
  auto_install = true,
  ignore_install = { "javascript" },
  highlight = {
    enable = true,
    -- NOTE: these are the names of the parsers and not the filetype. (for example if you want to
    -- disable highlighting for the `tex` filetype, you need to include `latex` in this list as this is
    -- the name of the parser)
    -- list of language that will be disabled
    disable = function(_, buf)
      local max_filesize = 100 * 1024 -- 100 KB
      local ok, stats = pcall(vim.loop.fs_stat, vim.api.nvim_buf_get_name(buf))
      if ok and stats and stats.size > max_filesize then
        return true
      end
    end,
    -- Setting this to true will run `:h syntax` and tree-sitter at the same time.
    -- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
    -- Using this option may slow down your editor, and you may see some duplicate highlights.
    -- Instead of true it can also be a list of languages
    additional_vim_regex_highlighting = false,
  },
}

-- vim.wo.foldtext = 'v:lua.vim.treesitter.foldtext()' -- not available yet in my installation
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
vim.wo.foldlevel = 1

require('telescope').load_extension('media_files')

vim.lsp.set_log_level 'error'
if vim.fn.has 'nvim-0.5.1' == 1 then
  require('vim.lsp.log').set_format_func(vim.inspect)
end
require'nvim-web-devicons'.setup {
 color_icons = true;
 default = true;
 strict = true;
}
require('colorizer').setup()
require('gitsigns').setup()
require('trouble').setup()
require('neodev').setup()

local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})

vim.keymap.set({"i", "s"}, "<leader><Tab>", function() require('luasnip').jump(1) end, {silent = true})
vim.keymap.set({"i", "s"}, "<leader><S-Tab>", function() require('luasnip').jump(-1) end, {silent = true})

local cmp = require'cmp'
cmp.setup({
  snippet = {
    -- REQUIRED - you must specify a snippet engine
    expand = function(args)
      require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
      -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
    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 = 'luasnip' }, -- For luasnip users.
  }, {
    { 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({
    ['<Down>'] = { c = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }) },
    ['<Up>'] = { c = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) },
  }),
  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({
    ['<Down>'] = { c = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }) },
    ['<Up>'] = { c = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }) },
  }),
  sources = cmp.config.sources(
    {{ name = 'path' }},
    {{ name = 'cmdline' }}
  ),
  matching = {
    disallow_symbol_nonprefix_matching = false,
    disallow_partial_matching = false,
    disallow_fullfuzzy_matching = false,
    disallow_fuzzy_matching = false,
    disallow_partial_fuzzy_matching = false,
    disallow_prefix_unmatching = false,
  }
})

-- Set up lspconfig.
local capabilities = require('cmp_nvim_lsp').default_capabilities()

-- # Language Servers
--   https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md

-- C/C++ | clang
require('lspconfig')['clangd'].setup{capabilities = capabilities}
-- lua (but not init.lua entirely, hence why neodev)
require('lspconfig')['lua_ls'].setup { capabilities = capabilities }
-- 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 }
require'lspconfig'.jdtls.setup{}
-- bash | bash-language-server
require('lspconfig')['bashls'].setup{capabilities = capabilities}
-- ccs | vscode-css-languageserver
require('lspconfig')['cssls'].setup{capabilities = capabilities}
-- rust | rust-analyzer
require('lspconfig')['rust_analyzer'].setup{capabilities = capabilities}
-- javascript | eslint
require('lspconfig')['eslint'].setup{capabilities = capabilities}
-- javascript | typescript-language-server
require('lspconfig')['tsserver'].setup{capabilities = capabilities}
-- vimscript | vim-language-server
require('lspconfig')['vimls'].setup{capabilities = capabilities}
-- html
require('lspconfig')['html'].setup{capabilities = capabilities}
-- jsonls
require('lspconfig')['jsonls'].setup{capabilities = capabilities}
-- C/C++ | clang
require('lspconfig')['clangd'].setup{capabilities = capabilities}
-- bash | bash-language-server
require('lspconfig')['bashls'].setup{capabilities = capabilities}
-- ccs | vscode-css-languageserver
require('lspconfig')['cssls'].setup{capabilities = capabilities}
-- rust | rust-analyzer
require('lspconfig')['rust_analyzer'].setup{capabilities = capabilities}
-- javascript | eslint
require('lspconfig')['eslint'].setup{capabilities = capabilities}
-- javascript | typescript-language-server
require('lspconfig')['tsserver'].setup{capabilities = capabilities}
-- vimscript | vim-language-server
require('lspconfig')['vimls'].setup{capabilities = capabilities}
-- configure html server
require('lspconfig')["html"].setup({
  capabilities = capabilities,
  -- on_attach = on_attach,
  init_options = {
    configurationSection = { "html", "css", "javascript" },
    embeddedLanguages = {
      css = true,
      javascript = true,
    },
    provideFormatter = true,
  },
})
require('lspconfig')['pylsp'].setup{
  settings = {
    pylsp = {
      plugins = {
        pycodestyle = {
          ignore = {'W391'},
          maxLineLength = 100
        }
      }
    }
  }
}

-- vim: tabstop=2 shiftwidth=2 softtabstop=2
..