Is there a way for vim to open all .C and .H files in a directory and all its subdirectories?

北城余情 提交于 2021-01-27 06:53:03

问题


I want to execute a substitution in vim on around 20 *.C and *.H files, and I want to open them all at once. All files are distributed in multiple nested directories, and the command is executed in the top parent directory. Can I do this using only vim, or do I need the "find" command and the "-p" option as shown on this answer?


回答1:


  1. Start Vim at the root of your project:

    $ vim /path/to/project
    
  2. Add the relevant files to the arglist, recursively:

    :argadd **/*.C **/*.H
    

    See :h starstar and :h :argadd.

  3. Perform your substitution on every file in the arglist:

    :argdo s/foo/bar/gc
    

    See :h argdo and :h s_flags.



来源:https://stackoverflow.com/questions/13877898/is-there-a-way-for-vim-to-open-all-c-and-h-files-in-a-directory-and-all-its-su

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!