File tree Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Expand file tree Collapse file tree 1 file changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -137,15 +137,23 @@ function M.is_windows_exe(ext)
137
137
return pathexts [ext :upper ()]
138
138
end
139
139
140
- function M .rename_loaded_buffers (old_name , new_name )
140
+ function M .rename_loaded_buffers (old_path , new_path )
141
141
for _ , buf in pairs (a .nvim_list_bufs ()) do
142
142
if a .nvim_buf_is_loaded (buf ) then
143
- if a .nvim_buf_get_name (buf ) == old_name then
144
- a .nvim_buf_set_name (buf , new_name )
145
- -- to avoid the 'overwrite existing file' error message on write
146
- vim .api .nvim_buf_call (buf , function ()
147
- vim .cmd " silent! w!"
148
- end )
143
+ local buf_name = a .nvim_buf_get_name (buf )
144
+ local exact_match = buf_name == old_path
145
+ local child_match = (
146
+ buf_name :sub (1 , # old_path ) == old_path and buf_name :sub (# old_path + 1 , # old_path + 1 ) == path_separator
147
+ )
148
+ if exact_match or child_match then
149
+ a .nvim_buf_set_name (buf , new_path .. buf_name :sub (# old_path + 1 ))
150
+ -- to avoid the 'overwrite existing file' error message on write for
151
+ -- normal files
152
+ if a .nvim_buf_get_option (buf , " buftype" ) == " " then
153
+ a .nvim_buf_call (buf , function ()
154
+ vim .cmd " silent! write!"
155
+ end )
156
+ end
149
157
end
150
158
end
151
159
end
You can’t perform that action at this time.
0 commit comments