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
0
votes
2answers
35 views

Pass visually-selected text as argument to script

I am trying to write a command that passes selected text to a shell script. The command works fine when there is no \n character in the selected text (using Visual mode). :vmap <Leader>tts 0y:...
2
votes
1answer
59 views

VIM - How to select multiple lines that are not adjacent?

If you have the following text: line 1 line 2 line 3 You can hit CTRL+v on line 1 and hit j to select line 2. However, I want to select both line 1 and line 3, but not line 2. Is this possible?
3
votes
1answer
46 views

pressing keys in visual line mode will leave this mode?

I find that in visual line mode, if I press a shortcut to print the current mode, it will print n instead of V. Is this the expected behavior? My mapping: xnoremap <a-j> :<c-u>echo mode()&...
1
vote
1answer
107 views

Indent current line by one space or two space character(s)

hopefully this is not obvious, but: I know how to indent and unindent multiple lines via: 3>> (shift right) and 3<< (shift left). The shift width is specified with 'shiftwidth'. How can I ...
0
votes
1answer
66 views

Fixing tab and space inconsistency

I used < in visual model to do a shift+tab reverse for a code inside loop after I removed the try/except phrase. Now, I get an error: $ python clean_captions.py File "clean_captions.py"...
0
votes
1answer
23 views

Grep for a pattern using current visual selection on another file

I want to basically search for a pattern in the current file on another file, from vim, using the current visual selection. I know doing: :grep pattern otherfile works, but i want the 'pattern' to be ...
1
vote
1answer
25 views

Append single-line register to many lines

I have a file like ... one;line;with;many;data starter another_starter yet_to_end complete;line;providing;information ... and I would like to have: ... one;line;with;many;data starter;default;...
1
vote
0answers
25 views

How can I repeat a custom function mapped using `vnoremap` using something similar to the dot (`.`) operator?

I have this custom function in my ~/.vimrc mapped to Visual mode using vnoremap. After having executed the function using <leader><space>, how execute it again using something similar to ...
1
vote
1answer
19 views

<Cmd> doesn't seem to work in visual mode

The following command copies the selected text into the PRIMARY selection: vnoremap <Leader>c :'<,'>!xsel<CR>u But this way it doesn't work: vnoremap <Leader>c <Cmd>'<...
3
votes
3answers
105 views

How can I indent selected lines in Visual mode by space granularity instead of TABs?

How can I indent lines selected in Visual mode using space granularity instead of than TABs (i.e. < or >)? Sometimes when coding Python, I need to indent lines to a level that is not a TAB ...
0
votes
1answer
32 views

gvim swaping between underline and normal visual text selection in visual mode

I'm having a weird issue running gvim 8.2.1081 on fedora 32 using kde. When selecting text in visual mode gvim keeps swapping between an underline and the expected visual text selection while moving ...
2
votes
3answers
37 views

Visually select consecutive lines with the same starting string

This is mainly for working on multiple files in vifm (log1.txt, log2.txt, etc.) so lines can be assumed to be sorted, though this should work in normal vim/nvim. Let's say we have this: test 1 test 2 ...
1
vote
1answer
54 views

Is it possible to view a history of commands (per mode) executed in Vim?

I sometimes execute commands in Vim by mistake, either in normal-, visual-, or ex-mode and have no idea what was executed. Is it possible to see a history of executed command per mode in Vim? I know ...
2
votes
1answer
33 views

How can I fold some lines on opening a buffer?

I want to fold from "Copyright" to "CONNECTION" every time I open a .c or .h file, so I don't have to see it. The license does have newlines in it in my files, so selecting shouldn'...
3
votes
2answers
114 views

Is it possible to enter visual mode without changing the last visual selection?

In a script, I want to delete a rectangular block of text. For example, I want to convert this: ABCD EFGH IJKL MNOP into this: ABCD EH IL MNOP One way to do this is with visual block mode. Move the ...
2
votes
3answers
285 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
34 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
53 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
133 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
38 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 ...
3
votes
4answers
146 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
31 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
102 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
32 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
291 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
21 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
30 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
42 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
118 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
19 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
85 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
67 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
32 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
112 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
31 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
52 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
44 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
340 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
56 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
187 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
53 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
546 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 ...
10
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
63 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
69 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
65 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
230 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 ...

1
2 3 4 5