123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272 |
- -- 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 = {
- ['<C-k>'] = '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({
- ['<C-b>'] = cmp.mapping.scroll_docs(-4),
- ['<C-f>'] = cmp.mapping.scroll_docs(4),
- ['<C-Space>'] = cmp.mapping.complete(),
- ['<C-e>'] = cmp.mapping.abort(),
- ['<CR>'] = 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'
|