vim 如何使用Exuberant ctags排除多个目录?

n3h0vuf2  于 2022-11-24  发布在  其他
关注(0)|答案(6)|浏览(158)

我已经尝试过使用丰富的ctags,但没有成功。我在Mac上尝试在一个项目中工作,我想排除.git、node_modules、test等目录。当我尝试使用ctags -R --exclude=[.git, node_modules, test]时,我没有得到任何回报。我真的只需要让它在我的核心目录中运行。有什么想法可以实现这一点吗?

atmip9wb

atmip9wb1#

--exclude选项不需要文件列表。根据ctags的手册页,“此选项可以根据需要指定任意多次。”因此,它是这样的:
ctags -R --exclude=.git --exclude=node_modules --exclude=test

lqfhib0f

lqfhib0f2#

读一读他妈的太棒了手册应该永远是解决问题的第一步。
$ man ctags开始:

--exclude=[pattern]
  Add  pattern to a list of excluded files and directories. This option may
  be specified as many times as desired. For each file name  considered  by
  both the complete path (e.g. some/path/base.ext) and the base name  (e.g.
  base.ext)  of  the  file, thus allowing patterns which match a given file
  name irrespective of its path, or match only a specific path.  If  appro-
  priate  support is available from the runtime library of your C compiler,
  then pattern may contain the usual shell wildcards (not  regular  expres-
  sions)  common  on Unix (be sure to quote the option parameter to protect
  the wildcards from being expanded by the shell  before  being  passed  to
  ctags;  also be aware that wildcards can match the slash character, '/').
  You can determine if shell wildcards are available on  your  platform  by
  examining  the output of the --version option, which will include "+wild-
  cards" in the  compiled  feature  list;  otherwise,  pattern  is  matched
  against file names using a simple textual comparison.

  If  pattern begins with the character '@', then the rest of the string is
  interpreted as a file name from which to read exclusion patterns, one per
  line.  If  pattern  is  empty,  the list of excluded patterns is cleared.
  Note that at program startup, the default exclude list contains "EIFGEN",
  "SCCS",  "RCS", and "CVS", which are names of directories for which it is
  generally not desirable to descend while processing the --recurse option.

从前两句话中你可以得到:

$ ctags -R --exclude=dir1 --exclude=dir2 --exclude=dir3 .

这可能有点冗长,但这正是别名和Map等的作用。作为替代,您可以从第二段中获得以下内容:

$ ctags -R --exclude=@.ctagsignore .

.ctagsignore中包含以下内容:

dir1
dir2
dir3

这样就排除了这3个目录,而不需要键入太多内容。

l2osamch

l2osamch3#

您可以使用大括号封装逗号分隔的列表,以便使用一个--exclude选项处理多个列表:

ctags -R --exclude={folder1,folder2,folder3}

这似乎只适用于您发出命令的根目录中的文件夹。排除嵌套文件夹需要单独的--exclude选项。

sxpgvts3

sxpgvts34#

其他人的回答都很直奔主题,我想举个小例子可能会有所帮助:
您应该添加一个类似Unix的星号样式来排除整个目录。

ctags -R --exclude={.git/*,.env/*,.idea/*} ./
x33g5p2x

x33g5p2x5#

有点晚了,但是在romainl响应之后,你可以使用你的.gitignore文件作为基础,你只需要从文件中删除任何前导斜杠,如下所示:

sed "s/\///" .gitignore > .ctagsignore

ctags -R --exclude=@.ctagsignore
bis0qfac

bis0qfac6#

我真的只需要让它在我的核心目录中运行。
只需删除-R(递归)标志!!!

相关问题