1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
return {
"mikavilpas/yazi.nvim",
version = "*", -- use the latest stable version
event = "VeryLazy",
dependencies = {
{ "nvim-lua/plenary.nvim", lazy = true },
{
"akinsho/toggleterm.nvim",
version = "*",
config = function()
require("toggleterm").setup({
open_mapping = [[<leader><c-s>]], -- or { [[<c-\>]], [[<c-¥>]] } if you also use a Japanese keyboard.
})
vim.keymap.set(
"n",
"<leader><C-\\>",
"<Cmd>ToggleTerm direction=float name=Terminal<cr>",
{ desc = "Toggle float terminal" }
)
vim.keymap.set(
"n",
"<leader><C-t>",
"<Cmd>ToggleTermToggleAll<cr>",
{ desc = "Toggle all float terminals" }
)
vim.keymap.set("n", "<leader><C-u>", "<Cmd>TermSelect<cr>", { desc = "Select float terminal" })
local function set_opfunc(opfunc)
_G._opfunc = opfunc -- Define the function globally
vim.go.operatorfunc = "v:lua._opfunc" -- Assign the global function
end
local trim_spaces = false
vim.keymap.set("v", "<leader><C-l>", function()
require("toggleterm").send_lines_to_terminal("single_line", trim_spaces, { args = vim.v.count })
end, { desc = "Send line to terminal" })
-- Replace with these for the other two options
-- require("toggleterm").send_lines_to_terminal("visual_lines", trim_spaces, { args = vim.v.count })
-- require("toggleterm").send_lines_to_terminal("visual_selection", trim_spaces, { args = vim.v.count })
-- For use as an operator map:
-- Send motion to terminal
vim.keymap.set("n", "<leader><C-l>", function()
set_opfunc(function(motion_type)
require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
end)
vim.api.nvim_feedkeys("g@", "n", false)
end, { desc = "Send motions to terminal" })
-- Double the command to send line to terminal
vim.keymap.set("n", "<leader><C-a>", function()
set_opfunc(function(motion_type)
require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
end)
vim.api.nvim_feedkeys("g@_", "n", false)
end, { desc = "Send double command to terminal" })
-- Send whole file
vim.keymap.set("n", "<leader><C-g>", function()
set_opfunc(function(motion_type)
require("toggleterm").send_lines_to_terminal(motion_type, false, { args = vim.v.count })
end)
vim.api.nvim_feedkeys("ggg@G''", "n", false)
end, { desc = "Send whole file to terminal (clipboard)" })
end,
},
},
keys = {
{
"<leader>ey",
mode = { "n", "v" },
"<cmd>Yazi<cr>",
desc = "Open yazi at the current file",
},
{
-- Open in the current working directory
"<leader>eY",
"<cmd>Yazi cwd<cr>",
desc = "Open the file manager in nvim's working directory",
},
{
"zy",
"<cmd>Yazi toggle<cr>",
desc = "Resume the last yazi session",
},
},
---@type YaziConfig | {}
opts = {
-- Below is the default configuration. It is optional to set these values.
-- You can customize the configuration for each yazi call by passing it to
-- yazi() explicitly
-- enable this if you want to open yazi instead of netrw.
-- Note that if you enable this, you need to call yazi.setup() to
-- initialize the plugin. lazy.nvim does this for you in certain cases.
--
-- If you are also using neotree, you may prefer not to bring it up when
-- opening a directory:
-- {
-- "nvim-neo-tree/neo-tree.nvim",
-- opts = {
-- filesystem = {
-- hijack_netrw_behavior = "disabled",
-- },
-- },
-- }
open_for_directories = false,
-- open visible splits and quickfix items as yazi tabs for easy navigation
-- https://github.com/mikavilpas/yazi.nvim/pull/359
open_multiple_tabs = false,
-- when yazi is closed with no file chosen, change the Neovim working
-- directory to the directory that yazi was in before it was closed. Defaults
-- to being off (`false`)
change_neovim_cwd_on_close = false,
highlight_groups = {
-- See https://github.com/mikavilpas/yazi.nvim/pull/180
hovered_buffer = nil,
-- See https://github.com/mikavilpas/yazi.nvim/pull/351
hovered_buffer_in_same_directory = nil,
},
-- the floating window scaling factor. 1 means 100%, 0.9 means 90%, etc.
floating_window_scaling_factor = 0.8,
-- the transparency of the yazi floating window (0-100). See :h winblend
yazi_floating_window_winblend = 0,
-- the type of border to use for the floating window. Can be many values,
-- including 'none', 'rounded', 'single', 'double', 'shadow', etc. For
-- more information, see :h nvim_open_win
yazi_floating_window_border = "single",
-- the zindex of the yazi floating window. Can be used to make the yazi
-- window fullscreen. See `:h nvim_open_win()` for more information.
yazi_floating_window_zindex = nil,
-- the log level to use. Off by default, but can be used to diagnose
-- issues. You can find the location of the log file by running
-- `:checkhealth yazi` in Neovim. Also check out the "reproducing issues"
-- section below
log_level = vim.log.levels.OFF,
-- what Neovim should do a when a file was opened (selected) in yazi.
-- Defaults to simply opening the file.
open_file_function = function(chosen_file, config, state) end,
-- customize the keymaps that are active when yazi is open and focused. The
-- defaults are listed below. Note that the keymaps simply hijack input and
-- they are never sent to yazi, so only try to map keys that are never
-- needed by yazi.
--
-- Also:
-- - use e.g. `open_file_in_tab = false` to disable a keymap
-- - you can customize only some of the keymaps (not all of them)
-- - you can opt out of all keymaps by setting `keymaps = false`
keymaps = {
show_help = "<f1>",
open_file_in_vertical_split = "<c-v>",
open_file_in_horizontal_split = "<c-x>",
open_file_in_tab = "<c-t>",
grep_in_directory = "<c-s>",
replace_in_directory = "<c-g>",
cycle_open_buffers = "<tab>",
copy_relative_path_to_selected_files = "<c-y>",
send_to_quickfix_list = "<c-q>",
change_working_directory = "<c-\\>",
open_and_pick_window = "<c-o>",
},
-- completely override the keymappings for yazi. This function will be
-- called in the context of the yazi terminal buffer.
set_keymappings_function = function(yazi_buffer_id, config, context) end,
-- some yazi.nvim commands copy text to the clipboard. This is the register
-- yazi.nvim should use for copying. Defaults to "*", the system clipboard
clipboard_register = "*",
hooks = {
-- if you want to execute a custom action when yazi has been opened,
-- you can define it here.
yazi_opened = function(preselected_path, yazi_buffer_id, config)
-- you can optionally modify the config for this specific yazi
-- invocation if you want to customize the behaviour
end,
-- when yazi was successfully closed
yazi_closed_successfully = function(chosen_file, config, state) end,
-- when yazi opened multiple files. The default is to send them to the
-- quickfix list, but if you want to change that, you can define it here
yazi_opened_multiple_files = function(chosen_files, config, state) end,
-- This function is called when yazi is ready to process events.
on_yazi_ready = function(buffer, config, process_api) end,
},
-- highlight buffers in the same directory as the hovered buffer
highlight_hovered_buffers_in_same_directory = true,
integrations = {
--- What should be done when the user wants to grep in a directory
grep_in_directory = function(directory)
-- the default implementation uses telescope if available, otherwise nothing
end,
grep_in_selected_files = function(selected_files)
-- similar to grep_in_directory, but for selected files
end,
--- Similarly, search and replace in the files in the directory
replace_in_directory = function(directory)
-- default: grug-far.nvim
end,
replace_in_selected_files = function(selected_files)
-- default: grug-far.nvim
end,
-- `grealpath` on OSX, (GNU) `realpath` otherwise
resolve_relative_path_application = "",
-- the way to resolve relative paths. The default_implementation can be
-- customized with a function. See
-- documentation/copy-relative-path-to-files.md for more information.
resolve_relative_path_implementation = function(args, get_relative_path) end,
-- how to delete (close) a buffer. Defaults to a bundled version of
-- `snacks.bufdelete`, copied from https://github.com/folke/snacks.nvim,
-- which maintains the window layout. See the `types.lua` file for more
-- information for the available options.
bufdelete_implementation = "bundled-snacks",
-- add an action to a file picker to copy the relative path to the
-- selected file(s). The implementation is the same as for the
-- `copy_relative_path_to_selected_files` yazi.nvim keymap. Currently
-- only snacks.nvim is supported. Documentation can be found in the
-- keybindings section of the readme.
--
-- available options:
-- - nil (default, no action added)
-- - "snacks.picker" (snacks.nvim)
picker_add_copy_relative_path_action = nil,
},
future_features = {
-- use a file to store the last directory that yazi was in before it was
-- closed. Defaults to `true`.
use_cwd_file = true,
-- use a new shell escaping implementation that is more robust and works
-- on more platforms. Defaults to `true`. If set to `false`, the old
-- shell escaping implementation will be used, which is less robust and
-- may not work on all platforms.
new_shell_escaping = true,
},
},
-- 👇 if you use `open_for_directories=true`, this is recommended
init = function()
-- mark netrw as loaded so it's not loaded at all.
--
-- More details: https://github.com/mikavilpas/yazi.nvim/issues/802
-- vim.g.loaded_netrwPlugin = 1
local wk = require("which-key")
wk.add({
mode = { "n" },
{ "<leader>ey", group = "Yazi" },
})
end,
}
|