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
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
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
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
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
39 votes
2 answers
50k views

How to block replace code in visual mode?

I have a list of items where I want to replace the first two characters: a) item 1 b) item 2 c) item 3 What is the fastest way to make this: * item 1 * item 2 * item 3 I have an approach with ...
poseid's user avatar
  • 493
36 votes
5 answers
19k views

Git Fugitive how to git add a visually selected chunk of code

I would like to know if i could select some code in visual mode and git add it ? I checked with fugitive.vim but i didn't find how to do it. Is it possible ? Or is there any other plugin to do it ?
albttx's user avatar
  • 1,205
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
28 votes
11 answers
19k views

Quickly calculate the total of a column of numbers

I'm writing down a markdown table which looks like this: | 13/05/15 | 09:30-16:00 | 6.5 | | 14/05/15 | 10:00-16:30 | 6.5 | | 16/05/15 | 15:30-01:00 | 9.5 | | 21/05/15 | 09:00-16:30 | 7.5 | | 22/...
mrzool's user avatar
  • 1,022
27 votes
8 answers
5k views

How can I source a visual selection of vimscript?

If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them? I have tried make visual selection v, then motions to ...
the_velour_fog's user avatar
24 votes
3 answers
59k views

How to add space on multiple lines when pressing spacebar (without extra configuration)?

I tried visual block, but visual block only allow to highlight or delete characters on multiple lines. Is there any function that allows to add space before the first character of multiple lines when ...
ggrr's user avatar
  • 341
24 votes
1 answer
12k views

Fold selected lines

How can I fold and unfold lines selected in visual mode? Lets say I have three paragraphs and I want to fold the first or last two into one line: Test ==== Lorem Ipsum es simplemente el texto de ...
niekas's user avatar
  • 1,705
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
18 votes
1 answer
7k views

Mapping a command in Visual Mode results in error E481: No range alllowed

I'm trying to make a keyboard binding in Neovim that would send a selected block to the opened Neovim terminal. I've used these answers as guidelines https://vi.stackexchange.com/a/3390/3405 https://...
6D65's user avatar
  • 423
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
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
17 votes
2 answers
13k views

How to partially replace text in a selected text-block?

Not easy to find a nice title for my problem. I'm aware of inserting in front of a text-block: Ctrl-v select lines I type text ESC Now I would like to do this but also with replacing a part in my ...
Patrick B.'s user avatar
16 votes
3 answers
12k views

Visual select from cursor to next empty line?

How does one select from the current line to the next empty line? I'm aware of SHIFT+V but then I have to either jump to the next empty line or press the down key a bunch of times. I know how to do ...
leeand00's user avatar
  • 3,651
14 votes
2 answers
3k views

Extend visual selection until the last character on the line (excluding the new line character)

In the visual mode the $ extends selection until the end of the line including the new line character at the end, so I need to press an additional h to exclud the new line character. Is it possible ...
Boris Brodski's user avatar
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
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
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
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
1 answer
638 views

Which text object defines text enclosed in space?

Since I need to operate on a sequence of symbols between spaces I'd like to know which text object defines it. Here is an example: 45908 Sep 24 21:31 [r].t3891993.tr some another text. ...
user3663882's user avatar
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
10 votes
1 answer
743 views

How can I easily get the length of a piece of text?

I sometimes want to check the length of a piece of text, for example in this example: str = 'Hello, world!' if len(str) == 13: print('Hello back to you!') I would like to know the length of the ...
Martin Tournoij's user avatar
10 votes
2 answers
913 views

How to source a part of a file

I can source a file, e.g. my vimrc with :so % or :so <filename>. But what do I do when I need to source only part of a file. I want some way to visually select a portion of the file with :h v ...
3N4N's user avatar
  • 5,864
10 votes
1 answer
4k views

selecting a range of lines from command line

I need to (visual) select a range of lines from command line. For example the following command :?^\s*for?+,/^\s*end/- p prints all lines contained between a for and end (exclusive way). Instead of ...
nicmus's user avatar
  • 365
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
9 votes
3 answers
8k views

Passing visual range to a :command as its argument

I have a command: command! -nargs=1 TmuxSession !tmux.session "<args>" and I want to run it in visual mode so that selected text will be passed as argument. By selected text I mean selected in ...
lewiatan's user avatar
  • 421
9 votes
1 answer
378 views

Perform previous substitution for different selection with single keystroke

I performed following command :'<,'>s/2/digit/g on the code below manually visually selected: return _.round(this.getTotalAbs(), 2).toFixed(2); And it worked as intended return _.round(...
WitVault's user avatar
  • 1,729
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
3 answers
3k views

How to simply remove braces

One of my friend told me that I can use the trick below to remove a pair of curly brackets. Put the cursor inside the curly bracket pair you want to remove. y i { to yank the text in braces , then v ...
MrDwZ's user avatar
  • 101
8 votes
1 answer
2k views

Key binding to select the current paragraph

I'm using the following key binding to visually select the current paragraph. nnoremap <leader>v }kV{j Is works as follows: } Move below the current paragraph. k Move one line up. V Start ...
danijar's user avatar
  • 391
8 votes
1 answer
659 views

How to prevent Vim from clearing the system clipboard (:reg +) on exit?

After copying text to the system keyboard clipboard in vim, I'm unable to paste the text after exiting vim. I find this behavior frustrating, since I often copy text in files to paste it on the ...
Shuzheng's user avatar
  • 1,285
8 votes
1 answer
2k views

How to I get around "normal" exiting visual mode?

I'm trying to write a vimscript function that moves the cursor all the way up or all the way down without changing the column. (similar to the way :set nostartofline works). It works, but when I ...
DJMcMayhem's user avatar
  • 17.8k
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
7 votes
1 answer
7k views

How to expand selection to containing block? (It is in fact called Smart Selection)

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>...
Pierre-Antoine Guillaume's user avatar
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
7 votes
1 answer
468 views

What does [count]v and [count]V do? How is it useful?

I am confused about how the start visual commands work when you pass them a count. I checked the help page but I am still confused. [count]V Start Visual mode linewise. ...
wefwefa3's user avatar
  • 1,193
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
1 answer
532 views

How do you set no timeout for a specific remap?

The question arise from a problem using a huge remapped configuration so bépo layout is virtually the same as the qwerty in normal mode, at least for single key press commands. Selecting text using ...
psychoslave's user avatar
7 votes
1 answer
1k views

Replace all occurrences in visual block selection but NOT all occurrences on line

I'm trying to figure out how to do a search and replace on a visual block selection that will replace all occurrences in the visual block selection without replacing all occurrences on the line. What ...
user avatar
6 votes
2 answers
5k views

What does g CTRL-A really do?

Today I had that old feeling of wonder on how powerful VIM is: I needed a number sequence in the start of some fields and discovered the power of g CTRL-A. So as I always do when I discover something ...
Nelson Teixeira's user avatar
6 votes
5 answers
9k views

Copying lines when v is not implemented?

Is there any way to copy / paste blocks of text when v is not implemented?`
leeand00's user avatar
  • 3,651
6 votes
1 answer
5k views

Select text till and including pattern

I want to select text from multiple lines up till and including the pattern pattern. When I use v/pattern the text till attern is selected (not including attern). How can I select text including ...
user2609980's user avatar
6 votes
5 answers
433 views

How to ignore a column when visually selecting a paragraph

I have a file that looks like this: # Section 1 # # new: a.txt # new: b.txt # # # Section 2 # # [n]ew: c.txt # new: d.txt # new: e.txt # My cursor is on the first new of the second section and I ...
nobe4's user avatar
  • 16.2k
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
2 answers
1k views

How to paste a line in a vertical selection block?

Consider the following text: long foobar=(test); int barbar=(something); char foofoo=(); Suppose I have yanked some chunk of code which I want to place before each opening parenthesis, e.g. ...
Ruslan's user avatar
  • 475
6 votes
3 answers
1k views

How do I switch between the command-line history and file panes?

When using the command-line history window, I'd like to go back to the file I use it on to see what I'm working with. When revisualizing a block of code (gv), the cursor will go to the top after ...
oddRaven's user avatar
  • 235

1
2 3 4 5
7