From a00e28b031b86c5c67f0e82e46df5c9e4f51f0eb Mon Sep 17 00:00:00 2001 From: Fernando Schauenburg Date: Sat, 8 Jul 2023 21:42:40 +0200 Subject: [PATCH] vim: migrate plugin configuration to lazy.nvim --- config/nvim/after/plugin/colorizer.lua | 5 - config/nvim/after/plugin/fugitive.lua | 3 - config/nvim/after/plugin/indent-blankline.lua | 10 - config/nvim/after/plugin/lualine.lua | 180 ----------------- config/nvim/after/plugin/nvim-tree.lua | 46 ----- config/nvim/after/plugin/solarized.lua | 5 - config/nvim/after/plugin/tabular.lua | 6 - config/nvim/after/plugin/telescope.lua | 172 ---------------- config/nvim/after/plugin/treesitter.lua | 91 --------- .../after/plugin/vim-better-whitespace.lua | 6 - config/nvim/after/plugin/virt-column.lua | 17 -- config/nvim/lua/user/init.lua | 6 +- config/nvim/lua/user/plugins/colorizer.lua | 8 + config/nvim/lua/user/plugins/fugitive.lua | 8 + .../lua/user/plugins/indent-blankline.lua | 13 ++ config/nvim/lua/user/plugins/init.lua | 45 +---- config/nvim/lua/user/plugins/lualine.lua | 181 +++++++++++++++++ config/nvim/lua/user/plugins/nvim-tree.lua | 50 +++++ config/nvim/lua/user/plugins/solarized.lua | 8 + config/nvim/lua/user/plugins/tabular.lua | 12 ++ config/nvim/lua/user/plugins/telescope.lua | 183 ++++++++++++++++++ config/nvim/lua/user/plugins/treesitter.lua | 102 ++++++++++ .../user/plugins/vim-better-whitespace.lua | 22 +++ config/nvim/lua/user/plugins/virt-column.lua | 20 ++ .../user/plugins/visual-multi.lua.disabled | 9 + 25 files changed, 621 insertions(+), 587 deletions(-) delete mode 100644 config/nvim/after/plugin/colorizer.lua delete mode 100644 config/nvim/after/plugin/fugitive.lua delete mode 100644 config/nvim/after/plugin/indent-blankline.lua delete mode 100644 config/nvim/after/plugin/lualine.lua delete mode 100644 config/nvim/after/plugin/nvim-tree.lua delete mode 100644 config/nvim/after/plugin/solarized.lua delete mode 100644 config/nvim/after/plugin/tabular.lua delete mode 100644 config/nvim/after/plugin/telescope.lua delete mode 100644 config/nvim/after/plugin/treesitter.lua delete mode 100644 config/nvim/after/plugin/vim-better-whitespace.lua delete mode 100644 config/nvim/after/plugin/virt-column.lua create mode 100644 config/nvim/lua/user/plugins/colorizer.lua create mode 100644 config/nvim/lua/user/plugins/fugitive.lua create mode 100644 config/nvim/lua/user/plugins/indent-blankline.lua create mode 100644 config/nvim/lua/user/plugins/lualine.lua create mode 100644 config/nvim/lua/user/plugins/nvim-tree.lua create mode 100644 config/nvim/lua/user/plugins/solarized.lua create mode 100644 config/nvim/lua/user/plugins/tabular.lua create mode 100644 config/nvim/lua/user/plugins/telescope.lua create mode 100644 config/nvim/lua/user/plugins/treesitter.lua create mode 100644 config/nvim/lua/user/plugins/vim-better-whitespace.lua create mode 100644 config/nvim/lua/user/plugins/virt-column.lua create mode 100644 config/nvim/lua/user/plugins/visual-multi.lua.disabled diff --git a/config/nvim/after/plugin/colorizer.lua b/config/nvim/after/plugin/colorizer.lua deleted file mode 100644 index 77a6a94..0000000 --- a/config/nvim/after/plugin/colorizer.lua +++ /dev/null @@ -1,5 +0,0 @@ -local ok, colorizer = pcall(require, 'colorizer') -if ok and colorizer and vim.opt.termguicolors:get() then - colorizer.setup({'*'}, { mode = 'foreground' }) -end - diff --git a/config/nvim/after/plugin/fugitive.lua b/config/nvim/after/plugin/fugitive.lua deleted file mode 100644 index 4041bc3..0000000 --- a/config/nvim/after/plugin/fugitive.lua +++ /dev/null @@ -1,3 +0,0 @@ -vim.keymap.set('n', 'gs', 'tab Git') -vim.keymap.set('n', 'gb', 'Git blame') - diff --git a/config/nvim/after/plugin/indent-blankline.lua b/config/nvim/after/plugin/indent-blankline.lua deleted file mode 100644 index 2a421b0..0000000 --- a/config/nvim/after/plugin/indent-blankline.lua +++ /dev/null @@ -1,10 +0,0 @@ -local ok, plugin = pcall(require, 'indent_blankline') -if not ok then return end - -plugin.setup { - enabled = false, -} - --- show/hide indent guides -vim.keymap.set('n', 'si', 'IndentBlanklineToggle') - diff --git a/config/nvim/after/plugin/lualine.lua b/config/nvim/after/plugin/lualine.lua deleted file mode 100644 index 58febea..0000000 --- a/config/nvim/after/plugin/lualine.lua +++ /dev/null @@ -1,180 +0,0 @@ -local ok, lualine = pcall(require, 'lualine') -if not ok or not lualine then - return -end - -local MODE_MAP = { - ['n'] = 'Normal ', - ['no'] = 'O-Pend ', - ['nov'] = 'O-Pend ', - ['noV'] = 'O-Pend ', - ['no'] = 'O-Pend ', - ['niI'] = 'Normal ', - ['niR'] = 'Normal ', - ['niV'] = 'Normal ', - ['nt'] = 'Normal ', - ['ntT'] = 'Normal*', - ['v'] = 'Visual ', - ['vs'] = 'Visual ', - ['V'] = 'V-Line ', - ['Vs'] = 'V-Line ', - [''] = 'V-Block', - ['s'] = 'V-Block', - ['s'] = 'Select ', - ['S'] = 'S-Line ', - [''] = 'S-Block', - ['i'] = 'Insert ', - ['ic'] = 'Insert ', - ['ix'] = 'Insert ', - ['R'] = 'Replace', - ['Rc'] = 'Replace', - ['Rx'] = 'Replace', - ['Rv'] = 'V-Repl ', - ['Rvc'] = 'V-Repl ', - ['Rvx'] = 'V-Repl ', - ['c'] = 'Command', - ['cv'] = ' Ex ', - ['ce'] = ' Ex ', - ['r'] = 'Replace', - ['rm'] = ' More ', - ['r?'] = 'Confirm', - ['!'] = ' Shell ', - ['t'] = ' Term ', -} - -local update_status = function(self, is_focused) - self.options.colored = is_focused - return self.super.update_status(self, is_focused) -end - -local diff = require'lualine.components.diff':extend() -diff.update_status = update_status - -local filetype = require'lualine.components.filetype':extend() -filetype.update_status = update_status - -local window_is_at_least = function(width) - return function() return vim.fn.winwidth(0) > width end -end - -local window_is_wide = window_is_at_least(80) -local window_is_medium = window_is_at_least(50) - -local parts = { - paste = { - function() return '' end, - color = { bg = '#bbaa00' }, - cond = function() - return vim.opt.paste:get() - end - }, - - mode = { - function() - local code = vim.api.nvim_get_mode().mode - return MODE_MAP[code] or code - end, - }, - - visual_multi = function() - local ok, infos = pcall(vim.fn.VMInfos) - if not ok or not infos.status then return '' end - return infos.current .. '/' .. infos.total .. ' ' .. infos.status - end, - - branch = { - 'branch', - icon = '', - cond = window_is_medium, - }, - - status = { - function() - local flags = {} - if vim.bo.modified then - table.insert(flags, '+') - end - if vim.bo.modifiable == false or vim.bo.readonly == true then - table.insert(flags, 'RO') - end - return table.concat(flags, ' ') - end, - - color = { fg = '#eee8d5' }, - }, - - filename = { - function() - local shorten_path = function(path) - if window_is_wide() then - return path - elseif window_is_medium() then - return vim.fn.pathshorten(path) -- only first letter of directories - else - return vim.fn.fnamemodify(path, ':t') -- only tail - end - end - - return shorten_path(vim.fn.expand('%:~:.')) - end, - - color = function() - if vim.bo.modified then - return { gui = 'italic' } - end - end, - - padding = { left = 1, right = 0}, - }, - - filetype = { - filetype, - cond = window_is_medium, - }, - - fileformat = { - 'fileformat', - cond = window_is_medium, - }, - - progress = { - function() - local chars = { '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' } - local current, total = vim.fn.line '.', vim.fn.line '$' - return chars[math.ceil(#chars * current / total)] - end, - padding = { left = 0, right = 1 }, - cond = window_is_wide, - }, -} - -local inactive_sections = { - lualine_a = {}, - lualine_b = { parts.visual_multi, parts.branch }, - lualine_c = { parts.filename, parts.status }, - lualine_x = { 'diagnostics', parts.filetype }, - lualine_y = { parts.fileformat, parts.progress }, - lualine_z = { 'location' }, -} - -lualine.setup { - options = { - icons_enabled = true, - component_separators = { left = '', right = '' }, - section_separators = { left = '', right = '' }, - theme = 'solarized', - }, - - sections = vim.tbl_extend('force', inactive_sections, { - lualine_a = { parts.paste, parts.mode }, - }), - - inactive_sections = inactive_sections, - - extensions = { - 'fugitive', - 'quickfix', - 'nvim-tree', - } -} - diff --git a/config/nvim/after/plugin/nvim-tree.lua b/config/nvim/after/plugin/nvim-tree.lua deleted file mode 100644 index b168c51..0000000 --- a/config/nvim/after/plugin/nvim-tree.lua +++ /dev/null @@ -1,46 +0,0 @@ -local ok, nt = pcall(require, 'nvim-tree') -if not ok then return end - -local on_attach = function(bufnr) - local api = require 'nvim-tree.api' - local opts = function(desc) - return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true } - end - - vim.keymap.set('n', 'l', api.node.open.edit, opts('open')) - vim.keymap.set('n', '', api.node.open.edit, opts('open')) - vim.keymap.set('n', 'o', api.node.open.edit, opts('open')) - vim.keymap.set('n', 'h', api.node.navigate.parent_close, opts('close directory')) -end - -nt.setup { - disable_netrw = true, -- replace netrw with nvim-tree - hijack_cursor = true, -- keep the cursor on begin of the filename - sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree - on_attach = on_attach, - - git = { - ignore = false, -- don't hide files from .gitignore - }, - - view = { - adaptive_size = true, -- resize the window based on the longest line - width = 35, -- a little wider than the default 30 - }, - - filters = { - dotfiles = false, -- show files starting with a . - custom = { '^\\.git' }, -- don't show .git directory - }, - - renderer = { - add_trailing = true, -- add trailing / to folders - group_empty = true, -- folders that contain only one folder are grouped - highlight_git = true, -- enable highlight based on git attributes - }, -} - -vim.keymap.set('n', 'nn', 'NvimTreeOpen') -vim.keymap.set('n', 'nf', 'NvimTreeFindFile') -vim.keymap.set('n', 'nc', 'NvimTreeClose') - diff --git a/config/nvim/after/plugin/solarized.lua b/config/nvim/after/plugin/solarized.lua deleted file mode 100644 index 17067a8..0000000 --- a/config/nvim/after/plugin/solarized.lua +++ /dev/null @@ -1,5 +0,0 @@ -local ok, solarized = pcall(require, 'solarized') -if ok and solarized then - vim.cmd [[colorscheme solarized]] -end - diff --git a/config/nvim/after/plugin/tabular.lua b/config/nvim/after/plugin/tabular.lua deleted file mode 100644 index 562cece..0000000 --- a/config/nvim/after/plugin/tabular.lua +++ /dev/null @@ -1,6 +0,0 @@ -if vim.fn.exists('g:tabular_loaded') ~= 1 then return end - -vim.cmd [[ AddTabularPattern! first_comma /^[^,]*\zs,/ ]] -vim.cmd [[ AddTabularPattern! first_colon /^[^:]*\zs:/ ]] -vim.cmd [[ AddTabularPattern! first_equal /^[^=]*\zs=/ ]] - diff --git a/config/nvim/after/plugin/telescope.lua b/config/nvim/after/plugin/telescope.lua deleted file mode 100644 index 597c4c4..0000000 --- a/config/nvim/after/plugin/telescope.lua +++ /dev/null @@ -1,172 +0,0 @@ -local has_telescope, telescope = pcall(require, 'telescope') -if not has_telescope then return end - -local actions = require 'telescope.actions' -local actions_layout = require 'telescope.actions.layout' - -local common_mappings = { - [''] = actions_layout.cycle_layout_next, - [''] = actions_layout.toggle_mirror, - [''] = actions.smart_send_to_qflist + actions.open_qflist, -} - -telescope.setup { - defaults = { - prompt_prefix = ' ❯ ', - selection_caret = ' ', -- Other ideas: ➔  - multi_icon = ' ', - - layout_strategy = 'flex', - layout_config = { - anchor = 'center', - width = 0.9, - height = 0.9, - - flex = { - flip_columns = 130, - }, - - horizontal = { - preview_width = 0.5, - preview_cutoff = 130, - }, - - vertical = { - preview_height = 0.5, - }, - }, - - cycle_layout_list = { - { layout_strategy = 'bottom_pane', layout_config = { width = 1, height = 0.4 }, }, - 'horizontal', - 'vertical', - }, - - mappings = { - i = vim.tbl_extend('force', common_mappings, { - [''] = actions.cycle_history_next, - [''] = actions.cycle_history_prev, - }), - n = common_mappings, - }, - }, - - pickers = { - buffers = { prompt_title = ' ﬘ Buffers ' }, - find_files = { prompt_title = '  Files ' }, - git_commits = { prompt_title = '  Commits ' }, - help_tags = { prompt_title = '  Help tags ' }, - keymaps = { prompt_title = '  Keymaps ' }, - live_grep = { prompt_title = '  Live grep ' }, - vim_options = { prompt_title = '  Vim options ' }, - man_pages = { prompt_title = '  Man pages ' }, - }, - - extensions = { - file_browser = { - theme = 'ivy', - mappings = { - n = { - -- normal mode mappings go here - }, - i = { - -- insert mode mappings go here - }, - }, - }, - }, -} - -local builtin = require 'telescope.builtin' - -local selected_range = function() - local _, s_row, s_col, _ = unpack(vim.fn.getpos('v')) - local _, e_row, e_col, _ = unpack(vim.fn.getpos('.')) - - local mode = vim.api.nvim_get_mode().mode - local visual_line = (mode == 'V' or mode == 'CTRL-V') - - if s_row < e_row or (s_row == e_row and s_col <= e_col) then - if visual_line then s_col, e_col = 1, #vim.fn.getline(e_row) end - return s_row - 1, s_col - 1, e_row - 1, e_col - else - if visual_line then e_col, s_col = 1, #vim.fn.getline(s_row) end - return e_row - 1, e_col - 1, s_row - 1, s_col - end -end - -local selected_text = function() - local r0, c0, r1, c1 = selected_range() - return vim.fn.join(vim.api.nvim_buf_get_text(0, r0, c0, r1, c1, {}), '\n') -end - -local custom = { - all_files = function() - builtin.find_files { - prompt_title = '  ALL Files ', - hidden = true, - no_ignore = true, - no_ignore_parent = true, - } - end, - - dotfiles = function() - builtin.find_files { - prompt_title = '  Find dotfiles ', - cwd = '~/.dotfiles', - hidden = true, - } - end, - - grep_visual = function() - local selection = selected_text() - builtin.grep_string { - prompt_title = string.format('  Grep: %s', selection), - search = selection, - } - end, - - man_pages = function() - -- Fix for macOS Ventura onwards (macOS 13.x <-> Darwin 22.x). - -- See: https://github.com/nvim-telescope/telescope.nvim/issues/2326#issuecomment-1407502328 - local uname = vim.loop.os_uname() - local sysname = string.lower(uname.sysname) - if sysname == "darwin" then - local major_version = tonumber(vim.fn.matchlist(uname.release, [[^\(\d\+\)\..*]])[2]) or 0 - if major_version >= 22 then - builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", "." } } - else - builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", " " } } - end - elseif sysname == "freebsd" then - builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", "." } } - else - builtin.man_pages { sections = { 'ALL' } } - end - end, -} - -local map = vim.keymap.set - -map('n', 'fa', custom.all_files, { desc = ' [F]ind [A]ll Files in $PWD' }) -map('n', 'fb', builtin.buffers, { desc = ' [F]ind [B]uffers' }) -map('n', 'fc', builtin.git_commits, { desc = ' [F]ind [C]ommits' }) -map('n', 'fd', custom.dotfiles, { desc = ' [F]ind [D]otfiles' }) -map('n', 'ff', builtin.find_files, { desc = ' [F]ind [F]iles in $PWD' }) -map('n', 'fg', builtin.live_grep, { desc = ' [F]ind with [G]rep in $PWD' }) -map('n', 'fh', builtin.help_tags, { desc = ' [F]ind [H]elp tags' }) -map('n', 'fk', builtin.keymaps, { desc = ' [F]ind [K]eymaps' }) -map('n', 'fm', custom.man_pages, { desc = ' [F]ind [M]an pages' }) -map('n', 'fo', builtin.vim_options, { desc = ' [F]ind vim [O]ptions' }) -map('n', 'fs', builtin.grep_string, { desc = ' [F]ind [S]tring' }) -map('v', 'fs', custom.grep_visual, { desc = ' [F]ind visual [S]election' }) - - - -local loaded_file_browser, _ = pcall(telescope.load_extension, 'file_browser') -if loaded_file_browser then - map('n', 'br', 'Telescope file_browser', { desc = ' file [BR]owser' }) -else - vim.notify('Telescope file_browser not installed!', vim.log.levels.WARN) -end - diff --git a/config/nvim/after/plugin/treesitter.lua b/config/nvim/after/plugin/treesitter.lua deleted file mode 100644 index 80e90e4..0000000 --- a/config/nvim/after/plugin/treesitter.lua +++ /dev/null @@ -1,91 +0,0 @@ -local ok, configs = pcall(require, 'nvim-treesitter.configs') -if not ok then return end - -configs.setup { - ensure_installed = { - 'bash', - 'c', - 'cpp', - 'haskell', - 'html', - 'javascript', - 'latex', - 'lua', - 'make', - 'markdown', - 'markdown_inline', - 'python', - 'query', - 'toml', - 'vim', - 'vimdoc', - 'yaml', - }, - - highlight = { - enable = true, - disable = { - 'help', - }, - }, - - incremental_selection = { - enable = true, - keymaps = { - init_selection = 'gnn', -- mapped in normal mode - node_incremental = '', -- mapped in visual mode - node_decremental = '', -- mapped in visual mode - scope_incremental = nil, -- disabled, normally mapped in visual mode - }, - }, - - refactor = { - highlight_definitions = { enable = true }, - highlight_current_scope = { enable = false }, - - smart_rename = { - enable = true, - keymaps = { - smart_rename = 'grr', - }, - }, - - navigation = { - enable = true, - keymaps = { - goto_definition = 'gd', -- default: 'gnd' - list_definitions = nil, -- disabled, default: 'gnD' - list_definitions_toc = 'gO', - goto_next_usage = '', - goto_previous_usage = '', - }, - }, - }, - - textobjects = { - select = { - enable = true, - keymaps = { - ['ab'] = '@block.outer', - ['ib'] = '@block.inner', - ['ac'] = '@conditional.outer', - ['ic'] = '@conditional.inner', - ['af'] = '@function.outer', - ['if'] = '@function.inner', - ['al'] = '@loop.outer', - ['il'] = '@loop.inner', - ['aa'] = '@parameter.outer', - ['ia'] = '@parameter.inner', - }, - }, - }, - - playground = { - enable = true, - }, -} - -vim.keymap.set('n', 'sp', 'TSPlaygroundToggle') -vim.keymap.set('n', 'sh', 'TSHighlightCapturesUnderCursor') -vim.keymap.set('n', 'sn', 'TSNodeUnderCursor') - diff --git a/config/nvim/after/plugin/vim-better-whitespace.lua b/config/nvim/after/plugin/vim-better-whitespace.lua deleted file mode 100644 index 33ff6e6..0000000 --- a/config/nvim/after/plugin/vim-better-whitespace.lua +++ /dev/null @@ -1,6 +0,0 @@ --- fix whitespace -vim.keymap.set('n', 'w', 'StripWhitespace') - --- show/hide whitespace -vim.keymap.set('n', 'sw', 'ToggleWhitespace') - diff --git a/config/nvim/after/plugin/virt-column.lua b/config/nvim/after/plugin/virt-column.lua deleted file mode 100644 index ee65593..0000000 --- a/config/nvim/after/plugin/virt-column.lua +++ /dev/null @@ -1,17 +0,0 @@ -local ok, plugin = pcall(require, 'virt-column') -if not ok then return end - -plugin.setup { - char = '│', -} - -local toggle_virtual_column = function() - if vim.o.colorcolumn == '' then - vim.o.colorcolumn = '+1' -- one after 'textwidth' - else - vim.o.colorcolumn = '' -- none - end -end - -vim.keymap.set('n', 'sc', toggle_virtual_column) - diff --git a/config/nvim/lua/user/init.lua b/config/nvim/lua/user/init.lua index 31903ca..5d74607 100644 --- a/config/nvim/lua/user/init.lua +++ b/config/nvim/lua/user/init.lua @@ -9,14 +9,14 @@ require 'user.filetypes' local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then - vim.fn.system({ + vim.fn.system { "git", "clone", "--filter=blob:none", "https://github.com/folke/lazy.nvim.git", - "--branch=stable", -- latest stable release + "--branch=stable", lazypath, - }) + } end vim.opt.rtp:prepend(lazypath) diff --git a/config/nvim/lua/user/plugins/colorizer.lua b/config/nvim/lua/user/plugins/colorizer.lua new file mode 100644 index 0000000..c9023be --- /dev/null +++ b/config/nvim/lua/user/plugins/colorizer.lua @@ -0,0 +1,8 @@ +return { + 'norcalli/nvim-colorizer.lua', + cond = vim.opt.termguicolors:get(), + config = function() + require('colorizer').setup({'*'}, { mode = 'foreground' }) + end, +} + diff --git a/config/nvim/lua/user/plugins/fugitive.lua b/config/nvim/lua/user/plugins/fugitive.lua new file mode 100644 index 0000000..d09df61 --- /dev/null +++ b/config/nvim/lua/user/plugins/fugitive.lua @@ -0,0 +1,8 @@ +return { + 'tpope/vim-fugitive', + config = function() + vim.keymap.set('n', 'gs', 'tab Git') + vim.keymap.set('n', 'gb', 'Git blame') + end, +} + diff --git a/config/nvim/lua/user/plugins/indent-blankline.lua b/config/nvim/lua/user/plugins/indent-blankline.lua new file mode 100644 index 0000000..9607ba5 --- /dev/null +++ b/config/nvim/lua/user/plugins/indent-blankline.lua @@ -0,0 +1,13 @@ +return { + 'lukas-reineke/indent-blankline.nvim', + + config = function() + require('indent_blankline').setup { + enabled = false, + } + + -- show/hide indent guides + vim.keymap.set('n', 'si', 'IndentBlanklineToggle') + end, +} + diff --git a/config/nvim/lua/user/plugins/init.lua b/config/nvim/lua/user/plugins/init.lua index e34342b..7784b69 100644 --- a/config/nvim/lua/user/plugins/init.lua +++ b/config/nvim/lua/user/plugins/init.lua @@ -1,50 +1,9 @@ --- vim.g.better_whitespace_filetypes_blacklist = { --- 'diff', --- 'fugitive', --- 'git', --- 'gitcommit', --- 'help', --- } - --- vim.g.VM_leader = '\\' --- vim.g.VM_silent_exit = 1 - return { - 'wbthomason/packer.nvim', 'nvim-lua/plenary.nvim', - - -- Visuals ---------------------------------------------------------------- - { dir = '~/.dotfiles/plugins/solarized.nvim' }, + 'milisims/nvim-luaref', 'kyazdani42/nvim-web-devicons', - 'nvim-lualine/lualine.nvim', - 'lukas-reineke/virt-column.nvim', - 'lukas-reineke/indent-blankline.nvim', - 'norcalli/nvim-colorizer.lua', - - -- Navigation ------------------------------------------------------------- - 'nvim-telescope/telescope.nvim', - 'nvim-telescope/telescope-file-browser.nvim', - 'kyazdani42/nvim-tree.lua', - - -- Editing ---------------------------------------------------------------- - 'ntpeters/vim-better-whitespace', - 'godlygeek/tabular', 'tpope/vim-commentary', - -- 'mg979/vim-visual-multi', - - -- git -------------------------------------------------------------------- - 'tpope/vim-fugitive', - - -- Treesitter ------------------------------------------------------------- - 'nvim-treesitter/nvim-treesitter', - 'nvim-treesitter/nvim-treesitter-refactor', - 'nvim-treesitter/nvim-treesitter-textobjects', - 'nvim-treesitter/playground', - - -- Filetypes -------------------------------------------------------------- 'keith/swift.vim', 'chr4/nginx.vim', - - -- Misc ------------------------------------------------------------------- - 'milisims/nvim-luaref', } + diff --git a/config/nvim/lua/user/plugins/lualine.lua b/config/nvim/lua/user/plugins/lualine.lua new file mode 100644 index 0000000..eb57670 --- /dev/null +++ b/config/nvim/lua/user/plugins/lualine.lua @@ -0,0 +1,181 @@ +return { + 'nvim-lualine/lualine.nvim', + + config = function() + local MODE_MAP = { + ['n'] = 'Normal ', + ['no'] = 'O-Pend ', + ['nov'] = 'O-Pend ', + ['noV'] = 'O-Pend ', + ['no'] = 'O-Pend ', + ['niI'] = 'Normal ', + ['niR'] = 'Normal ', + ['niV'] = 'Normal ', + ['nt'] = 'Normal ', + ['ntT'] = 'Normal*', + ['v'] = 'Visual ', + ['vs'] = 'Visual ', + ['V'] = 'V-Line ', + ['Vs'] = 'V-Line ', + [''] = 'V-Block', + ['s'] = 'V-Block', + ['s'] = 'Select ', + ['S'] = 'S-Line ', + [''] = 'S-Block', + ['i'] = 'Insert ', + ['ic'] = 'Insert ', + ['ix'] = 'Insert ', + ['R'] = 'Replace', + ['Rc'] = 'Replace', + ['Rx'] = 'Replace', + ['Rv'] = 'V-Repl ', + ['Rvc'] = 'V-Repl ', + ['Rvx'] = 'V-Repl ', + ['c'] = 'Command', + ['cv'] = ' Ex ', + ['ce'] = ' Ex ', + ['r'] = 'Replace', + ['rm'] = ' More ', + ['r?'] = 'Confirm', + ['!'] = ' Shell ', + ['t'] = ' Term ', + } + + local update_status = function(self, is_focused) + self.options.colored = is_focused + return self.super.update_status(self, is_focused) + end + + local diff = require'lualine.components.diff':extend() + diff.update_status = update_status + + local filetype = require'lualine.components.filetype':extend() + filetype.update_status = update_status + + local window_is_at_least = function(width) + return function() return vim.fn.winwidth(0) > width end + end + + local window_is_wide = window_is_at_least(80) + local window_is_medium = window_is_at_least(50) + + local parts = { + paste = { + function() return '' end, + color = { bg = '#bbaa00' }, + cond = function() + return vim.opt.paste:get() + end + }, + + mode = { + function() + local code = vim.api.nvim_get_mode().mode + return MODE_MAP[code] or code + end, + }, + + visual_multi = function() + local ok, infos = pcall(vim.fn.VMInfos) + if not ok or not infos.status then return '' end + return infos.current .. '/' .. infos.total .. ' ' .. infos.status + end, + + branch = { + 'branch', + icon = '', + cond = window_is_medium, + }, + + status = { + function() + local flags = {} + if vim.bo.modified then + table.insert(flags, '+') + end + if vim.bo.modifiable == false or vim.bo.readonly == true then + table.insert(flags, 'RO') + end + return table.concat(flags, ' ') + end, + + color = { fg = '#eee8d5' }, + }, + + filename = { + function() + local shorten_path = function(path) + if window_is_wide() then + return path + elseif window_is_medium() then + return vim.fn.pathshorten(path) -- only first letter of directories + else + return vim.fn.fnamemodify(path, ':t') -- only tail + end + end + + return shorten_path(vim.fn.expand('%:~:.')) + end, + + color = function() + if vim.bo.modified then + return { gui = 'italic' } + end + end, + + padding = { left = 1, right = 0}, + }, + + filetype = { + filetype, + cond = window_is_medium, + }, + + fileformat = { + 'fileformat', + cond = window_is_medium, + }, + + progress = { + function() + local chars = { '', '', '', '', '', '', '', '', '', '', '', '', '', '', '' } + local current, total = vim.fn.line '.', vim.fn.line '$' + return chars[math.ceil(#chars * current / total)] + end, + padding = { left = 0, right = 1 }, + cond = window_is_wide, + }, + } + + local inactive_sections = { + lualine_a = {}, + lualine_b = { parts.visual_multi, parts.branch }, + lualine_c = { parts.filename, parts.status }, + lualine_x = { 'diagnostics', parts.filetype }, + lualine_y = { parts.fileformat, parts.progress }, + lualine_z = { 'location' }, + } + + require('lualine').setup { + options = { + icons_enabled = true, + component_separators = { left = '', right = '' }, + section_separators = { left = '', right = '' }, + theme = 'solarized', + }, + + sections = vim.tbl_extend('force', inactive_sections, { + lualine_a = { parts.paste, parts.mode }, + }), + + inactive_sections = inactive_sections, + + extensions = { + 'fugitive', + 'quickfix', + 'nvim-tree', + } + } + end, +} + diff --git a/config/nvim/lua/user/plugins/nvim-tree.lua b/config/nvim/lua/user/plugins/nvim-tree.lua new file mode 100644 index 0000000..4c84e35 --- /dev/null +++ b/config/nvim/lua/user/plugins/nvim-tree.lua @@ -0,0 +1,50 @@ +local on_attach = function(bufnr) + local node = require('nvim-tree.api').node + local opts = function(desc) + return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, silent = true } + end + + vim.keymap.set('n', 'l', node.open.edit, opts('open')) + vim.keymap.set('n', '', node.open.edit, opts('open')) + vim.keymap.set('n', 'o', node.open.edit, opts('open')) + vim.keymap.set('n', 'h', node.navigate.parent_close, opts('close directory')) +end + + +return { + 'kyazdani42/nvim-tree.lua', + + config = function() + require('nvim-tree').setup { + disable_netrw = true, -- replace netrw with nvim-tree + hijack_cursor = true, -- keep the cursor on begin of the filename + sync_root_with_cwd = true, -- watch for `DirChanged` and refresh the tree + on_attach = on_attach, + + git = { + ignore = false, -- don't hide files from .gitignore + }, + + view = { + adaptive_size = true, -- resize the window based on the longest line + width = 35, -- a little wider than the default 30 + }, + + filters = { + dotfiles = false, -- show files starting with a . + custom = { '^\\.git' }, -- don't show .git directory + }, + + renderer = { + add_trailing = true, -- add trailing / to folders + group_empty = true, -- folders that contain only one folder are grouped + highlight_git = true, -- enable highlight based on git attributes + }, + } + + vim.keymap.set('n', 'nn', 'NvimTreeOpen') + vim.keymap.set('n', 'nf', 'NvimTreeFindFile') + vim.keymap.set('n', 'nc', 'NvimTreeClose') + end, +} + diff --git a/config/nvim/lua/user/plugins/solarized.lua b/config/nvim/lua/user/plugins/solarized.lua new file mode 100644 index 0000000..ace2d17 --- /dev/null +++ b/config/nvim/lua/user/plugins/solarized.lua @@ -0,0 +1,8 @@ +return { + dir = '~/.dotfiles/plugins/solarized.nvim', + + config = function() + vim.cmd [[colorscheme solarized]] + end, +} + diff --git a/config/nvim/lua/user/plugins/tabular.lua b/config/nvim/lua/user/plugins/tabular.lua new file mode 100644 index 0000000..97708c3 --- /dev/null +++ b/config/nvim/lua/user/plugins/tabular.lua @@ -0,0 +1,12 @@ +return { + 'godlygeek/tabular', + + config = function() + if vim.fn.exists('g:tabular_loaded') == 1 then + vim.cmd [[ AddTabularPattern! first_comma /^[^,]*\zs,/ ]] + vim.cmd [[ AddTabularPattern! first_colon /^[^:]*\zs:/ ]] + vim.cmd [[ AddTabularPattern! first_equal /^[^=]*\zs=/ ]] + end + end, +} + diff --git a/config/nvim/lua/user/plugins/telescope.lua b/config/nvim/lua/user/plugins/telescope.lua new file mode 100644 index 0000000..1173854 --- /dev/null +++ b/config/nvim/lua/user/plugins/telescope.lua @@ -0,0 +1,183 @@ +local config_telescope = function(_, opts) + local telescope = require 'telescope' + local actions = require 'telescope.actions' + local actions_layout = require 'telescope.actions.layout' + local builtin = require 'telescope.builtin' + + local mappings = { + [''] = actions_layout.cycle_layout_next, + [''] = actions_layout.toggle_mirror, + [''] = actions.smart_send_to_qflist + actions.open_qflist, + } + + local mappings_normal_mode = mappings + local mappings_insert_mode = vim.tbl_extend('force', mappings, { + [''] = actions.cycle_history_next, + [''] = actions.cycle_history_prev, + }) + + telescope.setup { + defaults = { + prompt_prefix = ' ❯ ', + selection_caret = ' ', -- Other ideas: ➔  + multi_icon = ' ', + + layout_strategy = 'flex', + layout_config = { + anchor = 'center', + width = 0.9, + height = 0.9, + + flex = { + flip_columns = 130, + }, + + horizontal = { + preview_width = 0.5, + preview_cutoff = 130, + }, + + vertical = { + preview_height = 0.5, + }, + }, + + cycle_layout_list = { + { layout_strategy = 'bottom_pane', layout_config = { width = 1, height = 0.4 }, }, + 'horizontal', + 'vertical', + }, + + mappings = { + i = mappings_insert_mode, + n = mappings_normal_mode, + }, + }, + + pickers = { + buffers = { prompt_title = ' ﬘ Buffers ' }, + find_files = { prompt_title = '  Files ' }, + git_commits = { prompt_title = '  Commits ' }, + help_tags = { prompt_title = '  Help tags ' }, + keymaps = { prompt_title = '  Keymaps ' }, + live_grep = { prompt_title = '  Live grep ' }, + vim_options = { prompt_title = '  Vim options ' }, + man_pages = { prompt_title = '  Man pages ' }, + }, + + extensions = { + file_browser = { + theme = 'ivy', + mappings = { + n = { + -- normal mode mappings go here + }, + i = { + -- insert mode mappings go here + }, + }, + }, + }, + } + + local selected_range = function() + local _, s_row, s_col, _ = unpack(vim.fn.getpos('v')) + local _, e_row, e_col, _ = unpack(vim.fn.getpos('.')) + + local mode = vim.api.nvim_get_mode().mode + local visual_line = (mode == 'V' or mode == 'CTRL-V') + + if s_row < e_row or (s_row == e_row and s_col <= e_col) then + if visual_line then s_col, e_col = 1, #vim.fn.getline(e_row) end + return s_row - 1, s_col - 1, e_row - 1, e_col + else + if visual_line then e_col, s_col = 1, #vim.fn.getline(s_row) end + return e_row - 1, e_col - 1, s_row - 1, s_col + end + end + + local selected_text = function() + local r0, c0, r1, c1 = selected_range() + return vim.fn.join(vim.api.nvim_buf_get_text(0, r0, c0, r1, c1, {}), '\n') + end + + local custom = { + all_files = function() + builtin.find_files { + prompt_title = '  ALL Files ', + hidden = true, + no_ignore = true, + no_ignore_parent = true, + } + end, + + dotfiles = function() + builtin.find_files { + prompt_title = '  Find dotfiles ', + cwd = '~/.dotfiles', + hidden = true, + } + end, + + grep_visual = function() + local selection = selected_text() + builtin.grep_string { + prompt_title = string.format('  Grep: %s', selection), + search = selection, + } + end, + + man_pages = function() + -- Fix for macOS Ventura onwards (macOS 13.x <-> Darwin 22.x). + -- See: https://github.com/nvim-telescope/telescope.nvim/issues/2326#issuecomment-1407502328 + local uname = vim.loop.os_uname() + local sysname = string.lower(uname.sysname) + if sysname == "darwin" then + local major_version = tonumber(vim.fn.matchlist(uname.release, [[^\(\d\+\)\..*]])[2]) or 0 + if major_version >= 22 then + builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", "." } } + else + builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", " " } } + end + elseif sysname == "freebsd" then + builtin.man_pages { sections = { 'ALL' }, man_cmd = { "apropos", "." } } + else + builtin.man_pages { sections = { 'ALL' } } + end + end, + } + + local map = vim.keymap.set + map('n', 'fa', custom.all_files, { desc = ' [F]ind [A]ll Files in $PWD' }) + map('n', 'fb', builtin.buffers, { desc = ' [F]ind [B]uffers' }) + map('n', 'fc', builtin.git_commits, { desc = ' [F]ind [C]ommits' }) + map('n', 'fd', custom.dotfiles, { desc = ' [F]ind [D]otfiles' }) + map('n', 'ff', builtin.find_files, { desc = ' [F]ind [F]iles in $PWD' }) + map('n', 'fg', builtin.live_grep, { desc = ' [F]ind with [G]rep in $PWD' }) + map('n', 'fh', builtin.help_tags, { desc = ' [F]ind [H]elp tags' }) + map('n', 'fk', builtin.keymaps, { desc = ' [F]ind [K]eymaps' }) + map('n', 'fm', custom.man_pages, { desc = ' [F]ind [M]an pages' }) + map('n', 'fo', builtin.vim_options, { desc = ' [F]ind vim [O]ptions' }) + map('n', 'fs', builtin.grep_string, { desc = ' [F]ind [S]tring' }) + map('v', 'fs', custom.grep_visual, { desc = ' [F]ind visual [S]election' }) +end + +file_browser = { + 'nvim-telescope/telescope-file-browser.nvim', + + config = function() + require('telescope').load_extension 'file_browser' + vim.keymap.set('n', 'br', 'Telescope file_browser', { desc = ' file [BR]owser' }) + end, +} + +return { + 'nvim-telescope/telescope.nvim', + + config = config_telescope, + + dependencies = { + file_browser, + }, +} + diff --git a/config/nvim/lua/user/plugins/treesitter.lua b/config/nvim/lua/user/plugins/treesitter.lua new file mode 100644 index 0000000..14aa274 --- /dev/null +++ b/config/nvim/lua/user/plugins/treesitter.lua @@ -0,0 +1,102 @@ +return { + 'nvim-treesitter/nvim-treesitter', + + dependencies = { + 'nvim-treesitter/nvim-treesitter-refactor', + 'nvim-treesitter/nvim-treesitter-textobjects', + 'nvim-treesitter/playground', + }, + + opts = { + ensure_installed = { + 'bash', + 'c', + 'cpp', + 'haskell', + 'html', + 'javascript', + 'latex', + 'lua', + 'make', + 'markdown', + 'markdown_inline', + 'python', + 'query', + 'toml', + 'vim', + 'vimdoc', + 'yaml', + }, + + highlight = { + enable = true, + disable = { + 'help', + }, + }, + + incremental_selection = { + enable = true, + keymaps = { + init_selection = 'gnn', -- mapped in normal mode + node_incremental = '', -- mapped in visual mode + node_decremental = '', -- mapped in visual mode + scope_incremental = nil, -- disabled, normally mapped in visual mode + }, + }, + + refactor = { + highlight_definitions = { enable = true }, + highlight_current_scope = { enable = false }, + + smart_rename = { + enable = true, + keymaps = { + smart_rename = 'grr', + }, + }, + + navigation = { + enable = true, + keymaps = { + goto_definition = 'gd', -- default: 'gnd' + list_definitions = nil, -- disabled, default: 'gnD' + list_definitions_toc = 'gO', + goto_next_usage = '', + goto_previous_usage = '', + }, + }, + }, + + textobjects = { + select = { + enable = true, + keymaps = { + ['ab'] = '@block.outer', + ['ib'] = '@block.inner', + ['ac'] = '@conditional.outer', + ['ic'] = '@conditional.inner', + ['af'] = '@function.outer', + ['if'] = '@function.inner', + ['al'] = '@loop.outer', + ['il'] = '@loop.inner', + ['aa'] = '@parameter.outer', + ['ia'] = '@parameter.inner', + }, + }, + }, + + playground = { + enable = true, + }, + }, + + config = function(_, opts) + require('nvim-treesitter.configs').setup(opts) + + vim.keymap.set('n', 'sp', 'TSPlaygroundToggle') + vim.keymap.set('n', 'sh', 'TSHighlightCapturesUnderCursor') + vim.keymap.set('n', 'sn', 'TSNodeUnderCursor') + end, +} + diff --git a/config/nvim/lua/user/plugins/vim-better-whitespace.lua b/config/nvim/lua/user/plugins/vim-better-whitespace.lua new file mode 100644 index 0000000..773c987 --- /dev/null +++ b/config/nvim/lua/user/plugins/vim-better-whitespace.lua @@ -0,0 +1,22 @@ +return { + 'ntpeters/vim-better-whitespace', + + init = function() + vim.g.better_whitespace_filetypes_blacklist = { + 'diff', + 'fugitive', + 'git', + 'gitcommit', + 'help', + } + end, + + config = function() + -- fix whitespace + vim.keymap.set('n', 'w', 'StripWhitespace') + + -- show/hide whitespace + vim.keymap.set('n', 'sw', 'ToggleWhitespace') + end, +} + diff --git a/config/nvim/lua/user/plugins/virt-column.lua b/config/nvim/lua/user/plugins/virt-column.lua new file mode 100644 index 0000000..fdfd0c7 --- /dev/null +++ b/config/nvim/lua/user/plugins/virt-column.lua @@ -0,0 +1,20 @@ +return { + 'lukas-reineke/virt-column.nvim', + + config = function() + require('virt-column').setup { + char = '│', + } + + local toggle_virtual_column = function() + if vim.o.colorcolumn == '' then + vim.o.colorcolumn = '+1' -- one after 'textwidth' + else + vim.o.colorcolumn = '' -- none + end + end + + vim.keymap.set('n', 'sc', toggle_virtual_column) + end, +} + diff --git a/config/nvim/lua/user/plugins/visual-multi.lua.disabled b/config/nvim/lua/user/plugins/visual-multi.lua.disabled new file mode 100644 index 0000000..12ab6ef --- /dev/null +++ b/config/nvim/lua/user/plugins/visual-multi.lua.disabled @@ -0,0 +1,9 @@ +return { + 'mg979/vim-visual-multi', + + init = function() + vim.g.VM_leader = '\\' + vim.g.VM_silent_exit = 1 + end, +} +