1

I try to write a function to toggle my mappings in Vim script.

Here are the steps I have tested it:

  1. I load my vim. (open a file)
  2. Check my mapping in command mode with :imap and I can see mapping(etc. i ffff ...)
  3. I press F6 to toggle the function
  4. I got error message: No such mapping
  5. I check my mapping in command mode with :imap again and I see the mapping(i ffff ...)
  6. In command mode, I can use iunmpa ffff to unmap the ffff :iunmap ffff
  7. The mapping is gone.(I can check with :imap)

Does anyone get any idea why iunmap is not working inside my Vim script?

Here is code

nnoremap <F6>    :call ToggleBracketGroup()<CR>
let g:bracketmap = 1
function! ToggleBracketGroup()
    if g:bracketmap == 1
        inoremap <buffer> ffff    print("cool")
        let g:bracketmap = 0
    else
        **iunmap <buffer> ffff**
        let g:bracketmap = 1
    endif
endfunction
1

The issue with above code is there is space after ffff,

I have to remove the space after ffff and it works perfectly

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.