vimrc括号自动补全

75 views
Skip to first unread message

Cactus

unread,
Feb 25, 2012, 12:25:26 PM2/25/12
to Vim.cn
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
:inoremap ` ``<ESC>i
function ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
最后的函数以前没问题 现在开始出问题了,说是ClosePair函数已存在 要加感叹号什么的 不知道怎么回事。还有这个函数是干什么用的我也不知
道。好像注释掉都可以。inoremap ] <c-r>=ClosePair(']')<CR>这些干什么的都不知道。
:inoremap ( ()<ESC>i这样的就看得懂。

另外跟xp共享剪切板,如果有换行就不能从vim里面复制出来,没换行就可以。这个有什么改进的么?

闲耘(tm)

unread,
Feb 26, 2012, 12:54:02 AM2/26/12
to vim...@googlegroups.com
:h E124

--
闲耘™ (@hotoo, hotoo.me)




2012/2/26 Cactus <wang...@gmail.com>
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {}<ESC>i
:inoremap } <c-r>=ClosePair('}')<CR>
:inoremap [ []<ESC>i
:inoremap ] <c-r>=ClosePair(']')<CR>
:inoremap < <><ESC>i
:inoremap > <c-r>=ClosePair('>')<CR>
:inoremap " ""<ESC>i
:inoremap ' ''<ESC>i
:inoremap ` ``<ESC>i
function! ClosePair(char)

       if getline('.')[col('.') - 1] == a:char
               return "\<Right>"
       else
               return a:char
       endif
endfunction
最后的函数以前没问题 现在开始出问题了,说是ClosePair函数已存在 要加感叹号什么的 不知道怎么回事。还有这个函数是干什么用的我也不知
道。好像注释掉都可以。inoremap ] <c-r>=ClosePair(']')<CR>这些干什么的都不知道。
:inoremap ( ()<ESC>i这样的就看得懂。

另外跟xp共享剪切板,如果有换行就不能从vim里面复制出来,没换行就可以。这个有什么改进的么?

--
要退订此论坛,请发邮件至 vim-cn+un...@googlegroups.com
更多选项,请通过 http://groups.google.com/group/vim-cn 访问该论坛

Cactus

unread,
Feb 26, 2012, 1:53:04 AM2/26/12
to Vim.cn
ToT :h E124是什么意思啊?还有最后剪切板那里我是说用<C-c><C-v>从gvim里面复制出来,不是点击工具栏的复制按钮。点击的话可
以共享。如果是<C-c>而且有换行就不行,没换行又可以

On 2月26日, 下午1时54分, 闲耘(tm) <hotoo...@gmail.com> wrote:
> :h E124
>
> --
> 闲耘(tm) (@hotoo <https://twitter.com/hotoo>, hotoo.me)
> <http://hotoo.me/>
>
> 2012/2/26 Cactus <wangba...@gmail.com>


>
>
>
>
>
>
>
> > :inoremap ( ()<ESC>i
> > :inoremap ) <c-r>=ClosePair(')')<CR>
> > :inoremap { {}<ESC>i
> > :inoremap } <c-r>=ClosePair('}')<CR>
> > :inoremap [ []<ESC>i
> > :inoremap ] <c-r>=ClosePair(']')<CR>
> > :inoremap < <><ESC>i
> > :inoremap > <c-r>=ClosePair('>')<CR>
> > :inoremap " ""<ESC>i
> > :inoremap ' ''<ESC>i
> > :inoremap ` ``<ESC>i

> > function*!* ClosePair(char)

iceout

unread,
Feb 26, 2012, 11:41:49 PM2/26/12
to vim...@googlegroups.com
:h E124的意思是查看vim的帮助,先看看vim 的基础教程吧

复制的问题,你是自己把<C-C>映射到"+y 的?

2012/2/26 Cactus <wang...@gmail.com>:

Cactus

unread,
Feb 27, 2012, 2:01:05 AM2/27/12
to Vim.cn
汗。。。看了帮助文档,不过还是不太懂,昨天因为别的原因重装过gvim,那个自动补全问题消失了。
复制问题是自己映射的:
vmap <C-c> "yy "复制
vmap <C-x> "yd "剪切
nmap <C-v> "yp "粘帖
vmap <C-v> "yp "粘帖
nmap <C-a> ggvG$ "全选
imap <C-s> <Esc>:wa<cr> "保存
vmap <C-c> "yy "复制
vmap <C-x> "yd "剪切
nmap <C-v> "yp "粘帖
vmap <C-v> "yp "粘帖
nmap <C-a> ggvG$ "全选
imap <C-s> <Esc>:wa<cr> "保存
set clipboard+=unnamed " 与windows共享剪贴板
可能我弄错了,并不是换行不行的问题。感觉就是有两个剪切板吧。感觉只有第一次复制的内容是共享的。


On 2月27日, 下午12时41分, iceout <ice.404....@gmail.com> wrote:
> :h E124的意思是查看vim的帮助,先看看vim 的基础教程吧
>
> 复制的问题,你是自己把<C-C>映射到"+y 的?
>

> 2012/2/26 Cactus <wangba...@gmail.com>:

> > 更多选项,请通过http://groups.google.com/group/vim-cn访问该论坛- 隐藏被引用文字 -
>
> - 显示引用的文字 -

Leiking

unread,
Feb 27, 2012, 9:18:27 AM2/27/12
to vim...@googlegroups.com
autoclose

iceout

unread,
Feb 28, 2012, 11:52:45 PM2/28/12
to vim...@googlegroups.com
你是在Windows下使用vim?
reg不应该使用"y吧,"+或"*吧
http://vim.wikia.com/wiki/Accessing_the_system_clipboard
如果你十分想要使用<C-C>,<C-V>,可以参考Windows下gvim自带的mswin.vim里面的代码
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x

" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y

" CTRL-V and SHIFT-Insert are Paste
map <C-V> "+gP
map <S-Insert> "+gP

cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
" Pasting blockwise and linewise selections is not possible in Insert and
" Visual mode without the +virtualedit feature. They are pasted as if they
" were characterwise instead.
" Uses the paste.vim autoload script.

exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']

imap <S-Insert> <C-V>
vmap <S-Insert> <C-V>


2012/2/27 Cactus <wang...@gmail.com>:

alswl

unread,
Mar 1, 2012, 7:46:24 PM3/1/12
to vim...@googlegroups.com
感谢推荐,蛮好用

--
-----------------------------------------
alswl
Blog: http://log4d.com
Mail: alswlx[a]gmailDOTcom
-----------------------------------------

Leiking

unread,
Mar 5, 2012, 8:31:55 AM3/5/12
to vim...@googlegroups.com
呵呵, It's a pleasure :)
Reply all
Reply to author
Forward
0 new messages