• 搜索
    • 使用额外工具
      • 常用按键绑定
      • 在当前文件中进行搜索
      • 搜索当前文件所在的文件夹
      • 在所有打开的缓冲区中进行搜索
      • 在任意目录中进行搜索
      • 在工程中进行搜索
      • 后台进行工程搜索
      • 在网上进行搜索
    • 实时代码检索
    • 保持高亮
    • Highlight current symbol

    搜索

    使用额外工具

    SpaceVim 像下面那样调用不同搜索工具的搜索接口:

    • rg - ripgrep
    • ag - the silver searcher
    • pt - the platinum searcher
    • ack
    • grep
      SpaceVim 中的搜索命令是以 SPC s 为前缀的, 前一个键是使用的工具,后一个键是范围. 例如 SPC s a b将使用 ag在当前所有已经打开的缓冲区中进行搜索.

    如果最后一个键(决定范围)是大写字母, 那么就会对当前光标下的单词进行搜索. 举个例子 SPC s a b 将会搜索当前光标下的单词.

    如果工具键被省略了, 那么会用默认的搜索工具进行搜索. 默认的搜索工具对应在 g:spacevim_search_tools 列表中的第一个工具. 列表中的工具默认的顺序为: rg, ag, pt, ack then grep. 举个例子 如果 rgag 没有在系统中找到, 那么 SPC s b 会使用 pt 进行搜索.

    下表是全部的工具键:

    Tool Key
    ag a
    grep g
    ack k
    rg r
    pt t

    应当避免的范围和对应按键为:

    范围
    opened buffers b
    files in a given directory f
    current project p

    可以双击按键序列中的第二个键来在当前文件中进行搜索. 举个例子: SPC s a a 会使用 ag 在当前文件中进行搜索.

    Notes:

    • 如果使用源代码管理的话 rg, ag 和 pt 都会被忽略掉, 但是他们可以在任意目录中正常运行.
    • 也可以通过将它们标记在联合缓冲区来一次搜索多个目录.注意 如果你使用 pt, TCL parser tools 同时也需要安装一个名叫 pt 的命令行工具.
      常用按键绑定
    Key Binding Description
    SPC r l resume the last completion buffer
    SPC s ` go back to the previous place before jump
    Prefix argument will ask for file extensions
    在当前文件中进行搜索
    Key Binding Description
    SPC s s search with the first found tool
    SPC s S search with the first found tool with default input
    SPC s a a ag
    SPC s a A ag with default input
    SPC s g g grep
    SPC s g G grep with default input
    SPC s r r rg
    SPC s r R rg with default input
    搜索当前文件所在的文件夹
    Key Binding Description
    SPC s d searching in buffer directory with default tool
    SPC s D searching in buffer directory cursor word with default tool
    SPC s a d searching in buffer directory with ag
    SPC s a D searching in buffer directory cursor word with ag
    SPC s g d searching in buffer directory with grep
    SPC s g D searching in buffer directory cursor word with grep
    SPC s k d searching in buffer directory with ack
    SPC s k D searching in buffer directory cursor word with ack
    SPC s r d searching in buffer directory with rg
    SPC s r D searching in buffer directory cursor word with rg
    SPC s t d searching in buffer directory with pt
    SPC s t D searching in buffer directory cursor word with pt
    在所有打开的缓冲区中进行搜索
    Key Binding Description
    SPC s b search with the first found tool
    SPC s B search with the first found tool with default input
    SPC s a b ag
    SPC s a B ag with default input
    SPC s g b grep
    SPC s g B grep with default input
    SPC s k b ack
    SPC s k B ack with default input
    SPC s r b rg
    SPC s r B rg with default input
    SPC s t b pt
    SPC s t B pt with default input
    在任意目录中进行搜索
    Key Binding Description
    SPC s f search with the first found tool
    SPC s F search with the first found tool with default input
    SPC s a f ag
    SPC s a F ag with default text
    SPC s g f grep
    SPC s g F grep with default text
    SPC s k f ack
    SPC s k F ack with default text
    SPC s r f rg
    SPC s r F rg with default text
    SPC s t f pt
    SPC s t F pt with default text
    在工程中进行搜索
    Key Binding Description
    SPC / or SPC s p search with the first found tool
    SPC * or SPC s P search with the first found tool with default input
    SPC s a p ag
    SPC s a P ag with default text
    SPC s g p grep
    SPC s g p grep with default text
    SPC s k p ack
    SPC s k P ack with default text
    SPC s t p pt
    SPC s t P pt with default text
    SPC s r p rg
    SPC s r P rg with default text

    提示: 在工程中进行搜索的话, 无需提前打开文件. 在工程保存目录中使用 SPC p p 和 C-s , 就比如 SPC s p.(TODO) 

    后台进行工程搜索

    在工程中进行后台搜索时,当搜索完成时,会在状态栏上进行显示.

    Key Binding Description
    SPC s j searching input expr background with the first found tool
    SPC s J searching cursor word background with the first found tool
    SPC s l List all searching result in quickfix buffer
    SPC s a j ag
    SPC s a J ag with default text
    SPC s g j grep
    SPC s g J grep with default text
    SPC s k j ack
    SPC s k J ack with default text
    SPC s t j pt
    SPC s t J pt with default text
    SPC s r j rg
    SPC s r J rg with default text
    在网上进行搜索
    Key Binding Description
    SPC s w g Get Google suggestions in vim. Opens Google results in Browser.
    SPC s w w Get Wikipedia suggestions in vim. Opens Wikipedia page in Browser.(TODO)

    注意: 为了在 vim 中使用谷歌 suggestions , 你需要在你的默认配置文件中加入 let g:spacevim_enable_googlesuggest = 1.

    实时代码检索

    Key Binding Description
    SPC s g G Searching in project on the fly with default tools

    FlyGrep 缓冲区的按键绑定:

    Key Binding Description
    <Esc> close FlyGrep buffer
    <Enter> open file at the cursor line
    <Tab> move cursor line down
    <S-Tab> move cursor line up
    <Bs> remove last character
    <C-w> remove the Word before the cursor
    <C-u> remove the Line before the cursor
    <C-k> remove the Line after the cursor
    <C-a>/<Home> Go to the beginning of the line
    <C-e>/<End> Go to the end of the line

    保持高亮

    SPaceVim 使用 g:spacevim_search_highlight_persist 保持当前搜索结果的高亮状态到下一次搜索.同样可以通过 SPC s c 或者 运行 ex 命令 :noh 来取消搜索结果的高亮表示.

    Highlight current symbol

    SpaceVim supports highlighting of the current symbol on demand and add a transient state to easily navigate and rename these symbol.

    It is also possible to change the range of the navigation on the fly to:

    • buffer
    • function
    • visible area
      To Highlight the current symbol under point press SPC s h.

    Navigation between the highlighted symbols can be done with the commands:

    Key Binding Description
    * initiate navigation transient state on current symbol and jump forwards
    # initiate navigation transient state on current symbol and jump backwards
    SPC s e edit all occurrences of the current symbol
    SPC s h highlight the current symbol and all its occurrence within the current range
    SPC s H go to the last searched occurrence of the last highlighted symbol

    In highlight symbol transient state:

    Key Binding Description
    e edit occurrences (*)
    n go to next occurrence
    N/p go to previous occurrence
    b search occurrence in all buffers
    / search occurrence in whole project
    Tab toggle highlight current occurrence
    r change range (function, display area, whole buffer)
    R go to home occurrence (reset position to starting occurrence)
    Any other key leave the navigation transient state