How to select between brackets (or quotes or …) in Vim?

前端 未结 9 2013
时光说笑
时光说笑 2020-12-12 08:55

I\'m sure there used to be a plugin for this kinda stuff, but now that I need it, I can\'t seem to find it (naturally), so I\'ll just ask nice and simple.

What is th

相关标签:
9条回答
  • 2020-12-12 09:24

    For selecting within single quotes use vi'.

    For selecting within parenthesis use vi(.

    0 讨论(0)
  • 2020-12-12 09:25

    To select between the single quotes I usually do a vi' ("select inner single quotes").

    Inside a parenthesis block, I use vib ("select inner block")

    Inside a curly braces block you can use viB ("capital B")

    To make the selections "inclusive" (select also the quotes, parenthesis or braces) you can use a instead of i.

    You can read more about the Text object selections on the manual, or :help text-objects within vim.

    0 讨论(0)
  • 2020-12-12 09:35

    Use arrows or hjkl to get to one of the bracketing expressions, then v to select visual (i.e. selecting) mode, then % to jump to the other bracket.

    0 讨论(0)
  • 2020-12-12 09:36

    Write a Vim function in .vimrc using the searchpair built-in function:

    searchpair({start}, {middle}, {end} [, {flags} [, {skip}
                [, {stopline} [, {timeout}]]]])
        Search for the match of a nested start-end pair.  This can be
        used to find the "endif" that matches an "if", while other
        if/endif pairs in between are ignored.
        [...]
    

    (http://vimdoc.sourceforge.net/htmldoc/eval.html)

    0 讨论(0)
  • 2020-12-12 09:36

    A simple keymap in vim would solve this issue. map viq F”lvf”hh This above command maps viq to the keys to search between quotes. Replace " with any character and create your keymaps. Stick this in vimrc during startup and you should be able to use it everytime.

    0 讨论(0)
  • 2020-12-12 09:37

    This method of selection is built-in and well covered in the Vim help. It covers XML tags and more.

    See :help text-objects.

    0 讨论(0)
提交回复
热议问题