如何在 Vim 中查找所有出现的变量? [英] How to find all occurrences of a variable in Vim?

查看:73
本文介绍了如何在 Vim 中查找所有出现的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vim中,如何查找某个目录下文件中所有出现的变量?

In vim, how to I find all occurrences of a variable in files under a certain directory?

我知道 vimgrep 有时可以工作,但它只查找文本,如果其他类具有相同名称的变量并且我只想要特定类下的变量,则它不起作用.

I know vimgrep works sometimes, but it looks for text only and doesn't work if other classes have variables of the same name and I only want the variable under a specific class.

我该怎么办?还是我应该换一个 IDE?

What should I do? Or should I get an IDE instead?

推荐答案

当您已经有一个 IDE 时,为什么还要使用另一个 IDE?Vim 一个可配置并可用于不同语言的 IDE..

Why would you want to use another IDE when you already have one? Vim is an IDE that is configurable and usable for different languages..

您可以使用 cscope构建代码数据库.这个数据库

You could use cscope to build a database of your code. This database

  • 允许搜索代码:
    • 对符号的所有引用
    • 全局定义
    • 函数调用的函数
    • 函数调用函数
    • 文本字符串
    • 正则表达式模式
    • 一个文件
    • 包含文件的文件

    Cscope 的其他功能:

    Further features of Cscope:

    • 基于诅咒(文本屏幕)
    • 生成信息数据库以便更快地搜索和以后参考
    • 模糊解析器支持 C,但足够灵活,可用于 C++ 和 Java,并可用作通用的grep 数据库"(用它来浏览大型文本文档!)
    • 具有用于包含在脚本中或作为 GUI/前端的后端的命令行模式
    • 可在所有版本的 Unix 以及大多数垄断控制的操作系统上运行.

    创建数据库后,您可以浏览变量、函数等的用法

    Once your database is created, you could browse through the usages of your variables, functions, etc.

    编辑(稍微偏离主题):
    在使用 Vim 处理代码时,另一个很酷的东西是 标签列表 使用 Ctags 的插件:

    标签列表"插件是 Vim 和提供源代码文件结构的概述,并允许您可以有效地浏览不同的源代码文件编程语言.

    The "Tag List" plugin is a source code browser plugin for Vim and provides an overview of the structure of source code files and allows you to efficiently browse through source code files for different programming languages.

    这篇关于如何在 Vim 中查找所有出现的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆