4

Is there a shortcut to move the Visual area as a whole?

For instance, after entering Visual mode linewise to make the next line selected.

Right now this is achieved by:

  • V Start Visual mode linewise
  • j move one line down -> now 2 lines are selected
  • o select the other end
  • j move that end one line down -> finally only next line selected

Is there a shortcut that achieves the same effect as the joj sequence.

I know how to create a mapping, I am asking if there is a default shortcut.

4
  • Why do you need to do this? After your first j you can easily just reselect only the current line via <esc>V or just VV Nov 2, 2015 at 19:05
  • @PeterRincker still 3 keys. Well, I just wanted to know if there is a default way to do it. The actual reason is that I use Vimium for Chrome and it has a Visual select mode, but it is almost impossible to start the selection at the right line, there is no way to create mappings so I thought that if there is such a default movement in vim, maybe Vimium implements it.
    – bolov
    Nov 2, 2015 at 19:58
  • Check out vimrcfu.com/snippet/182 and vimrcfu.com/snippet/77 Nov 3, 2015 at 9:06
  • @bolov - With Vimium, I hit v once, then move to the desired location (j,k etc.), then hit v again - this starts the selection, on the line I want ... also, you can create Vimium mappings (click Icon, select Options).
    – VanLaser
    Nov 3, 2015 at 14:50

3 Answers 3

1

You can create a mapping for this:

:vnoremap <C-j> jojo
:vnoremap <C-k> koko

In this case I mapped it in visual mode to Ctrl+j and Ctrl+k

1

There’s no shortcut I'm aware of, but Vim does have a feature that allows you to move a visual selection. It's not useful for the specific use-case described, but it might be for moves of larger selections.

The output of :help V explains:

With [count] select the same number of lines as used for the last Visual operation, but at the current cursor position, multiplied by [count].

So you can move a linewise visual selection with the following sequence:

  1. Pressing y to perform a “Visual operation”,
  2. Using whichever of Vim’s motions are the most convenient/efficient to move the cursor to the first line of the location where you want the selection to be moved to.
  3. Pressing 1V to re-enter Visual mode with the same number of lines selected.

This obviously stores the previously selected text in the yank and unnamed registers. If this is not desirable, you can prevent it by using "_y to yank into the black hole register instead.

The other commands to enter visual mode also take counts, so you can use this technique for characterwise or blockwise selections, too.

-1

If you're amenable to a plugin, perhaps this is an option:

vim-move

1
  • 1
    no, it's not about moving the text. It's about moving the visual selection.
    – bolov
    Nov 14, 2015 at 19:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.