I wanted to be able to move/rename a currently open file using netrw. The typical concerns are:
- Closing the old buffer
- Actually moving to preserve file attributes (so no :saveas)
I'm aware of some of the plugins and custom functions for this purpose but I wanted to try it using netrw in a single keybind.
Here's what I have so far:
nnoremap <silent> <leader>Sm :argadd<CR>:enew<bar>bd #<CR>:1argdo Explore<CR>
This successfully adds the current file to arglist, opens temporary new buffer, deletes the previous old file buffer, and opens netrw to the dir of the file in arglist.
From there, what I have to do manually is
mA to mark the file from the arglist, then
R to move/rename.
How can I append the last two key-presses to the original mapping? The following does not work for example:
nnoremap <silent> <leader>Sm :argadd<CR>:enew<bar>bd #<CR>:1argdo Explore<CR>mAR
Once netrw is entered, the key-presses seem to stop.
nmap <leader>Sm :let fn=expand('%:t')<bar>enew<bar>bw #<bar>Explore %:p:h<bar>call search(expand(fn))<bar>redraw!<CR>mfR
nmapallowed the key-presses to continue
redraw!allowed me to actually see
enew<bar>bw #<bar>to delete the old buffer