I'll post this as an answer since it seems to have worked for you:
:nnoremap <expr> <Backspace> col('.') == 1 ? 'kgJ' : 'X'
Usually this does the same as the X
Normal-mode command, that deletes one character to the left.
But then it uses an <expr>
mapping to check whether we're executing it on the first column of the line, in which case it uses k
to move up one line followed by gJ
to join lines without adding any spaces between them.
(This mapping has shortcomings, for instance, it won't work with a count.)
My personal recommendation is that you're better off without such a mapping. I find that this kind of mapping will encourage you to use inefficient movements (such as hitting backspace repeatedly) rather than more efficient movements and text objects comprised of words, sentences, paragraphs, blocks, etc.
Instead of a backspace mapping (or even abuse of the X
command), try to use more powerful and efficient motions to select and move around your text in Vim.