Skip to main content

Questions tagged [visual-mode]

Visual mode is a flexible and easy way to select a piece of text for an operator.

Filter by
Sorted by
Tagged with
41 votes
12 answers
9k views

How to comment out a set of lines which are selected in visual mode?

How do I comment out multiple in visual mode selected lines? How do I make it language specific? For example, if the first 4 lines are selected: def foo(a,b): for each in (a,b): print ...
JHK's user avatar
  • 775
17 votes
5 answers
4k views

How to run a substitute command on only a certain part of the line

I have the following line in my code: INCORRECT_EMAIL_MOBILE_COMBINATION("incorrect_email_mobile_combination"); When I try to substitute the underscores with spaces in visual mode (using :'<,'>...
TheChetan's user avatar
  • 427
49 votes
5 answers
24k views

How to replace only within visual selection?

How does one get vim to replace a character within the visual selection only and not elsewhere on the line? Example: Line: int arr[] = { 00 01 02 03 04 05 05 /* ... lots more like this*/}; Visual ...
Bhargav's user avatar
  • 1,103
17 votes
3 answers
2k views

How do I visually select the block of text I just pasted in Vim?

I usually need to move/copy code snippets between my source files. After I paste a block of text, I usually need to apply some operation to that block such as reindenting them with =. Is there a way ...
thameera's user avatar
  • 17.7k
9 votes
6 answers
4k views

Clipboard is reset after first paste in Visual Mode

I am on Neovim. This is really annoying and weird. When I make a selection in Visual Mode and copy, then select a text and then paste, this paste only works once. For the next time, I again have to ...
ng.newbie's user avatar
  • 253
58 votes
1 answer
8k views

Expand a visual selection in the other direction

Sometimes I have selected a visual selection with, for example, Vjjjjj, only to realize later that I should have started the selection one line higher. However, pressing k simply decreases the lower ...
Doorknob's user avatar
  • 15.5k
33 votes
8 answers
20k views

Faster way to move a block of text

Here's how I usually copy a block of text or code: Select the block with Visual mode (V) and delete it with d; or if it's just a single line, just use dd. Go to where I want the text to be, I am too ...
Martin Tournoij's user avatar
13 votes
4 answers
4k views

How to achieve selection different length of texts on different lines?

assume I have following texts: aaa-dd-e: "aaa", bb-x: "bb", c-9: "c" I want to do selection like below: aaa-dd-e: "aaa", bb-x: "bb", c-9: "c" I tried using c-v to create a visual block, but after ...
Aaron Shen's user avatar
  • 2,529
14 votes
1 answer
2k views

How to visually select based on indentation?

If someone is editing the following javascript file: let foo = true if (foo) { let bar = 42 // moooooore code... } You can use vi{ anywhere on the line with let bar to select let bar = 42 and ...
joaumg's user avatar
  • 283
5 votes
3 answers
605 views

Way to get content of Visual Selection?

Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register? I looked through :h functions but didn't find anything.
hgiesel's user avatar
  • 1,954
0 votes
1 answer
59 views

How can expand and contract visual selection from a tag block?

Say I have hierarchical markup like this: <div id="level_1"> <div id="level_2"> <div id="level_3"> watermelon </div> </div>...
Sasgorilla's user avatar
85 votes
1 answer
32k views

What is the select mode and when is it relevant to use it?

I accidentally pressed gh in normal mode and started a selection, so I looked up the doc and found :h Select-mode. From what I understand the select mode is close to the visual mode excepted that: ...
statox's user avatar
  • 50.4k
23 votes
3 answers
3k views

How do you indent > < without leaving visual mode and losing your current selection?

I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press < or >, I leave visual mode whether I want to or not. I would rather have it so I stay in ...
Anon's user avatar
  • 905
9 votes
1 answer
228 views

How to modify visually selected block with external command?

I have a file that is made up of two vertical parts. On the left side, the data is already formatted and I don't want to change it. I only want to format the data on the right side. Say I have a file ...
kojiro's user avatar
  • 193
8 votes
2 answers
6k views

Why can't I paste commands into vi?

I've been using vi for 40 years. A week ago I upgraded; Disaster struck! The upgrade was to VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Mar 4 2018 23:38:28) I run this on xterm under Cygwin (...
user19858's user avatar
  • 171
5 votes
1 answer
8k views

Comment-out in vim with Shift-i not working

To comment out a block in vim, I enter visual mode with v or Control-v, select some lines, then hit I (Shift-i). However, I takes me out of visual mode and into Insert mode (which makes sense, as ...
Joshua Fox's user avatar
5 votes
3 answers
859 views

How to decrease markdown header level in visual mode without a plugin?

I have a file like this: # Heading A ### Heading B1 lorem ipsum ### Heading B2 lorem ipsum and I want to reduce the header levels of B1 and B2 to look like this: # Heading A ## Heading B1 ...
Allan Tsai's user avatar
4 votes
1 answer
113 views

How do I loop over a list of files from a visual selection?

Code in .vimrc which starts graphical Neovim on a filename when pressing gff % http://unix.stackexchange.com/q/277918/16920 :nnoremap gff :silent! exec "!gnvim " shellescape('<cfile>') <bar&...
Léo Léopold Hertz 준영's user avatar
2 votes
2 answers
1k views

Stop Vim from yanking visual selected text

Let's say I have a file like this (abc) (123) (456) I want to yank abc and paste it in place of 123 and 456. I would yi) on the first line. Then go down a line and paste it with vi)p. But for the 456,...
Tai Nguyen's user avatar
13 votes
2 answers
13k views

Is there a command to enter Visual Block mode?

I've set up a bunch of key mappings that would cause many Vim users to cringe. Now I am unable to get into Visual Block mode using Ctrl-V (Ctrl-Q isn't mapped, but it doesn't work). Is there any ...
Dan's user avatar
  • 485
12 votes
3 answers
3k views

Visual Block Mode edit with sequential number [duplicate]

Suppose I'd like to create a list - "1" - "2" - "3" what Is the smartest way to create such? My attempt would be to i- "1"ESCyypp to get - "1" - "1" - "1" and then jump to the second line's 1 ...
Joel's user avatar
  • 223
11 votes
2 answers
4k views

Is there a way to reselect the last visual shape, rather than the last actual selection, starting at the current cursor position?

I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to do something related but different: from the current cursor position, select a block ...
Philip's user avatar
  • 301
7 votes
1 answer
327 views

Can visual select mode be integrated with the Unix selection clipboard?

Is it possible to configure vim (obviously with :set mouse=a) and/or gvim such that the visual selection modes automatically integrate with X's selection buffer? I am aware of how to setup the copy ...
Caleb's user avatar
  • 2,255
7 votes
3 answers
2k views

Yank/select until delimiter in different lines

From the following text: variable1 = 'example' foo = 'foo' barett = 'ver' I would like to yank (or visually select, if possible) the content of each line until the = sign: variable1 foo barett ...
user2891462's user avatar
6 votes
3 answers
4k views

How do I add text before and after the visual selection?

Suppose I’ve selected some text in visual mode. How do I insert a certain piece of text at the beginning of the selection and a different piece of text at the end? (I’m only concerned with “normal” ...
bdesham's user avatar
  • 3,013
6 votes
3 answers
1k views

Insert a text selected via visual block

I'm facing a behavior that I find unatural when trying to paste a block of text selected with visual block mode (<C-v>): I can't insert it between two lines without messing with the already ...
statox's user avatar
  • 50.4k
6 votes
1 answer
1k views

Visual block editing: map i

How to map i to start editing on visual block mode? I want the same behavior for <shift>-i and i.
adelarsq's user avatar
  • 604
6 votes
2 answers
2k views

Using visual selection or register for search and replace

Is there a way to use a register or visual selection for search and replace? I have some longer sequence of words that are used repeatedly in my script. I want to replace them all but want to avoid ...
M.O. Kitzka's user avatar
4 votes
1 answer
416 views

Why does `yW` yank until the end of the WORD, but `W` move to the next one?

My confusion started with realizing, that yW yanks a different region, then what vW selects, but I found this that explains about selection. But then I realized, that while yW will yank until the end ...
fbence's user avatar
  • 707
4 votes
1 answer
471 views

How to check whether a command is run with range or not?

For example, I have the following code command! -range Test call TestFunc() function! TestFunc() abort " if run with range " get selected content " else " get current word under the ...
WW00WW's user avatar
  • 320
3 votes
1 answer
452 views

How can I call function in visual mode

I want a function to change underline word to little camel for one line. When I use <shift+v>:s/_\(\w\)/\u\1/g, it work fine. And then I want to make a function to simplify it, <shift+v>:...
Sangria's user avatar
  • 33
3 votes
2 answers
86 views

Why \%V is not added in visual mode during substitution by default?

\%V can be used to restrict match within the visual selection. However, I can't think of a situation when one would not want to do just that in visual mode.
tejasvi's user avatar
  • 470
3 votes
1 answer
1k views

Why is `vmap` for both Visual *and* Select mode?

Vim has both Visual and Select modes. Select mode is similar to Visual mode in some senses, but different in that when a printable character is typed, Vim will replace the selection with that ...
filbranden's user avatar
  • 29.6k
3 votes
2 answers
459 views

Is it possible to properly repeat a visual replacement?

It is possible in vanilla vim to: visual select some number of characters, e.g. a variable name in code type c to begin replacing selection in insert mode type a replacement (variable name) exit ...
Steven Lu's user avatar
  • 2,281
3 votes
1 answer
99 views

How to search in visual mapping?

I am trying to create a text object for consecutive lower-case letters. Here is how I am setting up the inner text object: xnoremap in :<C-u>normal! ?[^a-z]?e+1<CR>v/[^a-z]/s-1<CR> ...
Andy Stewart's user avatar
  • 1,359
3 votes
1 answer
537 views

Vim "gq" command doesn't recognize Haskell-style comments

I have a Haskell file on VIM with a Haskell-style comment block: When I select that comment block on visual mode... And press gq, I expected VIM to format my comment to something like: But instead, ...
MaiaVictor's user avatar
2 votes
1 answer
433 views

better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code

I want to select multiple lines in vim, copy them, and paste after that chunk of code (with cursor at the beginning). yp doesn't work because in visual chunk of code, vim pastes after the 1st line of ...
Mega Bang's user avatar
  • 319
2 votes
1 answer
436 views

Automatically set the 'number' option in Vim when entering Ex mode, set 'nonumber' in visual mode

I have previously asked this in StackOverflow (May 2015), but without getting any replies that I was completely happy with. This ought to be simple: I want to configure Vim to set number whenever ...
Kusalananda's user avatar
2 votes
3 answers
356 views

Quoting blocks but ignoring whitespace

Let's say I have Foo BAR Baz Quxxx Foo Baar Asd Duxxxxx Bar Foo Baazzz Kuxx Baz I would ideally like to be to highlight the first, second, or third column. Then I would ...
Evan Carroll's user avatar
  • 1,483
1 vote
1 answer
396 views

Vimscript: how to detect selection of a text object in visual mode?

I'm writing what may become a plugin that needs to know what is currently visually selected. To do it, I'm using the autocmd CursorMoved event to detect the creation of visual mode selections on the ...
mattb's user avatar
  • 1,161
1 vote
0 answers
65 views

How to stop vim from automatically displaying latex formatting? [duplicate]

I have a latex file I am editing in vim. Something annoying that I'm running into is that vim seems to auto display things that I am typesetting in math mode. Here is an example. Say I write the ...
Burnished Sandalwood's user avatar
1 vote
0 answers
39 views

Is there a way to reselect the last pasted text, rather than the last actual selection, starting at the current cursor position? [duplicate]

I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to select the block of text that I just pasted. This is useful e.g. for sending example ...
Philip's user avatar
  • 301
1 vote
1 answer
48 views

Understanding a vimscript function

I have the following function in a vim plugin: fu! HOLSelect(l,r) let l:cursor = getpos(".") if search(a:l,"Wbc") == 0 return endif normal v if search(a:r,"W&...
Gergely's user avatar
  • 293
0 votes
1 answer
178 views

Get visually selected text - weird behavior when last selected char is multi-byte

I have made a simple function to echo the visually selected text. The function is simplistic as I am only interested in max one-line selection. The problem is, if the last character of the visual ...
skamsie's user avatar
  • 235
0 votes
1 answer
335 views

May I have a Vim session report its "Mode" in its "Window Title"?

Clarification of the moving parts First, let me clarify what I mean by "Window Title", and what I expect to achieve On Windows OS, GUI programs will have three attributes: its Window Title texts, ...
llinfeng's user avatar
  • 352
0 votes
1 answer
79 views

How can I detect which way vim is going into visual mode (from up to down or from down to up)?

This is related to better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code. I need to be able to detect which way vim is going into visual mode so that I can ...
Mega Bang's user avatar
  • 319
0 votes
1 answer
74 views

How can you turn off text highlighting (hlsearch) with custom text objects?

I am implementing a custom text object in visual mode, but this text object uses regular expressions to find the beginning and ending of the selection. However, when I do this, other parts of the text ...
magnus's user avatar
  • 427