Reputation: 159
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.
Upvotes: 8
Views: 3221
Reputation: 1
A simple solution is that you can simply run the normal bash command in the netrw :!touch test.txt
. This way you can create a file and netrw will not enter into the file.
Upvotes: 0
Reputation: 6026
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
Upvotes: 5