Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/vim/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于清除隐藏字符的Vim函数_Vim - Fatal编程技术网

用于清除隐藏字符的Vim函数

用于清除隐藏字符的Vim函数,vim,Vim,目前在我的.vimrc文件中,我有一个函数,可以在保存时清除所有尾随空格,同时保留鼠标位置 fun! <SID>StripTrailingWhitespaces() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfun autocmd BufWritePre *.sql,*.php :call <SID>StripTrailingWhitespaces() 有趣!

目前在我的.vimrc文件中,我有一个函数,可以在保存时清除所有尾随空格,同时保留鼠标位置

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

autocmd BufWritePre *.sql,*.php :call <SID>StripTrailingWhitespaces()
有趣!StripTrailingWhitespaces()
设l=直线(“.”)
设c=col(“.”)
%s/\s\+$//e
调用游标(l,c)
结束
autocmd BufWritePre*.sql,*.php:call StripTrailingWhitespaces()
这很有效。但我想补充一些东西,比如:
*删除回车符
*固定缩进SP,后跟一个制表符

我试着加上

%s/^M//e

到我的
StripTailingWhitespaces()
函数,但是当我现在保存时,vim告诉我

按ENTER键或键入命令继续

所以我觉得我做错了什么,或者忘记了什么。能帮我弄清楚吗?谢谢

更新:仍在处理此问题。我已尝试在
StripTrailingWhitespaces
函数中的搜索结束时以及
BufWritePre
命令结束时添加
。不走运。事实上,添加它会给我带来很多“尾随空格”错误。还有什么建议吗

如果不是用来解决需要按enter键的问题的,那么先搜索以修复缩进SP,然后再搜索一个选项卡怎么样?

我已经用它进行了测试

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
,这可能会给您一个提示

另外,
:帮助消息

  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.

因此,这一节可能值得一读(它比我粘贴的那一节长)。

谢谢您的尝试。我在vim 7.1.138上。这可能就是问题所在吗?我对此表示怀疑(尽管我不是100%确定)