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
0answers
22 views

How to read the starting/ending line number of my visual selection?

So what I would like to achieve is when I selected a block of texts using shift-v, is it possible to read the starting and ending lines' line number within command mode? (Something like we could read ...
39
votes
4answers
11k 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 ...
1
vote
1answer
25 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&...
0
votes
1answer
13 views

Visually selecting from mark to cursor

How can I visually select the area between a mark and the cursor? According to https://vim.fandom.com/wiki/Using_marks I can yank this range by y`a yank text to unnamed buffer from cursor to ...
0
votes
0answers
22 views

How can I stop vim from automatically entering visual mode when I click into the PuTTY window with my mouse?

I suspect this is the same in vim as well, but fwiw I'm actually using nvim. For a long time I've used set mouse=a so I can choose to navigate my file with the mouse, if I so wish. What I've never ...
0
votes
1answer
306 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 ...
15
votes
5answers
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 ...
0
votes
1answer
30 views

“Visual around two Words”?

If I type 2daW, I can delete the current Word and the next (though I can't really see that case covered in the manual). Is there a way to visual-select around two words? I tried 2vaW, but of course (...
1
vote
1answer
48 views

Configure Vim 8 behavior regarding substitution in visual selection

When I select a section of text within a line, then indicate I want to substitute on that line with :s, the result is that the entire line is affected. In order to actually do what I intend, I have to ...
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 :'<,'>...
2
votes
1answer
41 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.
0
votes
1answer
23 views

Cause vi's visual mode to go in opposite directions? [duplicate]

If I enter visual mode I can select lines either up xor down, but not both. Is there a way to make vim do both? I'm particularly interested in this for purposes of searching, entering visual mode, ...
1
vote
2answers
34 views

How to remove periods within visual selections in a cmd composition?

I'd like to remove the period between the 6th comma and the 9th comma for the multiple lines of the following texts. Change from: 4,Afghanistan,2,Medium,1951,1951.5,4134.756,3705.395,7840.151,12.009 4,...
0
votes
1answer
33 views

Yanking into register within a script is not working

Given a file like this: Roy Maurice Jen Douglas If I were to type the following commands: ggVj"zy, followed by :reg z, I would see Roy and Maurice. Now I want to yank Jen and Douglas into the z ...
2
votes
3answers
68 views

Copy command on first letter of each line until end of file

Please forgive me, I'm relatively new to Vim. I'm editing my .vimrc file. I'm adding the following lines: nnoremap <up> <nop> nnoremap <down> <nop> nnoremap <left> &...
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 ?
2
votes
1answer
71 views

Search and yank in visual line mode with execute normal

I have this in a buffer: aaa bbb ccc ddd eee with the cursor on the first line. I do :execute 'normal! jV/ddd\<CR>y' which I expect should result in the middle three lines yanked. But what ...
0
votes
1answer
86 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 ...
3
votes
2answers
334 views

Move cursor to end of visual block [duplicate]

When in visual block mode is there a way to cause to the cursor to switch to the end/beginning of the block? For example, in Excel this functionality is performed by the "." key. If the ...
2
votes
3answers
210 views

How to select a block in visual mode and delete this block and immediately enter insert mode?

for one single word, the job is quite easy: we just do a 'cw' what if I select a certain text and I want to replace this block with one word? obviously I can do a 'x' and then 'i', is there a one ...
3
votes
1answer
3k views

Vim ^V Visual Block mode not working

I am running Vim version 8.0.563 on Solaris and when I run Vim, the CtrlV block selection works as expected, I type ^V and move the cursor and a block of text is highlighted by columns. So far, so ...
0
votes
2answers
49 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
260 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
50 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
168 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
1k 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
43 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 ...
2
votes
3answers
63 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 ...
3
votes
3answers
118 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 ...
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
29 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
1answer
24 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>'<...
1
vote
1answer
70 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 ...
0
votes
1answer
68 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 ...
3
votes
2answers
129 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
1answer
35 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'...
12
votes
3answers
24k 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 ...
2
votes
3answers
318 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'...
4
votes
5answers
5k views

Copying lines when v is not implemented?

Is there any way to copy / paste blocks of text when v is not implemented?`
0
votes
1answer
62 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 ...
0
votes
1answer
42 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 ...
3
votes
1answer
142 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 ...
37
votes
11answers
5k 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 ...
2
votes
1answer
46 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 ...
5
votes
1answer
601 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") ...
3
votes
4answers
328 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
111 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 ...
3
votes
3answers
3k views

Run macro over a visual selection with line movements

I can find an answer to a similar problem here, however although I can get that example to function I can't get what I want to do to work. Here is the example text to be edited, a partial section of ...
0
votes
1answer
180 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
77 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 ...

1
2 3 4 5