719 lines
25 KiB
Bash
719 lines
25 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# a collection of addition plugins for neovim with lazy
|
|
DEST=${1:-/etc/skel}
|
|
LAZY_DEST=${DEST}/.config/nvim/lua/plugins
|
|
|
|
# conf-print() {
|
|
# cat <<-EOF
|
|
#
|
|
# EOF
|
|
# }
|
|
# conf_print > ${DEST}
|
|
|
|
# nvim-dap Debug Adapter Protocol client
|
|
# https://microsoft.github.io/debug-adapter-protocol/implementors/adapters/
|
|
# nvim-dap-python An extension for nvim-dap for python debug, test methods or classes.
|
|
conf_print_nvim-dap() {
|
|
cat <<-EOF
|
|
return {
|
|
{
|
|
"mfussenegger/nvim-dap",
|
|
optional = true,
|
|
dependencies = {
|
|
"mfussenegger/nvim-dap-python",
|
|
keys = {
|
|
{ "<leader>dPt", function() require('dap-python').test_method() end, desc = "Debug Method", ft = "python" },
|
|
{ "<leader>dPc", function() require('dap-python').test_class() end, desc = "Debug Class", ft = "python" },
|
|
},
|
|
config = function()
|
|
local path = require("mason-registry").get_package("debugpy"):get_install_path()
|
|
require("dap-python").setup(path .. "/venv/bin/python")
|
|
end,
|
|
},
|
|
}
|
|
}
|
|
EOF
|
|
}
|
|
|
|
conf_print_nvim-dap >"${LAZY_DEST}/nvim-dap-python.lua"
|
|
|
|
|
|
# https://github.com/folke/lazy.nvim
|
|
conf-print-nvim-lazygit() {
|
|
cat <<-EOF
|
|
require("lazy").setup({
|
|
{
|
|
"kdheepak/lazygit.nvim",
|
|
cmd = {
|
|
"LazyGit",
|
|
"LazyGitConfig",
|
|
"LazyGitCurrentFile",
|
|
"LazyGitFilter",
|
|
"LazyGitFilterCurrentFile",
|
|
},
|
|
-- optional for floating window border decoration
|
|
dependencies = {
|
|
"nvim-lua/plenary.nvim",
|
|
},
|
|
-- setting the keybinding for LazyGit with 'keys' is recommended in
|
|
-- order to load the plugin when the command is run for the first time
|
|
keys = {
|
|
{ "<leader>lg", "<cmd>LazyGit<cr>", desc = "LazyGit" }
|
|
}
|
|
},
|
|
})
|
|
EOF
|
|
|
|
conf_print_nvim-lazygit >"${LAZY_DEST}/nvim-lazygit.lua"
|
|
|
|
# FIXME: Not sure where we put these settingsm assuming nvim.conf
|
|
conf_print_nvim-lazygit_map() {
|
|
cat <<-EOF
|
|
let g:lazygit_floating_window_winblend = 0 " transparency of floating window
|
|
let g:lazygit_floating_window_scaling_factor = 0.9 " scaling factor for floating window
|
|
let g:lazygit_floating_window_border_chars = ['╭','─', '╮', '│', '╯','─', '╰', '│'] " customize lazygit popup window border characters
|
|
let g:lazygit_floating_window_use_plenary = 0 " use plenary.nvim to manage floating window if available
|
|
let g:lazygit_use_neovim_remote = 1 " fallback to 0 if neovim-remote is not installed
|
|
|
|
let g:lazygit_use_custom_config_file_path = 0 " config file path is evaluated if this value is 1
|
|
let g:lazygit_config_file_path = '' " custom config file path
|
|
" OR
|
|
let g:lazygit_config_file_path = [] " list of custom config file paths
|
|
|
|
" setup mapping to call :LazyGit
|
|
nnoremap <silent> <leader>gg :LazyGit<CR>
|
|
EOF
|
|
}
|
|
|
|
# conf_print_nvim-lazygit_map > "${LAZY_DEST}"/
|
|
|
|
# https://sw.kovidgoyal.net/kitty/overview/
|
|
# https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/kitty_scrollback_nvim
|
|
# https://github.com/mikesmithgh/kitty-scrollback.nvim?tab=readme-ov-file#-installation
|
|
conf_print_nvim-kitty-scrollback() {
|
|
cat <<-EOF
|
|
{
|
|
'mikesmithgh/kitty-scrollback.nvim',
|
|
enabled = true,
|
|
lazy = true,
|
|
cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' },
|
|
event = { 'User KittyScrollbackLaunch' },
|
|
-- version = '*', -- latest stable version, may have breaking changes if major version changed
|
|
-- version = '^4.0.0', -- pin major version, include fixes and features that do not have breaking changes
|
|
config = function()
|
|
require('kitty-scrollback').setup()
|
|
end,
|
|
}
|
|
EOF
|
|
}
|
|
|
|
conf_print_nvim-kitty-scrollback >"${LAZY_DEST}/nvim-kitty-scrollback.lua"
|
|
|
|
|
|
|
|
# https://github.com/rcarriga/nvim-dap-ui
|
|
conf_print_nvim-dap-ui() {
|
|
cat <<-EOF
|
|
{
|
|
"rcarriga/nvim-dap-ui",
|
|
dependencies = {"mfussenegger/nvim-dap", "nvim-neotest/nvim-nio"}
|
|
}
|
|
EOF
|
|
}
|
|
|
|
|
|
# the command 'Codeium Chat' will start a chat session with the default browser
|
|
# the indexing seems not to work but it is new 02-04-2024
|
|
conf_print_nvim-codeium_enable-chat() {
|
|
cat <<-EOF
|
|
-- ~/.config/nvim/lua/plugins/nvim-codeium_enable-chat.lua
|
|
|
|
-- Assuming you want to configure the codeium plugin
|
|
return {
|
|
"Exafunction/codeium.nvim",
|
|
config = function()
|
|
-- Require the codeium module
|
|
local codeium = require("codeium.config")
|
|
|
|
-- Modify the options to enable chat, local search, and index service
|
|
codeium.options = {
|
|
enable_chat = true,
|
|
enable_local_search = true,
|
|
enable_index_service = true,
|
|
}
|
|
|
|
-- Call the setup function with the modified options
|
|
codeium.setup(codeium.options)
|
|
end,
|
|
}
|
|
EOF
|
|
}
|
|
|
|
conf_print_nvim-codeium_enable-chat >"${LAZY_DEST}/nvim-codeium_enable-chat.lua"
|
|
|
|
|
|
# the key for codeium sometimes gets wiped, put it back
|
|
CODEIUM_KEY_HOME=/home/default/.cache/nvim/codeium/config.json
|
|
|
|
conf_print_nvim-codeium-key() {
|
|
cat <<-EOF
|
|
{"api_key": "c8cbca7c-fabb-42bb-95e2-1c86fe71bd45"}
|
|
EOF
|
|
}
|
|
|
|
|
|
conf_print_nvim-codeium-key >"${CODEIUM_KEY_HOME}"
|
|
|
|
|
|
# an example of allowing fix on save
|
|
conf_print_nvim-lint-markdownlint() {
|
|
cat <<-EOF
|
|
return {
|
|
{
|
|
"mfussenegger/nvim-lint",
|
|
opts = {
|
|
linters = {
|
|
markdownlint = {
|
|
args = { "--fix" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
EOF
|
|
}
|
|
|
|
# conf_print_nvim-lint-markdownlint >"${LAZY_DEST}"/nvim-lint-markdownlint.lua
|
|
|
|
# Turn off .vscode import in neoconf
|
|
# neoconf settings are found in ~/.config/nvim/neoconf.json
|
|
# defaults are in lua/neoconf/config.lua
|
|
conf_print_neoconf_json() {
|
|
cat <<EOF
|
|
{
|
|
"neoconf": {
|
|
"import": {
|
|
"vscode": false,
|
|
"coc": true,
|
|
"nlsp": true
|
|
}
|
|
}
|
|
}
|
|
EOF
|
|
}
|
|
#conf_print_neoconf_json | tee -a "${DEST}/.config/nvim/neoconf.json"
|
|
#
|
|
# Check if the file exists
|
|
if [ -f ~/.config/nvim/neoconf.json ]; then
|
|
# If the file exists, merge the new JSON snippet with the existing content
|
|
conf_print_neoconf_json | jq -s 'reduce .[] as $item ({}; . *= $item)' ~/.config/nvim/neoconf.json - > ~/.config/nvim/neoconf.json.tmp
|
|
mv ~/.config/nvim/neoconf.json.tmp ~/.config/nvim/neoconf.json
|
|
else
|
|
# If the file does not exist, create it with the new JSON snippet
|
|
conf_print_neoconf_json > ~/.config/nvim/neoconf.json
|
|
fi
|
|
|
|
#==============================================================================
|
|
# vim-tmux-navigator.lua within the plugins folder of Lazyvim:
|
|
conf_print_tmux_navigator() {
|
|
cat <<EOF
|
|
return {
|
|
|
|
"christoomey/vim-tmux-navigator",
|
|
|
|
keys = {
|
|
{ "<C-\\>", "<cmd>TmuxNavigatePrevious<cr>", desc = "Go to the previous pane" },
|
|
{ "<C-h>", "<cmd>TmuxNavigateLeft<cr>", desc = "Got to the left pane" },
|
|
{ "<C-j>", "<cmd>TmuxNavigateDown<cr>", desc = "Got to the down pane" },
|
|
{ "<C-k>", "<cmd>TmuxNavigateUp<cr>", desc = "Got to the up pane" },
|
|
{ "<C-l>", "<cmd>TmuxNavigateRight<cr>", desc = "Got to the right pane" },
|
|
},
|
|
}
|
|
EOF
|
|
}
|
|
conf_print_tmux_navigator | tee "${LAZY_DEST}/ns/vim-tmux-navigator.lua"
|
|
#==============================================================================
|
|
# Example with keymap override.
|
|
|
|
# LazyVim overrides the <C-hjkl> keymaps, so only adding the keymaps in the
|
|
# plugin folder did not work and I had to explicitly add the keymaps outside the
|
|
# plugins in keymaps.lua.
|
|
# (e.g vim.keymap.set("n", "<C-j>", ":TmuxNavigateDown<CR>", { silent = true }))
|
|
|
|
conf_print_nvim-tmux() {
|
|
cat <<EOF
|
|
return {
|
|
"alexghergh/nvim-tmux-navigation",
|
|
event = "VeryLazy",
|
|
config = function()
|
|
local nvim_tmux_nav = require("nvim-tmux-navigation")
|
|
nvim_tmux_nav.setup({
|
|
disable_when_zoomed = true,
|
|
-- defaults to false
|
|
keybindings = {
|
|
left = "<C-h>",
|
|
down = "<C-j>",
|
|
up = "<C-k>",
|
|
right = "<C-l>",
|
|
last_active = "<C-\\>",
|
|
next = "<C-Space>",
|
|
},
|
|
})
|
|
end,
|
|
}
|
|
EOF
|
|
}
|
|
conf_print_nvim-tmux | tee "${LAZY_DEST}"/nvim-tmux.lua
|
|
lua/plugins/tmux.lua
|
|
LAZY_DEST=${DEST}/.config/nvim/lua/plugins
|
|
|
|
-- Keymaps are automatically loaded on the VeryLazy event
|
|
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
|
|
-- Add any additional keymaps here: ~/.config/nvim/lua/config/keymaps.lua
|
|
|
|
conf_print_nvim-tmux-keymap() {
|
|
cat <<EOF
|
|
|
|
vim.keymap.set("n", "<C-h>", "<Cmd>NvimTmuxNavigateLeft<CR>", { silent = true })
|
|
vim.keymap.set("n", "<C-j>", "<Cmd>NvimTmuxNavigateDown<CR>", { silent = true })
|
|
vim.keymap.set("n", "<C-k>", "<Cmd>NvimTmuxNavigateUp<CR>", { silent = true })
|
|
vim.keymap.set("n", "<C-l>", "<Cmd>NvimTmuxNavigateRight<CR>", { silent = true })
|
|
vim.keymap.set("n", "<C-\\>", "<Cmd>NvimTmuxNavigateLastActive<CR>", { silent = true })
|
|
vim.keymap.set("n", "<C-Space>", "<Cmd>NvimTmuxNavigateNavigateNext<CR>", { silent = true })
|
|
EOF
|
|
}
|
|
conf_print_nvim-tmux-keymap | tee -a "${LAZY_DEST}"/.config/nvim/lua/config/keymaps.lua
|
|
|
|
~/.tmux.conf
|
|
conf_print_tmux_conf() {
|
|
cat <<EOF
|
|
set -g default-terminal "screen-256color"
|
|
|
|
set -g prefix C-a
|
|
unbind C-b
|
|
bind-key C-a send-prefix
|
|
|
|
unbind %
|
|
bind | split-window -h
|
|
|
|
unbind '"'
|
|
bind - split-window -v
|
|
|
|
unbind r
|
|
bind r source-file ~/.tmux.conf
|
|
|
|
bind -r j resize-pane -D 5
|
|
bind -r k resize-pane -U 5
|
|
bind -r l resize-pane -R 5
|
|
bind -r h resize-pane -L 5
|
|
|
|
bind -r m resize-pane -Z
|
|
|
|
set -g mouse on
|
|
|
|
set-window-option -g mode-keys vi
|
|
|
|
bind-key -T copy-mode-vi 'v' send -X begin-selection # start selecting text with "v"
|
|
bind-key -T copy-mode-vi 'y' send -X copy-selection # copy text with "y"
|
|
|
|
unbind -T copy-mode-vi MouseDragEnd1Pane # don't exit copy mode when dragging with mouse
|
|
|
|
# remove delay for exiting insert mode with ESC in Neovim
|
|
set -sg escape-time 10
|
|
|
|
# tpm plugin
|
|
set -g @plugin 'tmux-plugins/tpm'
|
|
|
|
# list of tmux plugins
|
|
# set -g @plugin 'christoomey/vim-tmux-navigator'
|
|
# THIS IS WHERE THE NEW CODE FOR NAVIGATION IS
|
|
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
|
|
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
|
|
|
|
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
|
|
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
|
|
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
|
|
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
|
|
|
|
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
|
|
|
|
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
|
|
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
|
|
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
|
|
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
|
|
|
|
bind-key -n 'C-Space' if-shell "$is_vim" 'send-keys C-Space' 'select-pane -t:.+'
|
|
|
|
bind-key -T copy-mode-vi 'C-h' select-pane -L
|
|
bind-key -T copy-mode-vi 'C-j' select-pane -D
|
|
bind-key -T copy-mode-vi 'C-k' select-pane -U
|
|
bind-key -T copy-mode-vi 'C-l' select-pane -R
|
|
bind-key -T copy-mode-vi 'C-\' select-pane -l
|
|
bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+
|
|
|
|
|
|
# END FANCY STUFF <---------
|
|
|
|
set -g @plugin 'jimeh/tmux-themepack'
|
|
set -g @plugin 'tmux-plugins/tmux-resurrect' # persist tmux sessions after computer restart
|
|
set -g @plugin 'tmux-plugins/tmux-continuum' # automatically saves sessions for you every 15 minutes
|
|
|
|
set -g @themepack 'powerline/default/cyan'
|
|
|
|
set -g @resurrect-capture-pane-contents 'on'
|
|
set -g @continuum-restore 'on'
|
|
|
|
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
|
|
run '~/.tmux/plugins/tpm/tpm'
|
|
EOF
|
|
}
|
|
# conf_print_tmux_conf | tee ${DEST}/.config/tmux/tmux.conf
|
|
#==============================================================================
|
|
|
|
|
|
# write a lazyvim spec for diffview
|
|
# do not lazy load, it's a library
|
|
|
|
# https://github.com/sindrets/diffview.
|
|
# https://github.com/nvim-lua/plenary.nvim
|
|
# https://github.com/nvim-tree/nvim-web-devicons
|
|
|
|
# return {
|
|
-- add symbols-outline
|
|
{
|
|
"sindrets/diffview.nvim",
|
|
cmd = "diffview",
|
|
keys = { { "<leader>cs", "<cmd>SymbolsOutline<cr>", desc = "Symbols Outline" } },
|
|
opts = {
|
|
-- add your options that should be passed to the setup() function here
|
|
position = "right",
|
|
},
|
|
},
|
|
}
|
|
|
|
require("lazy").setup({
|
|
{
|
|
"sindrets/diffview.nvim",
|
|
cmd = {
|
|
'DiffviewOpen',
|
|
'DiffviewFileHistory',
|
|
'DiffviewClose',
|
|
'DiffviewToggleFiles',
|
|
'DiffviewFocusFiles',
|
|
'DiffviewRefresh'
|
|
},
|
|
dependencies = {
|
|
"nvim-lua/plenary.nvim",
|
|
"nvim-tree/nvim-web-devicons",
|
|
},
|
|
keys = {
|
|
{ "<leader>dv", "<cmd>DiffviewOpen<cr>", desc = "Open Diffview" },
|
|
{ "<leader>df", "<cmd>DiffviewFileHistory<cr>", desc = "Show file history" },
|
|
{ "<leader>dc", "<cmd>DiffviewClose<cr>", desc = "Close Diffview" },
|
|
{ "<leader>dt", "<cmd>DiffviewToggleFiles<cr>", desc = "Toggle file list" },
|
|
{ "<leader>df", "<cmd>DiffviewFocusFiles<cr>", desc = "Focus on file list" },
|
|
{ "<leader>dr", "<cmd>DiffviewRefresh<cr>", desc = "Refresh Diffview" }
|
|
-- Add other keybindings as needed
|
|
}
|
|
config = function()
|
|
require("config.diffview")
|
|
end,
|
|
},
|
|
})
|
|
|
|
|
|
|
|
use {
|
|
"sindrets/diffview.nvim",
|
|
requires = {
|
|
"nvim-lua/plenary.nvim",
|
|
"nvim-tree/nvim-web-devicons",
|
|
},
|
|
after = "plenary.nvim",
|
|
}
|
|
|
|
# packer
|
|
|
|
ui['sindrets/diffview.nvim'] = {
|
|
config = conf.diffview,
|
|
requires = {
|
|
{'nvim-lua/plenary.nvim'},
|
|
{'nvim-tree/nvim-web-devicons'},
|
|
}.
|
|
after='plenary.nvim',
|
|
cmd = {
|
|
'DiffviewOpen',
|
|
'DiffviewFileHistory',
|
|
'DiffviewClose',
|
|
'DiffviewToggleFiles',
|
|
'DiffviewFocusFiles',
|
|
'DiffviewRefresh'
|
|
}
|
|
}
|
|
|
|
config = function()
|
|
-- Lua
|
|
local cb = require'diffview.config'.diffview_callback
|
|
|
|
require'diffview'.setup {
|
|
diff_binaries = false, -- Show diffs for binaries
|
|
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
|
|
use_icons = true, -- Requires nvim-web-devicons
|
|
icons = { -- Only applies when use_icons is true.
|
|
folder_closed = "",
|
|
folder_open = "",
|
|
},
|
|
signs = {
|
|
fold_closed = "",
|
|
fold_open = "",
|
|
},
|
|
file_panel = {
|
|
position = "left", -- One of 'left', 'right', 'top', 'bottom'
|
|
width = 35, -- Only applies when position is 'left' or 'right'
|
|
height = 10, -- Only applies when position is 'top' or 'bottom'
|
|
listing_style = "tree", -- One of 'list' or 'tree'
|
|
tree_options = { -- Only applies when listing_style is 'tree'
|
|
flatten_dirs = true, -- Flatten dirs that only contain one single dir
|
|
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
|
|
},
|
|
},
|
|
file_history_panel = {
|
|
position = "bottom",
|
|
width = 35,
|
|
height = 16,
|
|
log_options = {
|
|
max_count = 256, -- Limit the number of commits
|
|
follow = false, -- Follow renames (only for single file)
|
|
all = false, -- Include all refs under 'refs/' including HEAD
|
|
merges = false, -- List only merge commits
|
|
no_merges = false, -- List no merge commits
|
|
reverse = false, -- List commits in reverse order
|
|
},
|
|
},
|
|
default_args = { -- Default args prepended to the arg-list for the listed commands
|
|
DiffviewOpen = {},
|
|
DiffviewFileHistory = {},
|
|
},
|
|
hooks = {}, -- See ':h diffview-config-hooks'
|
|
key_bindings = {
|
|
disable_defaults = false, -- Disable the default key bindings
|
|
-- The `view` bindings are active in the diff buffers, only when the current
|
|
-- tabpage is a Diffview.
|
|
view = {
|
|
["<tab>"] = cb("select_next_entry"), -- Open the diff for the next file
|
|
["<s-tab>"] = cb("select_prev_entry"), -- Open the diff for the previous file
|
|
["gf"] = cb("goto_file"), -- Open the file in a new split in previous tabpage
|
|
["<C-w><C-f>"] = cb("goto_file_split"), -- Open the file in a new split
|
|
["<C-w>gf"] = cb("goto_file_tab"), -- Open the file in a new tabpage
|
|
["<leader>e"] = cb("focus_files"), -- Bring focus to the files panel
|
|
["<leader>b"] = cb("toggle_files"), -- Toggle the files panel.
|
|
},
|
|
file_panel = {
|
|
["j"] = cb("next_entry"), -- Bring the cursor to the next file entry
|
|
["<down>"] = cb("next_entry"),
|
|
["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry.
|
|
["<up>"] = cb("prev_entry"),
|
|
["<cr>"] = cb("select_entry"), -- Open the diff for the selected entry.
|
|
["o"] = cb("select_entry"),
|
|
["<2-LeftMouse>"] = cb("select_entry"),
|
|
["-"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
|
|
["S"] = cb("stage_all"), -- Stage all entries.
|
|
["U"] = cb("unstage_all"), -- Unstage all entries.
|
|
["X"] = cb("restore_entry"), -- Restore entry to the state on the left side.
|
|
["R"] = cb("refresh_files"), -- Update stats and entries in the file list.
|
|
["<tab>"] = cb("select_next_entry"),
|
|
["<s-tab>"] = cb("select_prev_entry"),
|
|
["gf"] = cb("goto_file"),
|
|
["<C-w><C-f>"] = cb("goto_file_split"),
|
|
["<C-w>gf"] = cb("goto_file_tab"),
|
|
["i"] = cb("listing_style"), -- Toggle between 'list' and 'tree' views
|
|
["f"] = cb("toggle_flatten_dirs"), -- Flatten empty subdirectories in tree listing style.
|
|
["<leader>e"] = cb("focus_files"),
|
|
["<leader>b"] = cb("toggle_files"),
|
|
},
|
|
file_history_panel = {
|
|
["g!"] = cb("options"), -- Open the option panel
|
|
["<C-A-d>"] = cb("open_in_diffview"), -- Open the entry under the cursor in a diffview
|
|
["y"] = cb("copy_hash"), -- Copy the commit hash of the entry under the cursor
|
|
["zR"] = cb("open_all_folds"),
|
|
["zM"] = cb("close_all_folds"),
|
|
["j"] = cb("next_entry"),
|
|
["<down>"] = cb("next_entry"),
|
|
["k"] = cb("prev_entry"),
|
|
["<up>"] = cb("prev_entry"),
|
|
["<cr>"] = cb("select_entry"),
|
|
["o"] = cb("select_entry"),
|
|
["<2-LeftMouse>"] = cb("select_entry"),
|
|
["<tab>"] = cb("select_next_entry"),
|
|
["<s-tab>"] = cb("select_prev_entry"),
|
|
["gf"] = cb("goto_file"),
|
|
["<C-w><C-f>"] = cb("goto_file_split"),
|
|
["<C-w>gf"] = cb("goto_file_tab"),
|
|
["<leader>e"] = cb("focus_files"),
|
|
["<leader>b"] = cb("toggle_files"),
|
|
},
|
|
option_panel = {
|
|
["<tab>"] = cb("select"),
|
|
["q"] = cb("close"),
|
|
},
|
|
},
|
|
}
|
|
end
|
|
}
|
|
|
|
|
|
#==============================================================================
|
|
# To combine the Packer configuration for sindrets/diffview.nvim with the
|
|
# provided Lua configuration for diffview,
|
|
#==============================================================================
|
|
use {
|
|
'sindrets/diffview.nvim',
|
|
config = function()
|
|
-- Lua
|
|
local cb = require'diffview.config'.diffview_callback
|
|
|
|
require'diffview'.setup {
|
|
diff_binaries = false, -- Show diffs for binaries
|
|
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
|
|
use_icons = true, -- Requires nvim-web-devicons
|
|
icons = { -- Only applies when use_icons is true.
|
|
folder_closed = "",
|
|
folder_open = "",
|
|
},
|
|
signs = {
|
|
fold_closed = "",
|
|
fold_open = "",
|
|
},
|
|
file_panel = {
|
|
position = "left", -- One of 'left', 'right', 'top', 'bottom'
|
|
width = 35, -- Only applies when position is 'left' or 'right'
|
|
height = 10, -- Only applies when position is 'top' or 'bottom'
|
|
listing_style = "tree", -- One of 'list' or 'tree'
|
|
tree_options = { -- Only applies when listing_style is 'tree'
|
|
flatten_dirs = true, -- Flatten dirs that only contain one single dir
|
|
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
|
|
},
|
|
},
|
|
file_history_panel = {
|
|
position = "bottom",
|
|
width = 35,
|
|
height = 16,
|
|
log_options = {
|
|
max_count = 256, -- Limit the number of commits
|
|
follow = false, -- Follow renames (only for single file)
|
|
all = false, -- Include all refs under 'refs/' including HEAD
|
|
merges = false, -- List only merge commits
|
|
no_merges = false, -- List no merge commits
|
|
reverse = false, -- List commits in reverse order
|
|
},
|
|
},
|
|
default_args = { -- Default args prepended to the arg-list for the listed commands
|
|
DiffviewOpen = {},
|
|
DiffviewFileHistory = {},
|
|
},
|
|
hooks = {}, -- See ':h diffview-config-hooks'
|
|
key_bindings = {
|
|
disable_defaults = false, -- Disable the default key bindings
|
|
-- The `view` bindings are active in the diff buffers, only when the current
|
|
-- tabpage is a Diffview.
|
|
view = {
|
|
["<tab>"] = cb("select_next_entry"), -- Open the diff for the next file
|
|
["<s-tab>"] = cb("select_prev_entry"), -- Open the diff for the previous file
|
|
["gf"] = cb("goto_file"), -- Open the file in a new split in previous tabpage
|
|
["<C-w><C-f>"] = cb("goto_file_split"), -- Open the file in a new split
|
|
["<C-w>gf"] = cb("goto_file_tab"), -- Open the file in a new tabpage
|
|
["<leader>e"] = cb("focus_files"), -- Bring focus to the files panel
|
|
["<leader>b"] = cb("toggle_files"), -- Toggle the files panel.
|
|
},
|
|
file_panel = {
|
|
["j"] = cb("next_entry"), -- Bring the cursor to the next file entry
|
|
["<down>"] = cb("next_entry"),
|
|
["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry.
|
|
["<up>"] = cb("prev_entry"),
|
|
["<cr>"] = cb("select_entry"), -- Open the diff for the selected entry.
|
|
["o"] = cb("select_entry"),
|
|
["<2-LeftMouse>"] = cb("select_entry"),
|
|
["-"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
|
|
["S"] = cb("stage_all"), -- Stage all entries.
|
|
["U"] = cb("unstage_all"), -- Unstage all entries.
|
|
["X"] = cb("restore_entry"), -- Restore entry to the state on the left side.
|
|
["R"] = cb("refresh_files"), -- Update stats and entries in the file list.
|
|
["<tab>"] = cb("select_next_entry"),
|
|
["<s-tab>"] = cb("select_prev_entry"),
|
|
["gf"] = cb("goto_file"),
|
|
["<C-w><C-f>"] = cb("goto_file_split"),
|
|
["<C-w>gf"] = cb("goto_file_tab"),
|
|
["i"] = cb("listing_style"), -- Toggle between 'list' and 'tree' views
|
|
["f"] = cb("toggle_flatten_dirs"), -- Flatten empty subdirectories in tree listing style.
|
|
["<leader>e"] = cb("focus_files"),
|
|
["<leader>b"] = cb("toggle_files"),
|
|
},
|
|
file_history_panel = {
|
|
["g!"] = cb("options"), -- Open the option panel
|
|
["<C-A-d>"] = cb("open_in_diffview"), -- Open the entry under the cursor in a diffview
|
|
["y"] = cb("copy_hash"), -- Copy the commit hash of the entry under the cursor
|
|
["zR"] = cb("open_all_folds"),
|
|
["zM"] = cb("close_all_folds"),
|
|
["j"] = cb("next_entry"),
|
|
["<down>"] = cb("next_entry"),
|
|
["k"] = cb("prev_entry"),
|
|
["<up>"] = cb("prev_entry"),
|
|
["<cr>"] = cb("select_entry"),
|
|
["o"] = cb("select_entry"),
|
|
["<2-LeftMouse>"] = cb("select_entry"),
|
|
["<tab>"] = cb("select_next_entry"),
|
|
["<s-tab>"] = cb("select_prev_entry"),
|
|
["gf"] = cb("goto_file"),
|
|
["<C-w><C-f>"] = cb("goto_file_split"),
|
|
["<C-w>gf"] = cb("goto_file_tab"),
|
|
["<leader>e"] = cb("focus_files"),
|
|
["<leader>b"] = cb("toggle_files"),
|
|
},
|
|
option_panel = {
|
|
["<tab>"] = cb("select"),
|
|
["q"] = cb("close"),
|
|
},
|
|
},
|
|
}
|
|
end,
|
|
requires = {
|
|
{'nvim-lua/plenary.nvim'},
|
|
{'nvim-tree/nvim-web-devicons'},
|
|
},
|
|
after='plenary.nvim',
|
|
cmd = {
|
|
'DiffviewOpen',
|
|
'DiffviewFileHistory',
|
|
'DiffviewClose',
|
|
'DiffviewToggleFiles',
|
|
'DiffviewFocusFiles',
|
|
'DiffviewRefresh'
|
|
}
|
|
}
|
|
#==============================================================================
|
|
|
|
local diffview = require('diffview')
|
|
|
|
local custom_diff_view = diffview.CDiffView({
|
|
git_toplevel = '/path/to/git/repo',
|
|
left = 'HEAD',
|
|
right = 'HEAD~1',
|
|
files = {
|
|
working = {
|
|
{path = 'file1.txt', status = 'M'},
|
|
{path = 'file2.txt', status = 'A'},
|
|
},
|
|
},
|
|
})
|
|
|
|
-- Example command to open the options panel
|
|
vim.api.nvim_set_keymap('n', '<leader>o', '<cmd>DiffviewOpenOptions<CR>', {noremap = true, silent = true})
|
|
|
|
-- Example command to navigate to the next conflict
|
|
vim.api.nvim_set_keymap('n', '<leader>c', '<cmd>DiffviewNextConflict<CR>', {noremap = true, silent = true})
|
|
|
|
-- Example help command
|
|
vim.api.nvim_set_keymap('n', '<leader>h', '<cmd>DiffviewHelp<CR>', {noremap = true, silent = true})
|
|
|