plugins.lua 8.2 KB

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