init.lua 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. -- Lazy.nvim Configuration
  46. --
  47. -- `lazy.nvim` is a modern plugin manager for Neovim.
  48. --
  49. -- === === === === === === === === === === === === === === === === === === ===
  50. -- Bootstrapping `lazy`, as directed by GitHub docs:
  51. -- https://github.com/folke/lazy.nvim#-installation
  52. local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
  53. ---@diagnostic disable-next-line: undefined-field
  54. if not vim.loop.fs_stat(lazypath) then
  55. vim.fn.system({
  56. "git", "clone", "--filter=blob:none",
  57. "https://github.com/folke/lazy.nvim.git", "--branch=stable", lazypath
  58. })
  59. end
  60. vim.opt.rtp:prepend(lazypath)
  61. -- Add custom plugins to the runtimepath via lazy.
  62. local custom_runtime_path_root = vim.fn.stdpath("config") .. "/custom"
  63. local custom_runtime_paths = {}
  64. for _, filename in pairs(vim.split(vim.fn.glob(custom_runtime_path_root .. "/*"),
  65. "\n")) do
  66. table.insert(custom_runtime_paths, filename)
  67. end
  68. -- Load plugins
  69. require("lazy").setup("plugins", {
  70. performance = { rtp = { paths = custom_runtime_paths } },
  71. change_detection = { enabled = false },
  72. defaults = { lazy = false }
  73. })
  74. -- === === === === === === === === === === === === === === === === === === ===
  75. --
  76. -- Keymaps
  77. --
  78. -- === === === === === === === === === === === === === === === === === === ===
  79. -- Use `Alt-Arrow` to navigate between panes
  80. vim.keymap.set("i", "<A-left>", "<C-\\><C-N><C-w>W")
  81. vim.keymap.set("i", "<A-right>", "<C-\\><C-N><C-w>w")
  82. vim.keymap.set("i", "<S-A-left>", "<C-\\><C-N>:tabnext<CR>")
  83. vim.keymap.set("i", "<S-A-right>", "<C-\\><C-N>:tabprevious<CR>")
  84. vim.keymap.set("n", "<A-left>", "<C-w>W")
  85. vim.keymap.set("n", "<A-right>", "<C-w>w")
  86. vim.keymap.set("n", "<S-A-left>", ":tabnext<CR>")
  87. vim.keymap.set("n", "<S-A-right>", ":tabprevious<CR>")
  88. -- Folds toggled by homerow roll
  89. vim.keymap.set("n", "sr", ": normal za<CR>")
  90. -- Buffer actions
  91. vim.keymap.set("n", "SV", ":vsp<CR>")
  92. vim.keymap.set("n", "SQ", ":q<CR>")
  93. vim.keymap.set("n", "SH", ":noh<CR>")
  94. -- Yank to system clipboard
  95. vim.keymap.set({ "n", 'v' }, "Y", "\"+y")
  96. -- Yank file properties to system clipboard
  97. local yank_filename = function(full, line)
  98. local filename = vim.fn.expand("%")
  99. if full then filename = vim.fn.expand("%:p") end
  100. if line then filename = filename .. ":" .. vim.api.nvim_win_get_cursor(0)[1] end
  101. vim.fn.setreg("+", filename)
  102. end
  103. vim.keymap.set("n", "Syan", function() yank_filename(true, false) end)
  104. vim.keymap.set("n", "Syal", function() yank_filename(true, true) end)
  105. vim.keymap.set("n", "Syrn", function() yank_filename(false, false) end)
  106. vim.keymap.set("n", "Syrl", function() yank_filename(false, true) end)
  107. vim.keymap.set("n", "Syf", function() yank_filename(false, false) end)
  108. -- === === === === === === === === === === === === === === === === === === ===
  109. --
  110. -- Language Servers
  111. --
  112. -- === === === === === === === === === === === === === === === === === === ===
  113. -- See also configurations in `lsp/*.lua` and `custom/proj-conf/`
  114. vim.lsp.config("*", {
  115. cmd_cwd = vim.fn.expand("~"),
  116. root_markers = { ".git" },
  117. })
  118. -- Enable all language servers with extant configurations
  119. for _, filename in pairs(vim.split(io.popen("ls -a " .. vim.fn.stdpath("config")
  120. .. "/lsp"):read("*a"), "\n")) do
  121. if filename:match(".lua$") ~= nil then
  122. vim.lsp.enable(filename:sub(1, -5))
  123. end
  124. end
  125. -- LSP Keymaps
  126. vim.api.nvim_create_autocmd("LspAttach", {
  127. callback = function(_)
  128. vim.keymap.set("n", "SR", vim.lsp.buf.rename)
  129. vim.keymap.set("n", "Sx", vim.lsp.buf.code_action)
  130. vim.keymap.set("n", "<Space>", vim.lsp.buf.hover)
  131. vim.keymap.set("n", "SI", function()
  132. local diagnostic_config = vim.diagnostic.config()
  133. if (vim.lsp.inlay_hint.is_enabled()) then
  134. vim.lsp.inlay_hint.enable(false)
  135. vim.diagnostic.config({
  136. virtual_lines = {
  137. current_line = true,
  138. ---@diagnostic disable-next-line: need-check-nil, undefined-field
  139. format = diagnostic_config.format
  140. }
  141. })
  142. else
  143. vim.lsp.inlay_hint.enable(true)
  144. vim.diagnostic.config({
  145. virtual_lines = true,
  146. ---@diagnostic disable-next-line: need-check-nil, undefined-field
  147. format = diagnostic_config.format
  148. })
  149. end
  150. end)
  151. end
  152. })