3

My Vim (8.0) has started launching in command mode with the value :2R.

I keep my vimrc in a git repo, so I checked out previous commits until I got to a point where the weird behaviour stopped. The git diff between the last functioning commit and the first one with the error is simply:

diff --git a/.vim/common.vim b/.vim/common.vim
index a5b2443..bb209c3 100644
--- a/.vim/common.vim
+++ b/.vim/common.vim
@@ -13,27 +13,28 @@ noremap ( zz
 nnoremap Y y$

 " Find my way around inside text objects
-map [[ "_yaB
-map ]] "_yaB%
-map [b "_yab
-map ]b "_yab%
-map [d "_ya]
-map ]d "_ya]%
+noremap [[ "_yaB
+noremap ]] "_yaB%
+noremap [b "_yab
+noremap ]b "_yab%
+noremap [d "_ya]
+noremap ]d "_ya]%

-map [s (
-map }s )
+noremap [s (
+noremap ]s )

 " Various C-macros
-nmap <C-n> nzz
-nmap <C-a> W50i <Esc>B50ldwBj
-nmap <C-u> ElldwBj
-nmap <C-f> }?function<Enter>{jVN/{<Enter>%
+nnoremap <C-n> nzz
+nnoremap <C-a> W50i <Esc>B50ldwBj
+nnoremap <C-u> ElldwBj
+nnoremap <C-f> }?function<Enter>{jVN/{<Enter>%
 nnoremap <C-c> mwA;<Esc>`w
 nnoremap <C-o> mwO<Esc>0Dj`w
 nnoremap <C-.> mwo<Esc>0Dk`w

 " Give it back
-nnoremap <C-p> <C-o>
+nnoremap <C-[> <C-o>
+nnoremap <C-]> <C-p>

 " for search highlighting
 set hlsearch

How on earth would this change cause this behaviour?

Related: Strange symbol in vim command line after start suggests it's a misconfigured TERM environment variable, but I certainly didn't change that manually and comparing the output of env for the two commits shows no difference.

Edit: I traced it back to the line

nnoremap <C-[> <C-o>

This must be a problem because I'm remapping the escape key. I'm embarrassed I didn't think about that.

I still wonder how that could possibly manifest in the behaviour I saw, so any explanations would be welcome.

Igid
  • 515
  • 4
  • 15
  • why don't you try making some of these changes until you determine the specific line that caused the problem? – jeremysprofile Jan 25 '19 at 19:58
  • @jeremysprofile you're right, I should've done that. I've updated my question in light of that. – Igid Jan 26 '19 at 08:50
  • 1
    Basically, [vim uses the escape key during startup](https://vi.stackexchange.com/a/2620/17205), so it doesn't correctly execute its startup commands. – jeremysprofile Jan 27 '19 at 00:24
  • The `:2R` thing only happens to me when outside tmux. But still, [mapping causes bizarre arrow behavior](https://stackoverflow.com/q/11940801/9157799). – M Imam Pratama Nov 01 '21 at 04:31

1 Answers1

1

The Linux terminal uses ANSI escape sequences (i.e. strings of characters starting with <Esc>) to send special keys to Vim, and as part of the communication protocol with which the application queries for its capabilities. Your mapping interferes with that, and thereby leads to these "strange" behaviors.

Therefore, don't map <Esc>. Use another key. The problem is less pronounced in GVIM, but I wouldn't recommend it there, neither. If you absolutely want a mapping for <Esc>, only define it after Vim has fully started up, via :autocmd VimEnter * nnoremap <Esc> ...

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324