Domanda

I have a system to insert a single character in vim- I use :nmap <Space> i_<Esc>r. However, for some reason, this seems to be interfering with my remapping of escape. I remapped escape with :imap kj <Esc>.

Whenever I push kj, vim inserts a _ just before my cursor and then changes what it like I pressed space. I cannot figure out why these things are interacting like this. Can somebody shed some light on the matter? I appreciate it.

Here's my entire vimrc

"general settings
syntax on
filetype plugin on
set number
set smd
set ru

"Leader
let mapleader=','
nmap <Leader>w :w<Enter>
nmap <leader>e :wq<Enter>
nmap <leader>q :q!<Enter>

"remappings
nmap ; :
imap kj <Esc>
nmap <Space> i_<Esc>r

"au comands
au Filetype python source ~/.vim/scripts/python.vim
au Filetype ruby source ~/.vim/scripts/ruby.vim
au Filetype c source ~/.vim/scripts/c.vim
È stato utile?

Soluzione

Change every nmap to nnoremap and every imap to inoremap and see if the problem persists.

Check that you don't have any trailing whitespace.

Read :h 40.1 in full.

Read the chapter on "Strict mapping" in Learn Vimscript the Hard Way.

Altri suggerimenti

You are likely having trailing whitespace in your mapping. In addition to changing *map to *noremap like @glts suggested which will likely change the behavior from inserting text and so on to just moving cursor one position forward (default action for space) and should be done for another reasons explained at links referenced by @glts you should do one of the following to highlight trailing whitespaces:

  1. set list listchars+=trail:-: this will show specially highlighted - in place of trailing whitespaces.
  2. Run search: / $<CR> (/, <Space>, $, <CR>).
  3. Run search using match (can be put in the vimrc): let g:trailing_match_nr=matchadd('Error', '\s\+$'): this will highlight trailing whitespaces with Error highlight group.

Be sure you remove all unneeded trailing whitespaces highlighted by one of these ways. I personally prefer the first one.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top