I have VIM netrw split setting to open any file in a right-side Preview Buffer, and it works fine.
My problem is that a new file is automatically open in netrw buffer, when I create the new file by % command. I want to open the new created file in Preview Buffer, not in netrw buffer. Is this possible?
Thanks for your help in advance.
I think you will have to overwrite the mapping.
autocmd filetype netrw call Netrw_mappings()
function! Netrw_mappings()
noremap <buffer>% :call CreateInPreview()<cr>
endfunction
In this function you will have to rebuild the netrw function, but it is not that hard:
function! CreateInPreview()
let l:filename = input("please enter filename: ")
execute 'pedit ' . b:netrw_curdir.'/'.l:filename
endf
Note: this only opens the buffer in the preview. It does not save the file.
If you just want to create the file, without opening it anywhere, you can use the external command touch
(At least in Unix systems).
function! CreateInPreview()
let l:filename = input("please enter filename: ")
execute 'silent !touch ' . b:netrw_curdir.'/'.l:filename
redraw!
endf
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With