Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a new file but not open a buffer in Vim netrw

Tags:

vim

netrw

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.

like image 798
Joe Cho Avatar asked Aug 06 '17 20:08

Joe Cho


1 Answers

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
like image 85
Doktor OSwaldo Avatar answered Nov 05 '22 10:11

Doktor OSwaldo