【问题标题】:Move to the previous/next function in AndroidStudio (Vim Emulator)在 Android Studio (Vim Emulator) 中移动到上一个/下一个函数
【发布时间】:2017-11-08 00:15:34
【问题描述】:

我是 vim 用户,最近开始学习为 Android 编写应用程序。
我使用带有 Vim 模拟器的 Android Studio 2.3.2。

谈到 Vim - 我通常将它用于 C++ 编程,我每天使用的功能之一是 ]] 移动到下一个函数和 [[ 进入上一个函数。

当我在 Android Studio 中使用它时,它只会将我移动到文件的开头/结尾。

我的猜测是它与在同一行而不是在新行中打开函数范围有关。

问题:

是否可以像以前在 C++ 代码中那样使用 Android Studio Vim 模拟器跳转到下一个/上一个函数(即使我使用 Java 编码风格,又名“埃及方括号”)?

【问题讨论】:

    标签: android-studio vim editor


    【解决方案1】:

    来自文档:help ]]

                                *]]*
    ]]          [count] sections forward or to the next '{' in the
                first column.  When used after an operator, then also
                stops below a '}' in the first column.  |exclusive|
                Note that |exclusive-linewise| often applies.
    

    这意味着它只是转到下一个以“{”作为行的第一个字符的语句,这恰好是 C 和 C++ 函数的情况(至少在某些样式指南中),因为方法和函数以{,没有任何类型的嵌套。

    但是,在编写 Java 时,方法嵌套在类中,这意味着它们通常具有一定程度的缩进。

    According to this answer,Vim 具有内置的 [m]m 映射,用于导航方法。

                            *]m*
    ]m          Go to [count] next start of a method (for Java or
                similar structured language).  When not before the
                start of a method, jump to the start or end of the
                class.  When no '{' is found after the cursor, this is
                an error.  |exclusive| motion.
    

    因此,如果您希望使用[[]] 进行导航方法,您可以在~/.ideavimrc 中重新映射它们。

    nnoremap [[ [m
    nnoremap ]] ]m
    

    【讨论】:

    • 这就是我喜欢 vim 的原因。我认为自己是一个有经验的用户,但我不知道 ]m[m 方法。奇迹般有效。谢谢
    猜你喜欢
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 2010-11-24
    相关资源
    最近更新 更多