-- add extra filetypes for plenary require('plenary.filetype').add_table({ extension = { ['elv'] = [[elvish]] } }) -- add extra builtin filetypes vim.filetype.add({ pattern = { ['.*%.ts$'] = 'typescript' }, }) -- file/buffer/etc picker require('telescope').setup({ defaults = { mappings = { i = { ['jj'] = 'close', }, }, layout_config = { prompt_position = 'top', }, sorting_strategy = 'ascending', -- use filename as preview window title dynamic_preview_title = true, preview = { -- don't preview files larger than 1MB filesize_limit = 1, timeout = 500, }, -- ignore things we're likely not to edit file_ignore_patterns = { "%.zip$", "%.yarn/releases/", "%.yarn/plugins/" }, }, pickers = { buffers = { sort_lastused = true, sort_mru = true, mappings = { i = { [''] = 'delete_buffer' }, }, }, find_files = { find_command = { "fd", "--type", "f", "--strip-cwd-prefix" } }, }, }) -- use native sorter for better performance require('telescope').load_extension('fzf') local telescope_builtin = require('telescope.builtin') local telescope_pickers = require('telescope.pickers') local telescope_finders = require('telescope.finders') local telescope_previewers = require('telescope.previewers') local telescope_putils = require('telescope.previewers.utils') local telescope_conf = require('telescope.config').values -- custom picker to fallback to files if no git _G.project_files = function() local ok = pcall(telescope_builtin.git_files, { show_untracked = true }) if not ok then telescope_builtin.find_files({}) end end -- custom picker for files within a commit _G.commit_files = function(opts) local current_path = vim.api.nvim_buf_get_name(0) local parsed = vim.fn.FugitiveParse(current_path) local resolved_path = parsed[1] local repo = parsed[2] if resolved_path == "" then vim.print("current file is not a fugitive path") return end local parts = vim.split(resolved_path, ':') local commit = parts[1] opts = opts or {} telescope_pickers.new(opts, { prompt_title = commit, finder = telescope_finders.new_oneshot_job({ "git", "ls-tree", "--name-only", "-r", commit }, { entry_maker = function(entry) local path = string.format("fugitive://%s//%s/%s", repo, commit, entry) return { path = path, value = entry, display = entry, ordinal = entry, } end, }), sorter = telescope_conf.file_sorter(opts), -- the builtin previewer has fancy async loading which doesn't work for -- fugitive paths so we have to define our own previewer = telescope_previewers.new_buffer_previewer({ title = function(self) return 'Commit Files' end, dyn_title = function(self, entry) return entry.value end, define_preview = function(self, entry, status) -- the builtin previewer does more things like using mime type -- fallbacks as well as binary file detection which ours doesn't do local ft = telescope_putils.filetype_detect(entry.value) vim.api.nvim_buf_call(self.state.bufnr, function() vim.cmd('Gread ' .. entry.path) telescope_putils.highlighter(self.state.bufnr, ft, opts) end) end, }), }):find() end -- shows added/removed/changed lines require('gitsigns').setup() require('mini.statusline').setup({ content = { -- copy-pasted from default, we just want to remove the icon active = function() local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 }) local git = MiniStatusline.section_git({ trunc_width = 75, icon = '' }) local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75, icon = '' }) local filename = MiniStatusline.section_filename({ trunc_width = 140 }) local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 }) local location = MiniStatusline.section_location({ trunc_width = 75 }) return MiniStatusline.combine_groups({ { hl = mode_hl, strings = { mode } }, { hl = 'MiniStatuslineDevinfo', strings = { git, diagnostics } }, '%<', -- Mark general truncate point { hl = 'MiniStatuslineFilename', strings = { filename } }, '%=', -- End left alignment { hl = 'MiniStatuslineFileinfo', strings = { fileinfo } }, { hl = mode_hl, strings = { location } }, }) end }, }) -- delete buffer while preserving layout require('mini.bufremove').setup() -- shows a line indicating the current indentation scope require('mini.indentscope').setup() -- comment actions require('mini.comment').setup() -- surround actions require('mini.surround').setup() local spec_treesitter = require('mini.ai').gen_spec.treesitter require('mini.ai').setup({ custom_textobjects = { [','] = spec_treesitter({ a = '@parameter.outer', i = '@parameter.inner', }), }, }); -- align actions require('mini.align').setup() -- repeatable f/t require('mini.jump').setup({ mappings = { repeat_jump = '', }, delay = { highlight = 10000000, }, }) -- rest client require('rest-nvim').setup({}) -- Use Treesitter for syntax highlighting require('nvim-treesitter.configs').setup({ highlight = { enable = true, }, incremental_selection = { enable = true, keymaps = { init_selection = "]t", node_incremental = "]t", node_decremental = "[t", }, }, textobjects = { swap = { enable = true, swap_next = { ['>,'] = '@parameter.inner', }, swap_previous = { ['<,'] = '@parameter.inner', }, }, }, }) local tsj_utils = require('treesj.langs.utils') -- Treesitter-aware split/join require('treesj').setup({ use_default_keymaps = false, }) -- completion local cmp = require('cmp') local cmp_types = require('cmp.types') cmp.setup({ snippet = { expand = function(args) vim.fn['vsnip#anonymous'](args.body) end, }, mapping = cmp.mapping.preset.insert({ [''] = cmp.mapping.scroll_docs(-4), [''] = cmp.mapping.scroll_docs(4), [''] = cmp.mapping.complete(), [''] = cmp.mapping.abort(), [''] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items. }), sources = cmp.config.sources({ { name = "nvim_lsp", entry_filter = function(entry, ctx) -- don't autocomplete keywords return cmp_types.lsp.CompletionItemKind[entry:get_kind()] ~= 'Keyword' end }, { name = "vsnip" }, }), completion = { autocomplete = false, }, matching = { -- disable non-prefix matching disallow_fuzzy_matching = true, disallow_partial_matching = true, disallow_prefix_unmatching = true, }, sorting = { comparators = { -- since we only have prefix matches, just sort the results cmp.config.compare.sort_text, }, }, }) -- typescript-vim compiler options vim.g.typescript_compiler_options = '--incremental --noEmit'