Create new file but not open buffer in Vim netrw

I have VIM's netrw split option to open any file in the right pre-buffer and it works great.

My problem is that a new file is automatically opened in the netrw buffer when I create a new file with the% command. I want to open the newly created file in the Preview Buffer and not in the netrw buffer. Is it possible?

Thanks for your help in advance.

+3


source to share


1 answer


I think you will have to rewrite 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 preview. It doesn't save the file.

If you just want to create a file without opening it anywhere, you can use an external command touch

(at least on Unix systems).

function! CreateInPreview()
  let l:filename = input("please enter filename: ")
  execute 'silent !touch ' . b:netrw_curdir.'/'.l:filename 
  redraw!
endf

      

+3


source







All Articles