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
2
votes
3answers
271 views

Is there a quicker way to replace the content in parentheses with the content yanked?

If I want to replace something inside a group of parentheses (like say a function call) with something I've yanked I currently do: vi(p this obviously isn't an excessive use of the keyboard, however I'...
0
votes
1answer
31 views

Visual selection on variable line lengths

Suppose we have something like, here is some text. here is some more text. here is. here is some. Starting with gg 0, how do I do something like v t. 4j so that I can replace text up to a . on each ...
0
votes
1answer
48 views

Discrete Visual mode

A feature that I love in VSCode is to be able to use my mouse to click at multiple points in the screen and type with multiple cursors. I am aware that in Vim you can do the same in visual mode, but ...
3
votes
1answer
129 views

How can I quickly mark consecutive lines of the same indentation in Vim?

I often edit Python code that needs to be re-indented other otherwise manipulated through visual selection. Is there any way to visually select all lines of the same indentation in Vim? I know I ...
2
votes
1answer
33 views

How to store a region of text into a variable?

Suppose I have \label{some text} somewhere in my file and I want to store some text into a variable. Right now what I am doing to achieve this is to first visually select some text and then store it ...
2
votes
4answers
107 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 ...
0
votes
1answer
25 views

Select text in block-wise visual mode on each line asynchronously

If I have text like this: cat = "john" leopard = "frank" tiger = "josh" and I want to select the first word of each line in block-wise visual mode, I want to be able to do something like this: put ...
0
votes
1answer
51 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 ...
1
vote
1answer
25 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 ...
2
votes
1answer
68 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 ...
0
votes
2answers
16 views

Visual mode word behaves differently than in normal mode?

Say I have the text: This is a test! If my cursor is on the first character, "T", and then I do d4w, then I am left with just !. However, if instead I do v4wd then I'm left with nothing (i.e. the ...
2
votes
1answer
28 views

How to re-select a previously selected region in visual mode?

I often select a region in visual mode for properly indenting it. However, after pressing e.g. 3>, visual mode exists and the selection disappears. How can I re-select the previously selected ...
0
votes
1answer
37 views

Deleting comments from the beginning of selected lines

I have written a vimscript function to toggle comments on/off on lines selected in visual mode. The function successfully adds comments but freezes when I try to uncomment selected lines. The ...
1
vote
1answer
85 views

Trailing characters error in a substitution command

Suddenly simple find&replace stopped working in one particular case. I'm selecting the code-block in visual-mode, so the final command looks like: '<,'>%s/someStuff/stuff/gI I get the ...
4
votes
0answers
18 views

How to copy text to X primary selection only when visual mode is started with the mouse?

At the moment, if I use Visual mode, whenever I select a block of text using the keyboard it ends up on my X primary selection (ie the clipboard that is filled using the mouse). Even if I just select ...
2
votes
1answer
74 views

Visual/Operator-pending autocommand?

Last week, I turned off 'number' and have been using only 'relativenumber', plus a line/column count in my status line. I don't really look at line numbers that much. But now I've had a radical idea. ...
0
votes
1answer
57 views

viw breaks when i is remapped

I have the following in my init.vim (neovim): nnoremap i k nnoremap j h nnoremap k j xnoremap i k xnoremap j h xnoremap k j nnoremap h i nnoremap H I I find this arrow key-like configuration much ...
0
votes
1answer
30 views

'visual inner word' on single space does not grow selection

In visual mode, the iw text object 'grows' with repeated presses of iw, ie., viwiwiw... will 'grow' to select multiple inner words. However, this 'growing' behaviour is not seen when the cursor is ...
5
votes
1answer
100 views

Cursor Column in Visual Selection

What is the correct way get the column of the cursor after a visual selection was made? As a simple example, consider the following command. It takes a range and I am trying to obtain the column to ...
3
votes
0answers
30 views

Keep function “keyword = arguments” together when reformatting across multiple lines using “gq”?

One thing I find myself doing often is using visual mode to select a block containing a long function definition containing one or more keyword arguments, and then using gq to reformat the code across ...
4
votes
1answer
45 views

gq in visual mode indents just first two lines of enumeration

Some markdown as an example. I select the following paragraph in visual mode and press gq. The result is: - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor ...
2
votes
1answer
38 views

How to go back after accidentally hitting H in visual mode?

While selecting in visual mode I often accidentally hit H or L instead of h or l due to having used Shift for some previous command (like e.g. V to start selection by line) and not yet released it ...
3
votes
2answers
216 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 ...
2
votes
1answer
52 views

Write text under the cursor to new file and delete it form current file

I have this in my vimrc: " Export text under the cursor noremap <leader>e :w! >><Space> This allows me to select text using visual mode, press leader e, type a file name, and ...
1
vote
1answer
157 views

How to paste yanked text over visual selection?

Yanked text with y, then v select some text, paste with p, but nothing happens.
1
vote
2answers
50 views

remove extra (^@) from visual selection

I'm writing a function to execute an external command using visual selection. I've noticed that if by mistake the entire line is selected, including the new line char the extra ^@ character makes the ...
2
votes
3answers
413 views

How to repeat the last : command for a visual selection instead of whole buffer?

Say I've done the command: :g/^.\{1,50\}$/m$ To move all lines with 50 or less characters to the bottom of the file. Then I realise I actually didn't want to do that for the whole file, but for ...
8
votes
5answers
1k 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 :'<,'>...
1
vote
1answer
46 views

How do I map multiple replace commands in visual mode

I'm trying to edit my init.vim to allow quick, custom retabbing with one key. My current attempt is as follows (the replace text in the last command is a tab character inputted in insert mode): ...
1
vote
1answer
32 views

Entering visual mode is selecting whole lines unexpectedly

I'm editing a small bash script: d=$1 year=$(date -d"$d" +%Y) month=$(date -d "$d" +%m) day=$(date -d "$d" +%d) hive -f /home/gavin_cameron/hive_queries/dc_player_daily_snapshot.hive -d ...
0
votes
0answers
58 views

How to start insert-mode completion from select mode using Vimscript?

I have some text selected in select mode. I want to delete it and start insert-mode completion. When I type these keystrokes into Vim it works perfectly: gvc<C-X><C-U> gv switches to ...
3
votes
2answers
58 views

Why is this appearing to select wrong number of lines?

First, I typed 2V to select two lines, and y to yank them. Then I typed 3V, and instead of selecting 3 lines, Vim selects 6 lines. Next I typed 4V and Vim selected 8 lines. It seems that 3 or 4 in the ...
0
votes
1answer
54 views

How do I move to the beginning of a visual block from a vimscript function?

Suppose i have several lines of text: line1 line1 line2 line2 line3 line3 I want to create a vimscript function that has the following result: <itemizedlist> <listitem><para>line1 ...
0
votes
1answer
40 views

Is there a way to determine whether the current / last visual block selection is non-rectangular?

One can create non-rectangular Visual-Block selections using C-v$ on files with lines of non-equal length. Is it possible to programmatically determine whether the last Visual Block selection was non-...
0
votes
0answers
198 views

Visual block mode insert/append not working in vim on RHEL/CentOS?

I was trying to append some text to multiple lines in vi on a RHEL 6 system, however I could not get it to work. I press Control + V to get into visual block mode, select the lines I need, but when I ...
7
votes
3answers
641 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 ...
0
votes
3answers
608 views

Move selected text to the right

Say I have a line 1234text5678, where I have selected text in visual mode. I would like to have a command <Shift>+, that moves text to the right one character and selects text again. I.e. the ...
1
vote
2answers
55 views

Replacement in visual mode

I wrote a function for selecting a text region and replacing in it certain predefined characters: fun! Tstrepl() range s/\%Va/\="\u2227"/ge " 'a' to '∧' s/\%Vb/\="\u2228"/ge " 'b' to '∨' ...
1
vote
2answers
97 views

visual line mode is ended by inner block motion

When I do Vi{y to select inside a { block and yank it, it doesn't paste how I expect. I noticed that after V (which puts me into VISUAL-LINE mode), the i{ object takes me into VISUAL mode. Here's a ...
1
vote
0answers
74 views

How to use visual mode in python/dyn?

Vim documentation states how to run command and normal mode commands (source): vim.command(str) python-command Executes the vim (ex-mode) command str. ...
1
vote
5answers
542 views

How to write on multiple places at once

I'm familiar with vertical blocks, and I often ctrl+v down down down shift+I foobar esc to write foobar in various locations at once. This is useful if I want to replace <td> to <th> in a ...
2
votes
2answers
73 views

past yanked content in rectangular selection

I have some long text on Yank var e.g. "Hello all how are you ?" I have a rectangular selection between abc and ABC /a llC-vjj a A b B C C And I want to past my long text without having to type it
1
vote
2answers
52 views

Pass character-wise visual selection to an external command

I want to VISUAL select a piece of text character-wise and pass it to an external command. For example I want to select only the URL from the the text below abcde www.google.com abcde and open it ...
8
votes
2answers
449 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 ...
0
votes
1answer
176 views

How to expand selection to containing block?

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&...
2
votes
0answers
31 views

Do operator ranges/movements/textobjects always overwrite the last visual selection? workaround?

In vim, when I operate on a textobject from a plugin, say the 'inner indent' typed ii from kana/vim-textobj-indent, my last visual selection ('>, '<) is reset to where the operator worked on. ...
0
votes
0answers
29 views

Select characters in Visual mode (works differently than Normal mode)

I'm trying to understand the difference in character counting between Normal and Visual modes. Roses are red, Violets are blue, Sugar is sweet, And so are you. The task is to copy everything from ...
0
votes
1answer
97 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, ...
1
vote
0answers
63 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 ...
5
votes
1answer
252 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 ...

1
2 3 4 5