aboutsummaryrefslogtreecommitdiffhomepage
path: root/init.lua
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-08-12 16:27:12 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-08-12 16:27:12 +0800
commit6325a81a92484830992147583d4a6e8b72f134f1 (patch)
tree7dce56763e514d91a85bbf67dc72acb5f03198a9 /init.lua
parentb728e3eb1e5be9fa50c6e3a5c480ef0b0bafe26d (diff)
Update
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua542
1 files changed, 0 insertions, 542 deletions
diff --git a/init.lua b/init.lua
deleted file mode 100644
index d2a352d..0000000
--- a/init.lua
+++ /dev/null
@@ -1,542 +0,0 @@
1--[[
2
3=====================================================================
4==================== READ THIS BEFORE CONTINUING ====================
5=====================================================================
6
7-- Kickstart.nvim is *not* a distribution.
8--
9Kickstart.nvim is a template for your own configuration.
10 The goal is that you can read every line of code, top-to-bottom, and understand
11 what your configuration is doing.
12
13 Once you've done that, you should start exploring, configuring and tinkering to
14 explore Neovim!
15
16 If you don't know anything about Lua, I recommend taking some time to read through
17 a guide. One possible example:
18 - https://learnxinyminutes.com/docs/lua/
19
20 And then you can explore or search through `:help lua-guide`
21
22
23Kickstart Guide:
24
25I have left several `:help X` comments throughout the init.lua
26You should run that command and read that help section for more information.
27
28In addition, I have some `NOTE:` items throughout the file.
29These are for you, the reader to help understand what is happening. Feel free to delete
30them once you know what you're doing, but they should serve as a guide for when you
31are first encountering a few different constructs in your nvim config.
32
33I hope you enjoy your Neovim journey,
34- TJ
35
36P.S. You can delete this when you're done too. It's your config now :)
37--]]
38-- [[ General Config ]]
39vim.cmd('source ' .. '~/.vim/vim-init/init/init-basic.vim')
40vim.cmd('source ' .. '~/.vim/vim-init/init/init-keymaps.vim')
41
42
43-- Install package manager
44-- https://github.com/folke/lazy.nvim
45-- `:help lazy.nvim.txt` for more info
46local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
47if not vim.loop.fs_stat(lazypath) then
48 vim.fn.system {
49 'git',
50 'clone',
51 '--filter=blob:none',
52 'https://github.com/folke/lazy.nvim.git',
53 '--branch=stable', -- latest stable release
54 lazypath,
55 }
56end
57vim.opt.runtimepath:prepend(lazypath)
58
59-- NOTE: Here is where you install your plugins.
60-- You can configure plugins using the `config` key.
61--
62-- You can also configure plugins after the setup call,
63-- as they will be available in your neovim runtime.
64require('lazy').setup({
65 -- NOTE: First, some plugins that don't require any configuration
66
67 -- Detect tabstop and shiftwidth automatically
68 'tpope/vim-sleuth',
69
70 -- Use sudo in command mode
71 'lambdalisue/suda.vim',
72
73 -- For beancount
74 'nathangrigg/vim-beancount',
75
76 -- NOTE: This is where your plugins related to LSP can be installed.
77 -- The configuration is done below. Search for lspconfig to find it below.
78 {
79 -- LSP Configuration & Plugins
80 'neovim/nvim-lspconfig',
81 dependencies = {
82 -- Automatically install LSPs to stdpath for neovim
83 { 'williamboman/mason.nvim', config = true },
84 'williamboman/mason-lspconfig.nvim',
85
86 -- Useful status updates for LSP
87 -- NOTE: `opts = {}` is the same as calling `require('fidget').setup({})`
88 { 'j-hui/fidget.nvim', opts = {} },
89
90 -- Additional lua configuration, makes nvim stuff amazing!
91 'folke/neodev.nvim',
92 },
93 },
94
95 {
96 -- Autocompletion
97 'hrsh7th/nvim-cmp',
98 dependencies = { 'hrsh7th/cmp-nvim-lsp', 'L3MON4D3/LuaSnip', 'saadparwaiz1/cmp_luasnip' },
99 },
100
101 -- Useful plugin to show you pending keybinds.
102 {
103 'folke/which-key.nvim',
104 opts = {
105 triggers_blacklist = {
106 n = { ":" }, -- ignore : in normal mode
107 },
108 }
109 },
110 {
111 -- Adds git releated signs to the gutter, as well as utilities for managing changes
112 'lewis6991/gitsigns.nvim',
113 opts = {
114 -- See `:help gitsigns.txt`
115 signs = {
116 add = { text = '+' },
117 change = { text = '~' },
118 delete = { text = '_' },
119 topdelete = { text = '‾' },
120 changedelete = { text = '~' },
121 },
122 },
123 },
124
125 {
126 -- Set lualine as statusline
127 'nvim-lualine/lualine.nvim',
128 -- See `:help lualine.txt`
129 opts = {
130 options = {
131 icons_enabled = false,
132 component_separators = '|',
133 section_separators = { left = '', right = '' },
134 },
135 },
136 },
137
138 {
139 -- Add indentation guides even on blank lines
140 'lukas-reineke/indent-blankline.nvim',
141 -- Enable `lukas-reineke/indent-blankline.nvim`
142 -- See `:help indent_blankline.txt`
143 opts = {
144 char = '┊',
145 show_trailing_blankline_indent = true,
146 },
147 },
148
149 -- "gc" to comment visual regions/lines
150 {
151 'numToStr/Comment.nvim',
152 opts = {
153 opleader = {
154 ---Line-comment keymap
155 line = '<C-_>',
156 ---Block-comment keymap
157 block = 'gb',
158 },
159 }
160 },
161
162 -- Fuzzy Finder (files, lsp, etc)
163 { 'nvim-telescope/telescope.nvim', version = '*', dependencies = { 'nvim-lua/plenary.nvim' } },
164
165 -- Fuzzy Finder Algorithm which requires local dependencies to be built.
166 -- Only load if `make` is available. Make sure you have the system
167 -- requirements installed.
168 {
169 'nvim-telescope/telescope-fzf-native.nvim',
170 -- NOTE: If you are having trouble with this installation,
171 -- refer to the README for telescope-fzf-native for more instructions.
172 build = 'make',
173 cond = function()
174 return vim.fn.executable 'make' == 1
175 end,
176 },
177
178 {
179 -- Highlight, edit, and navigate code
180 'nvim-treesitter/nvim-treesitter',
181 dependencies = {
182 'nvim-treesitter/nvim-treesitter-textobjects',
183 },
184 build = ":TSUpdate",
185 },
186
187 -- NOTE: Next Step on Your Neovim Journey: Add/Configure additional "plugins" for kickstart
188 -- These are some example plugins that I've included in the kickstart repository.
189 -- Uncomment any of the lines below to enable them.
190 -- require 'kickstart.plugins.autoformat',
191 -- require 'kickstart.plugins.debug',
192
193 'machakann/vim-sandwich',
194 -- NOTE: The import below automatically adds your own plugins, configuration, etc from `lua/custom/plugins/*.lua`
195 -- You can use this folder to prevent any conflicts with this init.lua if you're interested in keeping
196 -- up-to-date with whatever is in the kickstart repo.
197 --
198 -- For additional information see: https://github.com/folke/lazy.nvim#-structuring-your-plugins
199 --
200 -- An additional note is that if you only copied in the `init.lua`, you can just comment this line
201 -- to get rid of the warning telling you that there are not plugins in `lua/custom/plugins/`.
202 --{ import = 'custom.plugins' },
203}, {})
204
205
206-- [[ Setting options ]]
207-- See `:help vim.o`
208
209-- Enable mouse mode
210-- vim.o.mouse = 'a'
211
212-- Sync clipboard between OS and Neovim.
213-- Remove this option if you want your OS clipboard to remain independent.
214-- See `:help 'clipboard'`
215-- vim.o.clipboard = 'unnamedplus'
216
217-- Enable break indent
218vim.o.breakindent = true
219
220-- Keep signcolumn on by default
221vim.wo.signcolumn = 'yes'
222
223-- Decrease update time
224vim.o.updatetime = 250
225vim.o.timeout = true
226vim.o.timeoutlen = 300
227
228-- Set completeopt to have a better completion experience
229vim.o.completeopt = 'menuone,noselect'
230
231-- NOTE: You should make sure your terminal supports this
232-- vim.o.termguicolors = true
233
234
235-- [[ Basic Keymaps ]]
236
237-- Keymaps for better default experience
238-- See `:help vim.keymap.set()`
239
240-- Use suda.vim to run sudo, or terminal prompt fails
241-- See more details at https://github.com/neovim/neovim/issues/1716
242vim.cmd("command! W execute 'SudaWrite %'")
243
244
245-- [[ Highlight on yank ]]
246-- See `:help vim.highlight.on_yank()`
247local highlight_group = vim.api.nvim_create_augroup('YankHighlight', { clear = true })
248vim.api.nvim_create_autocmd('TextYankPost', {
249 callback = function()
250 vim.highlight.on_yank()
251 end,
252 group = highlight_group,
253 pattern = '*',
254})
255
256
257-- [[ Configure lualine ]]
258-- Change the background of lualine_b section for normal mode
259local custom_wombat = require 'lualine.themes.wombat'
260custom_wombat.normal.b.bg = '#a8a8a8'
261custom_wombat.normal.b.fg = '#444444'
262require('lualine').setup {
263 options = { theme = custom_wombat },
264}
265
266
267-- [[ Configure Telescope ]]
268-- See `:help telescope` and `:help telescope.setup()`
269require('telescope').setup {
270 defaults = {
271 mappings = {
272 i = {
273 ['<C-u>'] = false,
274 ['<C-d>'] = false,
275 ["<c-j>"] = "move_selection_next",
276 ["<c-k>"] = "move_selection_previous",
277 },
278 },
279 layout_config = {
280 vertical = { height = 0.8 }
281 -- other layout configuration here
282 },
283 },
284 pickers = {
285 buffers = {
286 show_all_buffers = true,
287 sort_lastused = true,
288 theme = "dropdown",
289 previewer = false,
290 mappings = {
291 i = {
292 ["<c-d>"] = "delete_buffer",
293 },
294 n = {
295 ["<c-d>"] = "delete_buffer",
296 }
297 }
298 }
299 }
300}
301
302-- Enable telescope fzf native, if installed
303pcall(require('telescope').load_extension, 'fzf')
304
305-- See `:help telescope.builtin`
306vim.keymap.set('n', '<leader>f', require('telescope.builtin').oldfiles, { desc = '[f] Find recently opened files' })
307vim.keymap.set('n', '<leader>q', require('telescope.builtin').buffers, { desc = '[q] Find existing buffers' })
308vim.keymap.set('n', '<leader>/', function()
309 -- You can pass additional configuration to telescope to change theme, layout, etc.
310 require('telescope.builtin').current_buffer_fuzzy_find(require('telescope.themes').get_dropdown {
311 -- winblend = 10,
312 previewer = false,
313 })
314end, { desc = '[/] Fuzzily search in current buffer' })
315
316vim.keymap.set('n', '<leader>gf', require('telescope.builtin').git_files, { desc = 'Search [G]it [F]iles' })
317vim.keymap.set('n', '<leader>sf', require('telescope.builtin').find_files, { desc = '[S]earch [F]iles' })
318vim.keymap.set('n', '<leader>sh', require('telescope.builtin').help_tags, { desc = '[S]earch [H]elp' })
319vim.keymap.set('n', '<leader>sw', require('telescope.builtin').grep_string, { desc = '[S]earch current [W]ord' })
320vim.keymap.set('n', '<leader>sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' })
321vim.keymap.set('n', '<leader>sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' })
322
323
324-- [[ Configure Treesitter ]]
325-- See `:help nvim-treesitter`
326require('nvim-treesitter.configs').setup {
327 -- Add languages to be installed here that you want installed for treesitter
328 ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'typescript', 'vimdoc', 'vim' },
329
330 -- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
331 auto_install = false,
332
333 highlight = { enable = true },
334 indent = { enable = true, disable = { 'python' } },
335 incremental_selection = {
336 enable = true,
337 keymaps = {
338 init_selection = '<c-space>',
339 node_incremental = '<c-space>',
340 scope_incremental = '<c-s>',
341 node_decremental = '<M-space>',
342 },
343 },
344 textobjects = {
345 select = {
346 enable = true,
347 lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
348 keymaps = {
349 -- You can use the capture groups defined in textobjects.scm
350 ['aa'] = '@parameter.outer',
351 ['ia'] = '@parameter.inner',
352 ['af'] = '@function.outer',
353 ['if'] = '@function.inner',
354 ['ac'] = '@class.outer',
355 ['ic'] = '@class.inner',
356 },
357 },
358 move = {
359 enable = true,
360 set_jumps = true, -- whether to set jumps in the jumplist
361 goto_next_start = {
362 [']m'] = '@function.outer',
363 [']]'] = '@class.outer',
364 },
365 goto_next_end = {
366 [']M'] = '@function.outer',
367 [']['] = '@class.outer',
368 },
369 goto_previous_start = {
370 ['[m'] = '@function.outer',
371 ['[['] = '@class.outer',
372 },
373 goto_previous_end = {
374 ['[M'] = '@function.outer',
375 ['[]'] = '@class.outer',
376 },
377 },
378 swap = {
379 enable = true,
380 swap_next = {
381 ['<leader>a'] = '@parameter.inner',
382 },
383 swap_previous = {
384 ['<leader>A'] = '@parameter.inner',
385 },
386 },
387 },
388}
389
390-- Diagnostic keymaps
391vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = "Go to previous diagnostic message" })
392vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = "Go to next diagnostic message" })
393vim.keymap.set('n', '<leader>E', vim.diagnostic.open_float, { desc = "Open floating diagnostic message" })
394vim.keymap.set('n', '<leader>Q', vim.diagnostic.setloclist, { desc = "Open diagnostics list" })
395
396-- LSP settings.
397-- This function gets run when an LSP connects to a particular buffer.
398local on_attach = function(_, bufnr)
399 -- NOTE: Remember that lua is a real programming language, and as such it is possible
400 -- to define small helper and utility functions so you don't have to repeat yourself
401 -- many times.
402 --
403 -- In this case, we create a function that lets us more easily define mappings specific
404 -- for LSP related items. It sets the mode, buffer and description for us each time.
405 local nmap = function(keys, func, desc)
406 if desc then
407 desc = 'LSP: ' .. desc
408 end
409
410 vim.keymap.set('n', keys, func, { buffer = bufnr, desc = desc })
411 end
412
413 nmap('<leader>rn', vim.lsp.buf.rename, '[R]e[n]ame')
414 nmap('<leader>ca', vim.lsp.buf.code_action, '[C]ode [A]ction')
415
416 nmap('gd', vim.lsp.buf.definition, '[G]oto [D]efinition')
417 nmap('gr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
418 nmap('gI', vim.lsp.buf.implementation, '[G]oto [I]mplementation')
419 nmap('<leader>D', vim.lsp.buf.type_definition, 'Type [D]efinition')
420 nmap('<leader>ds', require('telescope.builtin').lsp_document_symbols, '[D]ocument [S]ymbols')
421 nmap('<leader><leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, '[W]orkspace [S]ymbols')
422
423 -- See `:help K` for why this keymap
424 nmap('K', vim.lsp.buf.hover, 'Hover Documentation')
425 nmap('<leader>k', vim.lsp.buf.signature_help, 'Signature Documentation')
426
427 -- Lesser used LSP functionality
428 nmap('gD', vim.lsp.buf.declaration, '[G]oto [D]eclaration')
429 nmap('<leader><leader>wa', vim.lsp.buf.add_workspace_folder, '[W]orkspace [A]dd Folder')
430 nmap('<leader><leader>wr', vim.lsp.buf.remove_workspace_folder, '[W]orkspace [R]emove Folder')
431 nmap('<leader><leader>wl', function()
432 print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
433 end, '[W]orkspace [L]ist Folders')
434
435 -- Create a command `:Format` local to the LSP buffer
436 vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
437 vim.lsp.buf.format()
438 end, { desc = 'Format current buffer with LSP' })
439 nmap('<leader>F', ':Format<CR>', 'Format code')
440end
441
442-- Enable the following language servers
443-- Read Doc page for more configuration:
444-- https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md
445-- Feel free to add/remove any LSPs that you want here. They will automatically be installed.
446--
447-- Add any additional override configuration in the following tables. They will be passed to
448-- the `settings` field of the server config. You must look up that documentation yourself.
449local servers = {
450 -- clangd = {},
451 -- gopls = {},
452 bashls = {},
453 marksman = {},
454 html = {},
455 pyright = {},
456 rust_analyzer = {},
457 tsserver = {},
458 beancount = {
459 filetypes = { "beancount", "bean" },
460 },
461
462 lua_ls = {
463 Lua = {
464 workspace = { checkThirdParty = false },
465 telemetry = { enable = false },
466 },
467 },
468}
469
470-- Setup neovim lua configuration
471require('neodev').setup()
472
473-- nvim-cmp supports additional completion capabilities, so broadcast that to servers
474local capabilities = vim.lsp.protocol.make_client_capabilities()
475capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)
476
477-- Ensure the servers above are installed
478local mason_lspconfig = require 'mason-lspconfig'
479
480mason_lspconfig.setup {
481 ensure_installed = vim.tbl_keys(servers),
482}
483
484mason_lspconfig.setup_handlers {
485 function(server_name)
486 require('lspconfig')[server_name].setup {
487 capabilities = capabilities,
488 on_attach = on_attach,
489 settings = servers[server_name],
490 }
491 end,
492}
493
494-- nvim-cmp setup
495local cmp = require 'cmp'
496local luasnip = require 'luasnip'
497
498luasnip.config.setup {}
499
500cmp.setup {
501 snippet = {
502 expand = function(args)
503 luasnip.lsp_expand(args.body)
504 end,
505 },
506 mapping = cmp.mapping.preset.insert {
507 ['<C-n>'] = cmp.mapping.select_next_item(),
508 ['<C-p>'] = cmp.mapping.select_prev_item(),
509 ['<C-d>'] = cmp.mapping.scroll_docs(-4),
510 ['<C-f>'] = cmp.mapping.scroll_docs(4),
511 ['<C-Space>'] = cmp.mapping.complete {},
512 ['<CR>'] = cmp.mapping.confirm {
513 behavior = cmp.ConfirmBehavior.Replace,
514 select = true,
515 },
516 ['<Tab>'] = cmp.mapping(function(fallback)
517 if cmp.visible() then
518 cmp.select_next_item()
519 elseif luasnip.expand_or_jumpable() then
520 luasnip.expand_or_jump()
521 else
522 fallback()
523 end
524 end, { 'i', 's' }),
525 ['<S-Tab>'] = cmp.mapping(function(fallback)
526 if cmp.visible() then
527 cmp.select_prev_item()
528 elseif luasnip.jumpable(-1) then
529 luasnip.jump(-1)
530 else
531 fallback()
532 end
533 end, { 'i', 's' }),
534 },
535 sources = {
536 { name = 'nvim_lsp' },
537 { name = 'luasnip' },
538 },
539}
540
541-- The line beneath this is called `modeline`. See `:help modeline`
542-- vim: ts=2 sts=2 sw=2 et