Last active
June 12, 2024 18:26
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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