Добавление сокращения для пробелов в vim

501
Krishna

Я пытаюсь добавить следующую аббревиатуру в vim, но она не работает.

 noreabbrev <space><space> .<space> 

Это так же, как в большинстве современных телефонов клавиатура.

так может кто-нибудь сказать мне, что я здесь делаю неправильно и как заставить это работать ??

1

2 ответа на вопрос

1
Ingo Karkat

There are three types of abbreviations: full-id, end-id, non-id, each with particular conditions on the sets of allowed characters. See :help abbreviations. Two spaces aren't allowed in any of them.

You have to use an :inoremap (and live with the inevitable delay with which the first space character will appear in the buffer), or build a complex :inoremap <expr> <Space> that checks the previous character and only then does its magic.

0
Heptite

I quickly hacked this together. Put it in a file called InsertSpace.vim or whatever and either source it from your vimrc, or place it in ~/.vim/plugin/ (~\vimfiles\plugin on Windows):

function! s:InsertSpace() if getline('.')[col('.')-3:col('.')-2] =~ '[^. ]\s$' return "\<bs>. " else return ' ' endif endfunction inoremap <expr> <space> <SID>InsertSpace() 

This isn't going to be perfect, but it can be refined.

Похожие вопросы