Map Backspace to Exit VIM if on top left corner (beginning of buffer)

1 min read Original article ↗
" Exit Vim if Backspace key at beginning of unmodified buffer (top left)
" Very usefull if you use a terminal file explorer like Ranger
" https://github.com/ranger/ranger
" you can just got into and out of files with Enter and Backspace keys.
" Obviously will notify if buffer is modified and unsaved.
function! ExitAtBufferStart()
if line('.') == 1 && col('.') == 1
quit
else
execute "normal! \<BS>"
endif
endfunction
nnoremap <silent> <BS> :call ExitAtBufferStart()<CR>