I'm getting some really weird behavior when trying to write a simple keybinding in my vimrc. the following key map:
nnoremap <F2> gdi
only works if the cursor is not over the first declaration of a variable. If it is, it won't go into insert mode.
This is the code sample I'm working with:
hangman :: IO () hangman = do word <- getLine guessword word $ concat $ replicate (length word) "-" guessword :: String -> String -> IO () guessword a b = do putStrLn b guess <- getLine
If I open the file and run the command on the first instance of "hangman", it just won't enter insert mode. If I run it on the second instance, it will.
But if I just type gdi manually (without using the key binding), it will always enter insert mode, wherever I type it.
Why this discrepancy between running the key binding and actually typing the command in Vim? Can anyone else reproduce this issue?
I'm using neovim if it matters.
EDIT: It appears that the key binding is actually dropping any key presses after gd. Anything I add to the key binding after gd is disregarded, but only if I'm on the first instance of the match.
To get around this, I'm using the following workaround using a regex:
nnoremap <expr> <leader>r "gg:/\\<" .expand("<cword>") . "\\>/<CR>
which allows me do what I was originally intending to do, which was write a key binding that renames a variable. The following works for me:
nnoremap <expr> <leader>r "gg:/\\<" .expand("<cword>") . "\\>/<CR>cgn" . input("Enter new name: ") . "<esc>:%norm .<CR><C-O>"