Without the yr mapping (or any other mapping that starts with y), the code does not work. Why?
That's because you're calling feedkeys() with the 'x' option, which will also process the typeahead buffer. So you need the next keypress to be in that buffer in order to execute the full command.
For example, if you type yG, you need the G to be on the buffer at ...
I have this since 2002 it seems
It also handles <end> key
inoremap <silent> <Home> <c-o>@=<SID>HomeLikeVCpp()<cr>
nnoremap <silent> <Home> @=<SID>HomeLikeVCpp()<cr>
vnoremap <silent> <Home> @=<SID>HomeLikeVCpp()<cr>
inoremap <silent> <End> <c-\><c-n>...
This is what I came up with. It is not as short as other options, but seems to
do the job:
let n_ind = indent(line('.'))
let n_col = col('.') - 1
if n_col > n_ind
nmap <Home> :call F_home()<CR>
imap <Home> <C-R>=F_home()<CR>
Yes, it is possible to create a mapping for that.
For example, a mapping that will go to the indent if you're elsewhere in the line, but go to the first character if you're on the indent:
noremap <expr> <Home> col('.') == match(getline('.'), '\S') + 1 ? "\<Home>" : "^"
inoremap <expr> <Home> col('.') == match(getline('.'), '\...
I feel like this is all overly complicated, you can realize this with just a few lines of regex:
This expression will allow you to add a closing tag after the cursor:
- < matches the start of the opening tag
- \w\+ matches the tag content, we include it in braces so that we can use it in the replacement
- > ...