Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
226
questions
3
votes
3answers
54 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
64 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
71 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
244 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
43 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
96 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
48 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
139 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
537 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
26 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
27 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
21 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
111 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
48 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
45 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
61 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
34 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
122 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
304 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
36 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
58 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
134 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
43 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
212 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
58 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
136 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
56 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
548 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
24 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
34 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
49 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
146 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
23 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
94 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
81 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
36 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
127 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
57 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
47 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
472 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
59 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
219 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
57 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
666 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
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 :'<,'>...
1
vote
1answer
86 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
79 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 ...