2011-02-02 128 views
2

我需要在数千个文件上执行vim命令,而不会受到交互模式缓慢的影响。我想:在没有交互模式的情况下执行vim命令

 
    find ... | xargs vim '+set fileencoding=utf-8 | x' 

 
    for file in ... ; do 
     vim '+set fileencoding=utf-8 | x' $file 
    done 

但它太慢了,我必须警告

 
Vim : Warning : Output is not to a terminal 

是无法避免的vim交互模式?

PS:我,否则可以使用iconv,但它会导致错误与文件> 32 KO

 
    iconv --from-code=ISO-8859-1 --to-code=UTF-8 $file -o $file 
+0

“但它会导致文件> 32 KO的错误” - 是应该阅读“kb”而不是“ko”? – 2011-02-02 18:44:30

回答

3

我会做:

find .... -print0 | xargs -0 vim -c 'argdo set fenc=utf8' -c 'wqa' 
+0

我的完整find命令是`find -exec file -i {} \; | grep iso-8859 | awk -F':''{print $ 1}'`,所以`-print0 | xargs -0`很难。通过`xargs vim -c'argdo设置fenc = utf8'-c'wqa'`,终端的行为会奇怪(从vim转义字符?)。但在for循环中,它工作得很好。感谢您的回复 – 2011-02-03 11:59:38

1

文件类型,语法和缩进插件可能是什么你放慢下。 这些在你的〜/ .vimrc指定用线,看起来像典型:

filetype plugin indent on 
  • 你可以尝试评论说出来,或者
  • 可以启动Vim没有你的插件和〜/。的vimrc但正是住在nocompatible模式:

    VIM -NU NONE

+0

它工作得很好。谢谢回复。 – 2011-02-03 12:01:17

相关问题