I'm searching for a command (let's say Ctrl+j) to add to my .vimrc to erase the last character of the line in normal mode, without changing position of the cursor. I'm beginner in this .vimrc language, sorry if it's too easy

2 Answers 2


The normal mode commands would be something like ma$x`a. You can use any mark, and you could map this to a key if you like. I don’t entirely follow the use case, so I probably wouldn’t make a map for this. I might use $xgi if I wanted to jump to the last place I was inserting, or $xg; to jump to last modifications.


If you want to avoid setting marks and moving the cursor, and don't mind a little bit of Vim script, this should work:

:nmap <silent> <leader>d :call setline('.', getline('.')[:-2])<CR>

This depends on what your mapleader global variable is set to, but defaults to backslash, so the mapping will come out as \d.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.