Skip to content

Instantly share code, notes, and snippets.

@mlongval
Last active June 12, 2024 18:26
Show Gist options
  • Save mlongval/e793c1038cf902f566112a89922c5af5 to your computer and use it in GitHub Desktop.
Save mlongval/e793c1038cf902f566112a89922c5af5 to your computer and use it in GitHub Desktop.
Map Backspace to Exit VIM if on top left corner (beginning of buffer)
" 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment