2011-02-16 29 views
3

当前在我的.vimrc文件中,我有一个函数可以在保存鼠标位置时清除保存时的所有尾随空格。Vim清除隐藏字符的函数

fun! <SID>StripTrailingWhitespaces() 
    let l = line(".") 
    let c = col(".") 
    %s/\s\+$//e 
    call cursor(l, c) 
endfun 

autocmd BufWritePre *.sql,*.php :call <SID>StripTrailingWhitespaces() 

This works great。但我想一些事情添加到它想:
*删除回车
*修正缩进SP之后按下TAB键

我尝试添加

%s/^ M // Ë

StripTailingWhitespaces()功能,但是当我现在救VIM告诉我

按ENTER或键入命令继续

所以我觉得我做错了什么或忘了什么。任何帮助搞清楚这一点?谢谢

更新:仍在解决此问题。我尝试在StripTrailingWhitespaces函数以及BufWritePre命令末尾搜索时添加<CR>。没有运气。实际上,添加它会导致很多“拖尾空间”错误。还有什么建议?

如果没有一个用于修复需要按下输入的问题,那么如何修复缩进SP后跟一个TAB?

回答

1

我与

fun! S() 
    let l = line(".") 
    let c = col(".") 
    %s/\s\+$//e 
    %s/^M//e 
    call cursor(l, c) 
endfun 

测试,它的Vim 7.3完美工作(注:^ M进入用CTRL-V CTRL-M)

因此,它看起来就像你不做任何错事,没有忘记任何事情。

现在,这并没有帮助你走得更远,是吗?

如果您有此消息,请尝试:messages,也许这会给您一个提示。

此外,:help messages读取

Press ENTER or type command to continue 

This message is given when there is something on the screen for you to read, 
and the screen is about to be redrawn: 
- After executing an external command (e.g., ":!ls" and "="). 
- Something is displayed on the status line that is longer than the width of 
    the window, or runs into the 'showcmd' or 'ruler' output. 

所以,这部分可能是值得一读的(这是一个比我粘贴更长)。

+0

谢谢你的尝试。我在vim 7.1.138上。这可能是问题吗? – clang1234 2011-02-17 15:58:56