0
0

init.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. -- === === === === === === === === Neovim Config === === === === === === === ===
  2. --
  3. -- A configuration for Neovim that aims to be beautiful, intuitive, and
  4. -- pragmatic about plugin usage, while providing a developer experience on par
  5. -- with professional IDEs. It is tuned for usage with a custom keyboard
  6. -- layout and terminal configuration, and may not be as useful in other setups.
  7. --
  8. -- This configuration leverages a combination of keymaps and omnibars to give
  9. -- quick access to a large amount of functionality in an intuitive way. Most
  10. -- keymaps are unchanged from stock Neovim, with the notable exception of
  11. -- remapping most `s<a-Z>` keymaps.
  12. --
  13. -- === === === === === === === === === === === === === === === === === === ===
  14. --
  15. -- Core Options
  16. --
  17. -- === === === === === === === === === === === === === === === === === === ===
  18. -- Incantation to render correctly in Alacritty/tmux/macOS
  19. vim.cmd([[
  20. let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
  21. let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
  22. set termguicolors
  23. ]])
  24. -- File options
  25. vim.opt.wrap = false
  26. vim.opt.encoding = "UTF-8"
  27. vim.opt.hlsearch = true
  28. vim.opt.spell = true
  29. vim.opt.spelllang = "en_us"
  30. -- Display options
  31. vim.opt.pumheight = 15
  32. vim.opt.laststatus = 2
  33. vim.opt.showtabline = 2
  34. vim.opt.showcmd = true
  35. vim.opt.cmdheight = 0
  36. vim.opt.number = true
  37. vim.opt.relativenumber = true
  38. vim.opt.splitbelow = true
  39. vim.opt.splitright = true
  40. vim.opt.expandtab = true
  41. vim.opt.tabstop = 4
  42. vim.opt.shiftwidth = 4
  43. -- === === === === === === === === === === === === === === === === === === ===
  44. --
  45. -- Leader
  46. --
  47. -- === === === === === === === === === === === === === === === === === === ===
  48. vim.keymap.set({'n', 'v'}, 's', '<Nop>', { noremap = true, silent = true })
  49. vim.keymap.set({'n', 'v'}, 'S', '<Nop>', { noremap = true, silent = true })
  50. vim.g.mapleader = 's'
  51. vim.g.maplocalleader = vim.g.mapleader
  52. -- === === === === === === === === === === === === === === === === === === ===
  53. --
  54. -- Lazy.nvim Configuration
  55. --
  56. -- `lazy.nvim` is a modern plugin manager for Neovim.
  57. --
  58. -- === === === === === === === === === === === === === === === === === === ===
  59. -- Bootstrapping `lazy`, as directed by GitHub docs:
  60. -- https://github.com/folke/lazy.nvim#-installation
  61. local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
  62. ---@diagnostic disable-next-line: undefined-field
  63. if not vim.loop.fs_stat(lazypath) then
  64. vim.fn.system({
  65. "git", "clone", "--filter=blob:none",
  66. "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath
  67. })
  68. end
  69. vim.opt.rtp:prepend(lazypath)
  70. -- Add custom plugins to the runtimepath via lazy.
  71. local custom_runtime_path_root = vim.fn.stdpath("config") .. "/custom"
  72. local custom_runtime_paths = {}
  73. for _, filename in pairs(vim.split(vim.fn.glob(custom_runtime_path_root .. "/*"),
  74. "\n")) do
  75. table.insert(custom_runtime_paths, filename)
  76. end
  77. -- Load plugins
  78. require("lazy").setup("plugins", {
  79. performance = { rtp = { paths = custom_runtime_paths } },
  80. change_detection = { enabled = false },
  81. defaults = { lazy = false }
  82. })
  83. -- === === === === === === === === === === === === === === === === === === ===
  84. --
  85. -- Keymaps
  86. --
  87. -- === === === === === === === === === === === === === === === === === === ===
  88. -- Use `Alt-Arrow` to navigate between panes
  89. vim.keymap.set("i", "<A-left>", "<C-\\><C-N><C-w>W")
  90. vim.keymap.set("i", "<A-right>", "<C-\\><C-N><C-w>w")
  91. vim.keymap.set("i", "<S-A-left>", "<C-\\><C-N>:tabnext<CR>")
  92. vim.keymap.set("i", "<S-A-right>", "<C-\\><C-N>:tabprevious<CR>")
  93. vim.keymap.set("n", "<A-left>", "<C-w>W")
  94. vim.keymap.set("n", "<A-right>", "<C-w>w")
  95. vim.keymap.set("n", "<S-A-left>", ":tabnext<CR>")
  96. vim.keymap.set("n", "<S-A-right>", ":tabprevious<CR>")
  97. -- Folds toggled by homerow roll
  98. vim.keymap.set("n", "sr", ": normal za<CR>")
  99. -- Buffer actions
  100. vim.keymap.set("n", "SV", ":vsp<CR>")
  101. vim.keymap.set("n", "SQ", ":q<CR>")
  102. vim.keymap.set("n", "SH", ":noh<CR>")
  103. -- Yank to system clipboard
  104. vim.keymap.set({ "n", 'v' }, "Y", "\"+y")
  105. -- Yank file properties to system clipboard
  106. local yank_filename = function(full, line)
  107. local filename = vim.fn.expand("%")
  108. if full then filename = vim.fn.expand("%:p") end
  109. if line then filename = filename .. ":" .. vim.api.nvim_win_get_cursor(0)[1] end
  110. vim.fn.setreg("+", filename)
  111. end
  112. vim.keymap.set("n", "Syan", function() yank_filename(true, false) end)
  113. vim.keymap.set("n", "Syal", function() yank_filename(true, true) end)
  114. vim.keymap.set("n", "Syrn", function() yank_filename(false, false) end)
  115. vim.keymap.set("n", "Syrl", function() yank_filename(false, true) end)
  116. vim.keymap.set("n", "Syf", function() yank_filename(false, false) end)
  117. -- === === === === === === === === === === === === === === === === === === ===
  118. --
  119. -- Language Servers
  120. --
  121. -- === === === === === === === === === === === === === === === === === === ===
  122. -- See also configurations in `lsp/*.lua` and `custom/proj-conf/`
  123. vim.lsp.config("*", {
  124. cmd_cwd = vim.fn.expand("~"),
  125. root_markers = { ".git" },
  126. })
  127. -- Enable all language servers with extant configurations
  128. for _, filename in pairs(vim.split(io.popen("ls -a " .. vim.fn.stdpath("config")
  129. .. "/lsp"):read("*a"), "\n")) do
  130. if filename:match(".lua$") ~= nil then
  131. vim.lsp.enable(filename:sub(1, -5))
  132. end
  133. end
  134. -- LSP Keymaps
  135. vim.api.nvim_create_autocmd("LspAttach", {
  136. callback = function(_)
  137. vim.keymap.set("n", "SR", vim.lsp.buf.rename)
  138. vim.keymap.set("n", "Sx", vim.lsp.buf.code_action)
  139. vim.keymap.set("n", "<Space>", vim.lsp.buf.hover)
  140. vim.keymap.set("n", "SI", function()
  141. local diagnostic_config = vim.diagnostic.config()
  142. if (vim.lsp.inlay_hint.is_enabled()) then
  143. vim.lsp.inlay_hint.enable(false)
  144. vim.diagnostic.config({
  145. virtual_lines = {
  146. current_line = true,
  147. ---@diagnostic disable-next-line: need-check-nil, undefined-field
  148. format = diagnostic_config.format
  149. }
  150. })
  151. else
  152. vim.lsp.inlay_hint.enable(true)
  153. vim.diagnostic.config({
  154. virtual_lines = true,
  155. ---@diagnostic disable-next-line: need-check-nil, undefined-field
  156. format = diagnostic_config.format
  157. })
  158. end
  159. end)
  160. end
  161. })