1

My .vimrc contains junegunn's implementation of Most Recently Used FZF search:

nmap <Leader><Leader> :FZFMru<CR>

command! FZFMru call fzf#run({
\  'source':  v:oldfiles,
\  'sink':    'e',
\  'options': '-m -x +s',
\  'down':    '40%'})

Recently, while this FZF window is open, I find the up and down keys behave strangely. In normal mode I hit <Leader><Leader>, and the FZF windows opens. Hitting <Up>, <Down>, <Left> or <Right> switches me into insert mode and types respectively A, B, C or D (upper case). Looking at :map I don't see that these keys are mapped to anything, in any mode.

What is going on?

Update: it seems like this is connected to the fzf.vim plugin's using terminal mode - in the floating terminal the arrow keys are mapped to these sequences:

up - "\027[A"
down - "\027[B"
left - "\027[D"
right - "\027[C"

(ie vi-compatible mode, even though within my main Vim session I use set nocompatible and this isn't an issue.) There is a GitHub discussion here. However, it's very hard to figure out under which conditions this occurs.

4
  • I don’t remember what key octal 27 is off the top of my head, but have you mapped the escape key at all?
    – D. Ben Knoble
    Jun 23, 2021 at 12:29
  • @D.BenKnoble no, I haven't Jun 23, 2021 at 12:41
  • 1
    (turns out I had... 😳 ) Aug 20, 2021 at 7:30
  • 1
    @filbranden good idea, done Aug 22, 2021 at 8:39

1 Answer 1

1

This problem was caused by a change I'd made in my .vimrc, a mapping to let me <Esc> to exit terminal mode tnoremap <Esc> <C-\><C-n>:bd!<CR>, identical to this GitHub issue. One solution is to map double escape, eg tnoremap <Esc><Esc> <c-\><c-n>.

Explanation: the issue seems to be that: a) fzf.vim uses terminal mode, which I rarely use; b) I added a terminal-mode modification which only showed up when using this plugin; c) apparently when <Esc> is mapped, Vim temporarily interprets it as a literal escape sequence, so that the arrow keys send ^[OA, etc., which goes from terminal mode back to normal mode, adds a new line and types A. (All of this is explained in many other places, such as here.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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