plugins.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. -- add extra filetypes for plenary
  2. require('plenary.filetype').add_table({
  3. extension = {
  4. ['elv'] = [[elvish]]
  5. }
  6. })
  7. -- add extra builtin filetypes
  8. vim.filetype.add({
  9. pattern = {
  10. ['.*%.ts$'] = 'typescript'
  11. },
  12. })
  13. -- file/buffer/etc picker
  14. require('telescope').setup({
  15. defaults = {
  16. mappings = {
  17. i = {
  18. ['jj'] = 'close',
  19. },
  20. },
  21. layout_config = {
  22. prompt_position = 'top',
  23. },
  24. sorting_strategy = 'ascending',
  25. -- use filename as preview window title
  26. dynamic_preview_title = true,
  27. preview = {
  28. -- don't preview files larger than 1MB
  29. filesize_limit = 1,
  30. timeout = 500,
  31. },
  32. -- ignore things we're likely not to edit
  33. file_ignore_patterns = {
  34. "%.zip$",
  35. "%.yarn/releases/",
  36. "%.yarn/plugins/"
  37. },
  38. -- picker history
  39. cache_picker = {
  40. num_pickers = 10,
  41. },
  42. },
  43. pickers = {
  44. buffers = {
  45. sort_lastused = true,
  46. sort_mru = true,
  47. mappings = {
  48. i = {
  49. ['<C-k>'] = 'delete_buffer'
  50. },
  51. },
  52. },
  53. find_files = {
  54. find_command = { "fd", "--type", "f", "--strip-cwd-prefix" }
  55. },
  56. },
  57. })
  58. -- use native sorter for better performance
  59. require('telescope').load_extension('fzf')
  60. local telescope_builtin = require('telescope.builtin')
  61. local telescope_pickers = require('telescope.pickers')
  62. local telescope_finders = require('telescope.finders')
  63. local telescope_previewers = require('telescope.previewers')
  64. local telescope_putils = require('telescope.previewers.utils')
  65. local telescope_conf = require('telescope.config').values
  66. -- custom picker to fallback to files if no git
  67. _G.project_files = function()
  68. local ok = pcall(telescope_builtin.git_files, { show_untracked = true })
  69. if not ok then telescope_builtin.find_files({}) end
  70. end
  71. -- custom picker for files within a commit
  72. _G.commit_files = function(opts)
  73. local current_path = vim.api.nvim_buf_get_name(0)
  74. local parsed = vim.fn.FugitiveParse(current_path)
  75. local resolved_path = parsed[1]
  76. local repo = parsed[2]
  77. if resolved_path == "" then
  78. vim.print("current file is not a fugitive path")
  79. return
  80. end
  81. local parts = vim.split(resolved_path, ':')
  82. local commit = parts[1]
  83. opts = opts or {}
  84. telescope_pickers.new(opts, {
  85. prompt_title = commit,
  86. finder = telescope_finders.new_oneshot_job({ "git", "ls-tree", "--name-only", "-r", commit }, {
  87. entry_maker = function(entry)
  88. local path = string.format("fugitive://%s//%s/%s", repo, commit, entry)
  89. return {
  90. path = path,
  91. value = entry,
  92. display = entry,
  93. ordinal = entry,
  94. }
  95. end,
  96. }),
  97. sorter = telescope_conf.file_sorter(opts),
  98. -- the builtin previewer has fancy async loading which doesn't work for
  99. -- fugitive paths so we have to define our own
  100. previewer = telescope_previewers.new_buffer_previewer({
  101. title = function(self)
  102. return 'Commit Files'
  103. end,
  104. dyn_title = function(self, entry)
  105. return entry.value
  106. end,
  107. define_preview = function(self, entry, status)
  108. -- the builtin previewer does more things like using mime type
  109. -- fallbacks as well as binary file detection which ours doesn't do
  110. local ft = telescope_putils.filetype_detect(entry.value)
  111. vim.api.nvim_buf_call(self.state.bufnr, function()
  112. vim.cmd('Gread ' .. entry.path)
  113. telescope_putils.highlighter(self.state.bufnr, ft, opts)
  114. end)
  115. end,
  116. }),
  117. }):find()
  118. end
  119. -- shows added/removed/changed lines
  120. require('gitsigns').setup()
  121. require('mini.statusline').setup({
  122. content = {
  123. -- copy-pasted from default, we just want to remove the icon
  124. active = function()
  125. local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
  126. local git = MiniStatusline.section_git({ trunc_width = 75, icon = '' })
  127. local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75, icon = '' })
  128. local filename = MiniStatusline.section_filename({ trunc_width = 140 })
  129. local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
  130. local location = MiniStatusline.section_location({ trunc_width = 75 })
  131. return MiniStatusline.combine_groups({
  132. { hl = mode_hl, strings = { mode } },
  133. { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } },
  134. '%<', -- Mark general truncate point
  135. { hl = 'MiniStatuslineFilename', strings = { filename } },
  136. '%=', -- End left alignment
  137. { hl = 'MiniStatuslineFileinfo', strings = { fileinfo } },
  138. { hl = mode_hl, strings = { location } },
  139. })
  140. end
  141. },
  142. })
  143. -- delete buffer while preserving layout
  144. require('mini.bufremove').setup()
  145. -- shows a line indicating the current indentation scope
  146. require('mini.indentscope').setup()
  147. -- comment actions
  148. require('mini.comment').setup()
  149. -- surround actions
  150. require('mini.surround').setup()
  151. local spec_treesitter = require('mini.ai').gen_spec.treesitter
  152. require('mini.ai').setup({
  153. custom_textobjects = {
  154. [','] = spec_treesitter({
  155. a = '@parameter.outer',
  156. i = '@parameter.inner',
  157. }),
  158. },
  159. });
  160. -- align actions
  161. require('mini.align').setup()
  162. -- repeatable f/t
  163. require('mini.jump').setup({
  164. mappings = {
  165. repeat_jump = '',
  166. },
  167. delay = {
  168. highlight = 10000000,
  169. },
  170. })
  171. -- notifications
  172. require('mini.notify').setup()
  173. vim.notify = require('mini.notify').make_notify()
  174. -- rest client
  175. require('rest-nvim').setup({})
  176. -- Use Treesitter for syntax highlighting
  177. require('nvim-treesitter.configs').setup({
  178. highlight = {
  179. enable = true,
  180. },
  181. indent = {
  182. enable = true,
  183. },
  184. incremental_selection = {
  185. enable = true,
  186. keymaps = {
  187. init_selection = "]t",
  188. node_incremental = "]t",
  189. node_decremental = "[t",
  190. },
  191. },
  192. textobjects = {
  193. swap = {
  194. enable = true,
  195. swap_next = {
  196. ['>,'] = '@parameter.inner',
  197. },
  198. swap_previous = {
  199. ['<,'] = '@parameter.inner',
  200. },
  201. },
  202. },
  203. })
  204. local tsj_utils = require('treesj.langs.utils')
  205. -- Treesitter-aware split/join
  206. require('treesj').setup({
  207. use_default_keymaps = false,
  208. })
  209. -- completion
  210. local cmp = require('cmp')
  211. local cmp_types = require('cmp.types')
  212. cmp.setup({
  213. snippet = {
  214. expand = function(args)
  215. vim.fn['vsnip#anonymous'](args.body)
  216. end,
  217. },
  218. mapping = cmp.mapping.preset.insert({
  219. ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  220. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  221. ['<C-Space>'] = cmp.mapping.complete(),
  222. ['<C-e>'] = cmp.mapping.abort(),
  223. ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
  224. }),
  225. sources = cmp.config.sources({
  226. {
  227. name = "nvim_lsp",
  228. entry_filter = function(entry, ctx)
  229. -- don't autocomplete keywords
  230. return cmp_types.lsp.CompletionItemKind[entry:get_kind()] ~= 'Keyword'
  231. end
  232. },
  233. { name = "vsnip" },
  234. }),
  235. completion = {
  236. autocomplete = false,
  237. },
  238. matching = {
  239. -- disable non-prefix matching
  240. disallow_fuzzy_matching = true,
  241. disallow_partial_matching = true,
  242. disallow_prefix_unmatching = true,
  243. },
  244. sorting = {
  245. comparators = {
  246. -- since we only have prefix matches, just sort the results
  247. cmp.config.compare.sort_text,
  248. },
  249. },
  250. })
  251. -- typescript-vim compiler options
  252. vim.g.typescript_compiler_options = '--incremental --noEmit'