TransWikia.com

Inconsistent behavior from map

Vi and Vim Asked by StevieD on August 31, 2021

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!

One Answer

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.

Answered by StevieD on August 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP