Skip to content

Commit 256b2c1

Browse files
committed
fix bdelete cmd annoying behavior; update diffview config;
1 parent 4297fb9 commit 256b2c1

File tree

4 files changed

+67
-58
lines changed

4 files changed

+67
-58
lines changed

nvim/lua/user/conf/diffview.lua

+48-44
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
-- Lua
2-
local cb = require'diffview.config'.diffview_callback
2+
local cb = require 'diffview.config'.diffview_callback
33

4-
require'diffview'.setup {
5-
diff_binaries = false, -- Show diffs for binaries
4+
require 'diffview'.setup {
5+
diff_binaries = false, -- Show diffs for binaries
66
enhanced_diff_hl = false, -- See ':h diffview-config-enhanced_diff_hl'
7-
use_icons = true, -- Requires nvim-web-devicons
8-
icons = { -- Only applies when use_icons is true.
7+
use_icons = true, -- Requires nvim-web-devicons
8+
icons = { -- Only applies when use_icons is true.
99
folder_closed = "",
1010
folder_open = "",
1111
},
@@ -14,73 +14,77 @@ require'diffview'.setup {
1414
fold_open = "",
1515
},
1616
file_panel = {
17-
position = "left", -- One of 'left', 'right', 'top', 'bottom'
18-
width = 35, -- Only applies when position is 'left' or 'right'
19-
height = 10, -- Only applies when position is 'top' or 'bottom'
20-
listing_style = "tree", -- One of 'list' or 'tree'
21-
tree_options = { -- Only applies when listing_style is 'tree'
22-
flatten_dirs = true, -- Flatten dirs that only contain one single dir
23-
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
17+
win_config = {
18+
position = "left", -- One of 'left', 'right', 'top', 'bottom'
19+
width = 35, -- Only applies when position is 'left' or 'right'
20+
height = 10, -- Only applies when position is 'top' or 'bottom'
21+
},
22+
listing_style = "tree", -- One of 'list' or 'tree'
23+
tree_options = { -- Only applies when listing_style is 'tree'
24+
flatten_dirs = true, -- Flatten dirs that only contain one single dir
25+
folder_statuses = "only_folded", -- One of 'never', 'only_folded' or 'always'.
2426
},
2527
},
2628
file_history_panel = {
27-
position = "bottom",
28-
width = 35,
29-
height = 16,
29+
win_config = {
30+
position = "bottom",
31+
width = 35,
32+
height = 16,
33+
},
3034
log_options = {
31-
max_count = 256, -- Limit the number of commits
32-
follow = false, -- Follow renames (only for single file)
33-
all = false, -- Include all refs under 'refs/' including HEAD
34-
merges = false, -- List only merge commits
35-
no_merges = false, -- List no merge commits
36-
reverse = false, -- List commits in reverse order
35+
max_count = 256, -- Limit the number of commits
36+
follow = false, -- Follow renames (only for single file)
37+
all = false, -- Include all refs under 'refs/' including HEAD
38+
merges = false, -- List only merge commits
39+
no_merges = false, -- List no merge commits
40+
reverse = false, -- List commits in reverse order
3741
},
3842
},
39-
default_args = { -- Default args prepended to the arg-list for the listed commands
43+
default_args = { -- Default args prepended to the arg-list for the listed commands
4044
DiffviewOpen = {},
4145
DiffviewFileHistory = {},
4246
},
43-
hooks = {}, -- See ':h diffview-config-hooks'
47+
hooks = {}, -- See ':h diffview-config-hooks'
4448
key_bindings = {
45-
disable_defaults = false, -- Disable the default key bindings
49+
disable_defaults = false, -- Disable the default key bindings
4650
-- The `view` bindings are active in the diff buffers, only when the current
4751
-- tabpage is a Diffview.
4852
view = {
49-
["<tab>"] = cb("select_next_entry"), -- Open the diff for the next file
50-
["<s-tab>"] = cb("select_prev_entry"), -- Open the diff for the previous file
51-
["gf"] = cb("goto_file"), -- Open the file in a new split in previous tabpage
52-
["<C-w><C-f>"] = cb("goto_file_split"), -- Open the file in a new split
53-
["<C-w>gf"] = cb("goto_file_tab"), -- Open the file in a new tabpage
54-
["<leader>e"] = cb("focus_files"), -- Bring focus to the files panel
55-
["<leader>b"] = cb("toggle_files"), -- Toggle the files panel.
53+
["<tab>"] = cb("select_next_entry"), -- Open the diff for the next file
54+
["<s-tab>"] = cb("select_prev_entry"), -- Open the diff for the previous file
55+
["gf"] = cb("goto_file"), -- Open the file in a new split in previous tabpage
56+
["<C-w><C-f>"] = cb("goto_file_split"), -- Open the file in a new split
57+
["<C-w>gf"] = cb("goto_file_tab"), -- Open the file in a new tabpage
58+
["<leader>e"] = cb("focus_files"), -- Bring focus to the files panel
59+
["<leader>b"] = cb("toggle_files"), -- Toggle the files panel.
5660
},
5761
file_panel = {
58-
["j"] = cb("next_entry"), -- Bring the cursor to the next file entry
62+
["j"] = cb("next_entry"), -- Bring the cursor to the next file entry
5963
["<down>"] = cb("next_entry"),
60-
["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry.
64+
["k"] = cb("prev_entry"), -- Bring the cursor to the previous file entry.
6165
["<up>"] = cb("prev_entry"),
62-
["<cr>"] = cb("select_entry"), -- Open the diff for the selected entry.
66+
["<cr>"] = cb("select_entry"), -- Open the diff for the selected entry.
6367
["o"] = cb("select_entry"),
6468
["<2-LeftMouse>"] = cb("select_entry"),
65-
["<Space>"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
66-
["S"] = cb("stage_all"), -- Stage all entries.
67-
["U"] = cb("unstage_all"), -- Unstage all entries.
68-
["r"] = cb("restore_entry"), -- Restore entry to the state on the left side.
69-
["R"] = cb("refresh_files"), -- Update stats and entries in the file list.
69+
["<Space>"] = cb("toggle_stage_entry"), -- Stage / unstage the selected entry.
70+
["S"] = cb("stage_all"), -- Stage all entries.
71+
["U"] = cb("unstage_all"), -- Unstage all entries.
72+
["r"] = cb("restore_entry"), -- Restore entry to the state on the left side.
73+
["R"] = cb("refresh_files"), -- Update stats and entries in the file list.
7074
["<tab>"] = cb("select_next_entry"),
7175
["<s-tab>"] = cb("select_prev_entry"),
7276
["gf"] = cb("goto_file"),
7377
["<C-w><C-f>"] = cb("goto_file_split"),
7478
["<C-w>gf"] = cb("goto_file_tab"),
75-
["i"] = cb("listing_style"), -- Toggle between 'list' and 'tree' views
76-
["f"] = cb("toggle_flatten_dirs"), -- Flatten empty subdirectories in tree listing style.
79+
["i"] = cb("listing_style"), -- Toggle between 'list' and 'tree' views
80+
["f"] = cb("toggle_flatten_dirs"), -- Flatten empty subdirectories in tree listing style.
7781
["<leader>e"] = cb("focus_files"),
7882
["<leader>b"] = cb("toggle_files"),
7983
},
8084
file_history_panel = {
81-
["g!"] = cb("options"), -- Open the option panel
82-
["<C-A-d>"] = cb("open_in_diffview"), -- Open the entry under the cursor in a diffview
83-
["y"] = cb("copy_hash"), -- Copy the commit hash of the entry under the cursor
85+
["g!"] = cb("options"), -- Open the option panel
86+
["<C-A-d>"] = cb("open_in_diffview"), -- Open the entry under the cursor in a diffview
87+
["y"] = cb("copy_hash"), -- Copy the commit hash of the entry under the cursor
8488
["zR"] = cb("open_all_folds"),
8589
["zM"] = cb("close_all_folds"),
8690
["j"] = cb("next_entry"),

nvim/lua/user/conf/init.lua

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
local starts_with = function(str, start)
2-
return str:sub(1, #start) == start
3-
end
4-
5-
local ends_with = function(str, ending)
6-
return ending == "" or str:sub(- #ending) == ending
7-
end
81

92

103
local M = {}
114

5+
-- local starts_with = require("user.utils").starts_with
6+
local ends_with = require("user.utils").ends_with
7+
128
M.setup = function()
139
local config_dir = vim.fn.stdpath('config') .. '/lua/user/conf'
1410
-- plugins do not need to load, NOTE: no .lua suffix required

nvim/lua/user/keymaps.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ keymap("n", "<leader>w", ":w<cr>", opts)
4040
-- exit cur window
4141
keymap("n", "<leader>q", ":q<cr>", opts)
4242
-- delete cur buffer
43-
keymap("n", "<leader>d", ":bdelete<cr>", opts)
44-
keymap("n", "<leader>D", ":bdelete<cr>", opts)
43+
keymap("n", "<leader>d", ":bp<bar>sp<bar>bn<bar>bd<CR>", opts)
44+
keymap("n", "<leader>D", ":bp<bar>sp<bar>bn<bar>bd<CR>", opts)
4545
-- exit whole program
4646
keymap("n", "ZZ", ":lua require('user.utils').SaveAndExit()<cr>", opts)
4747
-- remap macro record key

nvim/lua/user/utils.lua

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
local M = {}
22

3+
M.starts_with = function(str, start)
4+
return str:sub(1, #start) == start
5+
end
6+
7+
M.ends_with = function(str, ending)
8+
return ending == "" or str:sub(- #ending) == ending
9+
end
10+
11+
312
M.SaveAndExit = function()
4-
-- wirte all buffer first
5-
vim.api.nvim_command(":wa")
6-
-- quit all buffer
7-
vim.api.nvim_command(":qa")
13+
-- wirte all buffer first
14+
vim.api.nvim_command(":wa")
15+
-- quit all buffer
16+
vim.api.nvim_command(":qa")
817
end
918

1019

@@ -15,7 +24,7 @@ M.GtagsRefernce = function()
1524
vim.api.nvim_command(":copen")
1625
end
1726

18-
M.GtagsText = function()
27+
M.GtagsText = function()
1928
local word = vim.api.nvim_call_function("expand", { "<cword>" })
2029
vim.api.nvim_command(":cs find t " .. word)
2130
vim.api.nvim_command(":copen")

0 commit comments

Comments
 (0)