Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
236
questions
0
votes
0answers
21 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 ...
1
vote
1answer
24 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
20 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
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 ...
2
votes
1answer
40 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> &...
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
85 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
328 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 ...
0
votes
2answers
48 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
237 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
165 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
39 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
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
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
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>'<...
3
votes
3answers
117 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
66 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
62 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
68 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
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'...
3
votes
2answers
128 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
316 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
41 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
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 ...
3
votes
1answer
141 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
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 ...
3
votes
4answers
319 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
105 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
179 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
75 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
859 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
26 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
48 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
58 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
186 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
32 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
104 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
91 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
39 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
152 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 ...
5
votes
1answer
65 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 ...