I try create a map for open ~/.vimrc, but open the ~/.vimrc only when the buffer is empty, else split and open.
I try this
fun! BufferIsEmpty() "{{{
if line('$') == 1 && getline(1) == ''
return 1
else
return 0
endif
endf "}}}
fun! NotEmptySplit() "{{{
if !BufferIsEmpty()
sp
endif
return
endf
command! -nargs=0 NotEmptySplit call NotEmptySplit()
nnoremap <silent><leader>ve :NotEmptySplit <bar> ~/.vimrc<CR>
but I get this error
E488: Trailing characters
To take kev’s excellent answer a bit further:
How about pulling out a generic ‘open file in split if buffer not empty’ function.