I'm trying to re-do the C-w selection shortcut in Jetbrains's IDE.

Is there a way to select visually the whole containing block ?

for now, i use

nnoremap <C-w> <Esc>viw
vnoremap <C-w> <Esc>{v}

Which allow me to select current word, then current block. (That's already really nice though)

I know i could select multiple blocks with like {{v}}, but that would just catch adjacent blocks, and would not backtrack to parent block, and that plays poorly with new lines.

Is there a way to achieve that ?

It seems what I was looking for is called "smart selection", and there seem to be at least one vim extension that does that :


wildfire in use

  • 3
    Are you looking for vip ? See :h text-objects. Also I would advise to be careful remapping <C-w> because it is a useful prefix for a lot of window related commands. And also you don't need to add <Esc> in your normal mode mapping since you are already in normal mode.
    – statox
    Feb 26, 2019 at 11:06
  • I don't think there is a built-in way to do what you want. If none of the text objects mentioned in :h text-objects fit your needs, maybe you could have a look at this plugin which allows you to create your own.
    – statox
    Feb 26, 2019 at 11:14
  • @statox thank's for the c-w advice Its a shame we cant map control shift tab vs control tab. vip looks like what I want to achieve, but i mean some "recursive vip", if that would make sense ? It seems like <Esc>{v} makes a better job selecting a whole block. But it goes too far now that I check it with a better language to test it against. Maybe I have to think about a way to go through repetition viw -> vV -> vip -> <Esc>{v}. The second mapping is a visual-mode one :p. Feb 26, 2019 at 11:14
  • @Pierre-AntoineGuillaume I want to do the same. I am curious, what did you settle on? Feb 14, 2021 at 20:10
  • Didn't find what I was looking for (I was hoping to replicate jetbrains' expand selection) Feb 14, 2021 at 22:13

1 Answer 1


A slight change of workflow would be to type [{ as many times as necessary to jump to the start of the enclosing block, then V% to visually select that entire block.

See :help [{ and :help % for more details.

You can use these to implement your mappings:

nnoremap <C-W> [{V%
xnoremap <C-W> "_y[{V%

The visual mode mapping works by first yanking into the black hole register (see :help quote_), in order to exit visual mode leaving the cursor at the start of the previously selected block, and then selecting the next surrounding block with the same commands. I'm using xnoremap instead of vnoremap because the latter also applies in select mode, which you probably don't want.

Like statox, I'd recommend against using <C-W> for the lhs. You'd be better off finding another trigger for your mappings.

  • I'm letting the ticket open until tomorrow. What I synthetized is %[{v]} Feb 26, 2019 at 11:28
  • @PierreAntoineGuillaume See my edit for a mapping solution.
    – Rich
    Feb 26, 2019 at 11:31
  • So now you are using a _ registry, that you yank ? What does that mean ? Feb 26, 2019 at 11:31
  • @PierreAntoineGuillaume See my edit for an explanation.
    – Rich
    Feb 26, 2019 at 11:41

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .