1

I've got map that grabs the title and url from the browser and generates a markdown link from it:

inoremap <Leader>gg [<esc>:set fo-=t <cr>:silent !~/bin/copy_safari_title.osa <cr>:let @+ = substitute(@+, '\|', '', 'g') <cr>a<c-r>+](<esc>:let @+=''<cr>:silent !~/bin/copy_safari_url.osa <cr>:let @+ = substitute(@+, '(', '%28', 'g')<cr>:let @+ = substitute(@+, ')', '%29', 'g')<cr>a<c-r>+)<esc>:set fo+=t <cr>a  <left>

When a buffer is first opened and I run this map, it works flawlessly. But the next time it is called, it's hit or miss. It will usually jump up one line and insert the link in the wrong place. Sometimes it jumps several lines. It's really weird and driving me crazy. There doesn't seem to be any rhyme or reason to how it behaves.

The movie below show me doing <leader>gg and it working as expected. Then I drop down two lines and run the same command. This time, it gets inserted in the middle of the previous link.

enter image description here

UPDATE

It gets weirder. I changed the map to this:

inoremap <leader>gg <esc>:set fo-=t <cr>:!~/bin/copy_safari_title.osa <cr>:let @+ = substitute(@+, '\|', '', 'g')<cr>:let @x=@+<cr>:!~/bin/copy_safari_url.osa <cr>:let @+ = substitute(@+, '(', '%28', 'g')<cr>:let @+ = substitute(@+, ')', '%29', 'g')<cr>:let @y=@+<cr>:set fo+=t <cr>:let @z='[' . getreg('x') . '](' . getreg('y') . ')'<cr>"zpa  <left>

But the same thing happens!

1

I don't know why but removing the <left> from the end of map the did the trick. This has got to be some kind of vim bug.

4
  • 2
    Have you mapped esc at all? Can you reproduce this in vim --clean after adding your mapping? You’ll save yourself some headache if you consider using a function for the mapping
    – D. Ben Knoble
    Jul 18 '20 at 12:06
  • vim --clean looking interesting. I am familiar with vim -U none but not the --clean option. I don't think I've mapped <esc> in vim, no. Yeah, I was definitely thinking I should turn this into a function but I'm super lazy and I wanted to figure out what was causing this bug. :)
    – StevieD
    Jul 18 '20 at 14:35
  • To be honest, I’m not sure I see the point of the “left” in the first place :P you use a to append a space, and then move back?
    – D. Ben Knoble
    Jul 18 '20 at 15:27
  • Yeah, it's a really dumb hack. I have an autocmd that trims trailing whitespace from lines. This stops it from doing that.
    – StevieD
    Jul 18 '20 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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