Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
230
questions
53
votes
1answer
13k 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:
...
44
votes
1answer
5k 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 ...
37
votes
11answers
4k 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 ...
36
votes
4answers
10k 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 ...
33
votes
2answers
27k 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 ...
28
votes
7answers
8k 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 ...
21
votes
5answers
7k 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 ?
19
votes
8answers
10k 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/...
16
votes
3answers
1k 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 ...
15
votes
3answers
1k 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 ...
15
votes
2answers
9k 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 ...
14
votes
1answer
7k 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 ...
13
votes
3answers
3k 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 ...
11
votes
3answers
7k 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 ...
11
votes
4answers
3k 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 ...
11
votes
1answer
3k 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://...
10
votes
5answers
2k 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 :'<,'>...
10
votes
3answers
22k 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 ...
9
votes
2answers
549 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 ...
9
votes
1answer
240 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 ...
9
votes
2answers
2k 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 ...
9
votes
1answer
180 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 ...
8
votes
2answers
5k 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 ...
8
votes
3answers
2k 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 ...
8
votes
1answer
228 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(...
8
votes
1answer
2k 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 ...
7
votes
3answers
984 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 ...
7
votes
1answer
447 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 ...
7
votes
1answer
210 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.
...
7
votes
1answer
279 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 ...
7
votes
1answer
268 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 ...
6
votes
5answers
414 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 ...
6
votes
2answers
928 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. ...
6
votes
2answers
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 ...
6
votes
3answers
908 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 ...
6
votes
2answers
881 views
Extend visual selection til the last character on the line (excluding the new line character)
In the visual mode the $ extends selection til 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 to ...
6
votes
1answer
347 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.
...
6
votes
1answer
602 views
Expand visual selection to inner curly braces
Let's say I have this piece of code (cursor/selection is represented by []):
[f]unction a()
{
// ...
}
If I want to select the function declaration and the curly braces (and of course the ...
6
votes
2answers
2k views
How to programmatically visually select a text block?
Is there a way to select a text block (e.g. a first word "TODO:") programmatically (with some commands or functions from a script)? Not simply highlight, like with a search, but visually select like ...
6
votes
4answers
144 views
How can I delimit sentences by carriage return?
I write screenplays with fountain. Dialogue syntax looks like this:
THE TERMINATOR
Hasta la vista. Baby.
I would like to be able to select the sentence: Hasta la vista., without also selecting THE ...
6
votes
2answers
1k 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 (...
6
votes
2answers
2k views
How to pipe *characters* to cmd ( `:!` ) [duplicate]
It is possible to pipe visually selected lines (i.e. selected with uppercase V) using :, after which I can enter a command in vim's command line, e.g.:
:'<,'>!python -m base64 -d
I'd like to ...
6
votes
1answer
772 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 ...
5
votes
3answers
387 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.
5
votes
1answer
926 views
How to sort lines by the right most characters?
When I enter visual mode, :'<,'>sort allows me to sort alphabetically the lines I have selected, obviously starting from the left most characters on a line going to the right.
Is it possible to ...
5
votes
1answer
307 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 ...
5
votes
2answers
934 views
How to prevent “echo” output from being overwritten when leaving visual mode?
I am using gvim 7.4 on Windows (32 bit) and using the wc word-counting macro :WC by jcline. When I manually set a range and run the macro, e.g., :'a,.WC<CR>, I get the expected counted XXX ...
5
votes
1answer
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 ...
5
votes
1answer
566 views
getpos(“.”) in visual mode equals getpos(“v”)
I use neovim 0.3.1 only.
I define the following function and map to do a test for getpos in visual mode:
function! show_position()
echo getpos("'<") getpos("'>") getpos(".") getpos("v") ...
5
votes
1answer
703 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.