简体   繁体   English

vim:插入模式问题:.vimrc中的remaps(imap)和缩写(ab)不起作用

[英]vim : insert mode problem : remaps (imap) and abbreviations (ab) in .vimrc don't work

I have a problem in vim: If I modify the .vimrc file and add this lines: 我在vim中遇到问题:如果我修改.vimrc文件并添加以下行:

map ;bb A78

it just works in normal mode. 它只是在正常模式下工作。 If I got it, it should work in insert mode too, shouldn't it? 如果我得到它,它也应该在插入模式下工作,不应该吗? While editing, I've verified that everything was read properly (command ":map"): 编辑时,我已经确认所有内容都已正确读取(命令“:map”):

i  ;bb           A78

If I do the same thing with "imap", I got the same problem: command ":imap" shows it's configured, but if I go in insert mode, and type ";bb" or ";bb" or ";bb" nothing is changed, I don't get the A78 如果我用“imap”执行相同的操作,我遇到了同样的问题:命令“:imap”显示它已配置,但如果我进入插入模式,并键入“; bb”或“; bb”或“; bb”什么都没有改变,我没有得到A78

What am I missing? 我错过了什么? (And the marvellous codeSnippet plugin works only in normal mode too, which is a big problem to me) (而且奇妙的codeSnippet插件也只能在正常模式下工作,这对我来说是个大问题)

If forgot to precise: I have only the plugin Tabularize, it's vim version 7.3 under cygwin, but I get the same problem in SSH / Linux Debian / vim version 7.0 如果忘了精确:我只有插件Tabularize,它是cygwin下的vim版本7.3,但我在SSH / Linux Debian / vim 7.0版中遇到同样的问题

If I try to do exactly what written here (to give another try, if it may help), that doesn't work either: "To use the abbreviation, switch to Insert mode and type th, followed by any whitespace above (space, tab, or carriage return)." 如果我尝试完全按照这里所写的内容(如果它可能会有帮助的话再次尝试),那也不起作用:“要使用缩写,切换到插入模式并输入th,然后输入上面的任何空格(空格,标签或回车)。“ doesn't work at all . 没有在所有的工作。 This drives me nuts. 这让我疯狂。

Here follows my .vimrc file, maybe there's something wrong here I didn't see: 这是我的.vimrc文件,也许这里有什么问题我没看到:

set nocompatible
filetype plugin on
syntax enable

set ignorecase
set paste
set ruler
set modeline

set showcmd

set expandtab
set tabstop=2
set autoindent
set smartindent

set number
colorscheme desert

set vb t_vb=

set backup
set backupdir=~/.vim/backup
set directory=~/.vim/tmp
set fileencodings=utf-8,ucs-bom,default,latin1
set scrolloff=5
set undolevels=1000
nmap ;bw :. w! ~/.vimxfer<CR>
nmap ;br :r ~/.vimxfer<CR>
nmap ;ba :. w! >>~/.vimxfer<CR>

" Tell vim to remember certain things when we exit
"  '10 : marks will be remembered for up to 10 previously edited files
"  "100 : will save up to 100 lines for each register
"  :20 : up to 20 lines of command-line history will be remembered
"  % : saves and restores the buffer list
"  n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo

" when we reload, tell vim to restore the cursor to the saved position
augroup JumpCursorOnEdit
 au!
 autocmd BufReadPost *
 \ if expand("<afile>:p:h") !=? $TEMP |
 \ if line("'\"") > 1 && line("'\"") <= line("$") |
 \ let JumpCursorOnEdit_foo = line("'\"") |
 \ let b:doopenfold = 1 |
 \ if (foldlevel(JumpCursorOnEdit_foo) > foldlevel(JumpCursorOnEdit_foo - 1)) |
 \ let JumpCursorOnEdit_foo = JumpCursorOnEdit_foo - 1 |
 \ let b:doopenfold = 2 |
 \ endif |
 \ exe JumpCursorOnEdit_foo |
 \ endif |
 \ endif
 " Need to postpone using "zv" until after reading the modelines.
 autocmd BufWinEnter *
 \ if exists("b:doopenfold") |
 \ exe "normal zv" |
 \ if(b:doopenfold > 1) |
 \ exe "+".1 |
 \ endif |
 \ unlet b:doopenfold |
 \ endif
augroup END

set backspace=2
inoremap <silent> <Bar>   <Bar><Esc>:call <SID>align()<CR>a

function! s:align()
  let p = '^\s*|\s.*\s|\s*$'
  if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
    let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
    let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
    Tabularize/|/l1
    normal! 0
    call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
  endif
endfunction

:autocmd BufNewFile  * silent! 0r ~/.vim/templates/%:e.tpl
:autocmd BufNewFile  *.php call search('w', '', line("w$"))

Thanks a lot! 非常感谢!

You need to make sure that vim is not in "paste" mode. 您需要确保vim不处于“粘贴”模式。

Try 尝试

:set nopaste

map doesn't make the mapping work in insert mode: for ALL modes, you want map! map不会使映射在插入模式下工作:对于所有模式,您需要map! . See :help :map! 请参阅:help :map! for more information on this. 有关这方面的更多信息。

However, imap should work, so you're probably having issues either with timeouts or the 'paste' setting. 但是, imap应该可以工作,因此您可能遇到超时或“粘贴”设置问题。 The way a mapping works in insert mode is that it gives you a certain amount of time to enter the mapping (I think the default is 1 second) and if you type it slower than that it assumes you mean the individual characters. 映射在插入模式下的工作方式是它为您提供了一定的时间来输入映射(我认为默认值是1秒),如果您输入的速度比它慢,则假定您指的是单个字符。 So if you do: 所以,如果你这样做:

:map! ;bb A78

And then type: 然后键入:

;<pause>bb

(where <pause> is just a pause, not something you type) (其中<pause>只是一个暂停,而不是你输入的东西)

You'll get ;bb , but if you type: 你会得到;bb ,但如果你输入:

;bb

really quickly, you'll get A78 . 真的很快,你会得到A78

To find out more about timeouts, have a look at these help pages: 要了解有关超时的更多信息,请查看以下帮助页面:

:help 'timeout'
:help 'ttimeout'
:help 'timeoutlen'
:help 'ttimeoutlen'

The 'paste' option also has an effect: it disables mappings in insert mode and abbreviations. 'paste'选项也有效:它在插入模式和缩写中禁用映射。 Try :set paste? 试试:set paste? to find out if you have this set and :set nopaste to disable it. 找出你是否有这个设置和:set nopaste来禁用它。

See: 看到:

:help 'paste'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM