Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
312
questions
0
votes
2
answers
56
views
Any default command to swap the selection text
I’m quite noob in Neovim, not sure if it has builtin feature of key command to swap the selection text with its " (clipboard) register.
So anyone kind enough to clarify or laborate ?
0
votes
1
answer
51
views
Vim visual block copy don't paste in KDE konsole
Selecting by visual line mode and copying (V and y) in vim in rxvt-unicode or in gnome-terminal and pasting in another tab of that terminal with Shift + Insert works well.
But trying to do the same ...
0
votes
1
answer
88
views
Why do I need to type ggVVG to select all, instead of just ggVG? [closed]
Sometimes, ggVG does not work to select text. It will move the cursor to the top, but not select the text. This happens seemingly randomly. I have figured out if I type ggVVG it will work as expected. ...
1
vote
1
answer
34
views
v_g_ctrl-g in neovim does not work
I am trying to find out the word count in selected text in neovim. For some reason, g_ctrl-g works perfectly fine in normal mode, but when I try it in visual mode after selecting some text, nothing ...
0
votes
1
answer
22
views
Why do text objects move the cursor to the end in Visual mode, but in the beginning in Operator-pending mode?
As far as I can tell, selection in Visual mode using most text objects results in the cursor being placed at the end of the text object region, whether that's linewise or characterwise.
However, using ...
0
votes
1
answer
61
views
Vim to drag current selected multi lines up
How do we have neovim to drag up current selected multi lines as
vim.api.nvim_set_keymap('x', 'I', ":m '<-2<CR>", { noremap = true, silent = true })
or:
vim.api.nvim_set_keymap('x',...
1
vote
1
answer
64
views
Paste in front or after in visual-block mode?
I can enter visual-block mode using <C-v>, move down a couple of rows by pressing j several times, then paste some content from the registry via pressing p or P. However, the pasting will ...
0
votes
2
answers
42
views
Select current Line from normal mode without changing cursor position AND without selecting the new line character at the end
What I am asking about can be done using multiple ways but none of them fully achieves what I want. For an instance :
0vg_ selects the current line without the new line character at the end but ...
0
votes
2
answers
31
views
How to use register expression with visual selection?
I have this key map in my Vim configuration:
nmap <leader>rn :%s/\<<C-r><C-w>\>/
But for this code from php I have a problem.
$text=$home_intro['text'];
Because, if cursor is ...
1
vote
1
answer
96
views
How can I accept a range in a Lua user command?
I want to optionally accept a range in a user-defined function:
vim.api.nvim_create_user_command('Pizzafy',
function(args)
if args.range > 0 then
-- visual mode, I think
...
0
votes
1
answer
27
views
Can the dot operator expand to the outer brackets if an inner pair was mistakenly highlighted during 'vib' (visualize inner brackets)?
( 2. can dot highlight this too?
( 1. 'vib' HERE selects this inner text ))
0
votes
0
answers
32
views
How to undo expanding selection in Vim? [duplicate]
I have this code snippet:
await sendtemplateemail({
recipient: invite.recipient_primary_email,
templateid: 'd-******',
templatedata: {
inviteurl: `${process.env....
0
votes
2
answers
92
views
How do I switch modes inside a user-defined lua function?
I want to write a command to do the following:
Make a visual selection.
Call a command on the visual selection.
By way of example, I'd like to call vat to visually select around the current tag, and ...
0
votes
1
answer
59
views
How can expand and contract visual selection from a tag block?
Say I have hierarchical markup like this:
<div id="level_1">
<div id="level_2">
<div id="level_3">
watermelon
</div>
</div>...
0
votes
1
answer
36
views
Keybinding to quickly update (aka prettify) React indentation
This is an example of the original code
<Text fontWeight="bold" size="lg" color="turquoise.500">Use Search V2 Beta</Text>
and I want a keyboard shortcut (say ...
0
votes
1
answer
56
views
keybindings that change mode: cannot use keybindings on the new mode
I have defined the following keybindings:
local opts = { noremap = true }
local ll = "<leader>i"
opts["desc"] = "Send visual lines"
vim.keymap.set("v", ...
2
votes
3
answers
183
views
Best way to keybind subsequent substitutions in visual mode
I need a keybinding that, given some text selected in visual mode (line visual mode, block visual mode, or whatever):
Add > _ before the text
Add _ after the text
In case of empty lines, > ...
4
votes
1
answer
416
views
Why does `yW` yank until the end of the WORD, but `W` move to the next one?
My confusion started with realizing, that yW yanks a different region, then what vW selects, but I found this that explains about selection. But then I realized, that while yW will yank until the end ...
2
votes
1
answer
66
views
Replace only inside visual selection (\%V) by default
I would like to always use \%V bounds when replacing inside visual selection. How can I make that behaviour default?
I'm currently using this keymap to achieve that, but I was wondering if there is a ...
1
vote
1
answer
59
views
Search and replace text in visual range but not entire line [duplicate]
I want to search and replace within a visual range just as was answered in this SO post, which uses :'<,'>.
But I don't want this to take place on an entire line, only within the selected subset ...
2
votes
1
answer
843
views
How to add a keymap for a visual mode plugin command and pass it the visually-selected range?
I have the linediff.vim plugin installed. Its main command :Linediff only works for visual mode, to which I'd like to add a keymap for this command.
I'm using Neovim's Lua API, so I tried this:
vim....
0
votes
1
answer
120
views
Pipe visual region to external command, not whole line
I have a keybinding nmap <leader>c :w ! wc<CR>, I wanted to expand it to work with visual regions (not just the whole file). I did so by creating vmap <leader>c :w ! wc<CR>, ...
2
votes
2
answers
222
views
How to wrap my visual selection with brackets using vnoremap?
Suppose, I want to wrap a single word with braces in normal mode using keyboard map (say <F5>), I could add the following mapping
:nnoremap <F5> i{<Esc>ea}<Esc>
But, now I ...
1
vote
2
answers
166
views
Why variables related to visual mode start with two uppercase letters in Vim source code?
In Vim sources, a lot of variables related to visual mode start with two uppercase letters:
EXTERN bool VIsual_active INIT(= false);
EXTERN bool VIsual_select INIT(= false);
EXTERN int ...
0
votes
2
answers
164
views
Cannot get block-wise visual selections in vimscript?
I am searching for how to get visual selection in vimscript. And I found this: https://stackoverflow.com/a/61486601/4438921, it is great, but the only issue is that, in block-wise visual mode, I ...
1
vote
1
answer
78
views
How to yank while in visual mode without showing message?
When I'm in visual mode and I yank the selection (which has at least 3 lines), messages like these are shown:
4 lines yanked
block of 4 lines yanked
How can I suppress this so it won't appear in :...
1
vote
1
answer
77
views
Vim also deletes the line under the selected region -- why?
To delete multiple lines, I highlight a line with Shift v. And then go down a few lines and press d.
When I do this, Vim deletes the selected lines and the line directly below it.
I am not sure what ...
1
vote
1
answer
52
views
Make operator that doesn't change gv
I'm trying to redefine my inner and outer line text objects so that they don't change gv. First I had
onoremap <silent> il :<C-u>normal! $v^<CR>
I changed it based on Using visual ...
0
votes
0
answers
54
views
What's controlling Vim paste behaviour?
What's controlling Vim paste behaviour via Vim over ssh using putty with right-click paste set to Linux host?
To start we have:
VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Mar 27 2023 00:00:00)
...
-1
votes
1
answer
56
views
find first non-blank column in visual selection
If I select all of these lines in linewise-visual mode
hi
there
how
do
you
do
How can I get the column number of the first non-blank character from the left? I.e. the minimum ...
1
vote
5
answers
626
views
Yank lines without leading whitespace
If I have code like this:
const treeData = {
name: "Parent",
children: [
{
name: "Child 1",
children: [
{
name: "Grandchild 1"
...
1
vote
2
answers
845
views
How to grab visual selection for search, but apply the appropriate escapes?
In this clip,
From visual mode here after selecting im.g.mat I trigger my vnoremap <m-/> y:%s/<c-r>0//g<left><left> bind.
The purpose of this bind is to initiate a global file ...
1
vote
2
answers
47
views
Why my visual selection buffer contains ^@
I am writing a function to reformat a visual selection:
function! FormatText() range
" Calling this function has ended visual mode, so it must be started
" again before the selection can ...
0
votes
1
answer
397
views
How to visually highlight text between these tags?
I'm new to Vim and trying to create a book how practical applications of Vim key bindings to R and Quarto based workflows.
Using R with Quarto we will typically encourage two code blocks:
```{r}
#| ...
0
votes
1
answer
79
views
Copying non-consecutive selected lines in visual mode
Basically I want to select and copy a bunch of non-sequential lines (some lines only partially) from different locations of a code, in a way that each yanked line is appended to clipboard register so ...
1
vote
1
answer
49
views
Why doesn't the dot command work after pasting in visual mode?
1. Why doesn't this work?
If my text file is:
aaa
test bbbb test
test bbbb test
test bbbb test
I can yank aaa, select bbbb in visual mode, and type "0p, to replace it with aaa, with the idea of ...
1
vote
1
answer
273
views
:normal o in visual mode WORKS
In my environment, invoking :normal in Visual mode does Visual mode command.
" A map for calling command without quitting visual mode
" It gets the cursor to the other side of selection
...
0
votes
2
answers
57
views
Selecting and manipulating around visual blocks
I'm particularly interested in what the presenter, Damian Conway, in this talk is doing as he selects the end of visual-block to effortlessly add quotes.
In particular - what is happening around 36:57
...
2
votes
3
answers
86
views
Run colon command on a movement / text object?
When I substitute text within a paragraph, I've always visually selected (e.g. vap), then :s/ ....
How to do this without the visual selection? More generally, how to apply a colon command on a ...
2
votes
0
answers
402
views
How to configure cursor shape in visual, visual block modes?
I configure cursor shape in normal, insert, and replace modes with the following in my vimrc
let &t_SI = "\<Esc>]50;CursorShape=2\x7"
let &t_SR = "\<Esc>]50;...
1
vote
1
answer
44
views
select until repeatedly
Is there a way to repeat the "select until" operation?
For example:
f(a, g(b))
If I want to select f(a, g(b)).
I would like to:
go to f then
do vf) which will select f(a, g(b) and then
do ...
1
vote
2
answers
1k
views
Select entire function call or extend selection
I have the following situation a lot, where I always end up having to yank two things in a row: For example, I want to yank a function call:
func(a, b)
Okay, here I can go to f and press vf).
But ...
2
votes
1
answer
132
views
Comment out just-pasted text?
In vim, I would like to operate on the block of text I just pasted. How?
For example, I select a block of text using shift-V, yank and then paste it somewhere. I would then like to comment that text ...
1
vote
1
answer
265
views
Sort from current column from visual selection
I am trying to write a :sort wrapper that sorts from current column.
command! -bang -range=% -nargs=* Sortc exe '<line1>,<line2>sort<bang> <args> /\%' .. virtcol('.') .. 'v/'
...
1
vote
1
answer
391
views
How can I prevent Vim from exiting visual mode?
If I enter visual mode, select some text, then run a command or press a keybinding, it will exit visual mode afterward because it assumes I am done.
But sometimes I want to do multiple things with ...
1
vote
1
answer
248
views
Mapping snippet trigger in visual mode
I'm using the UltiSnips plugin. When selecting text, you can press the trigger key to enter Insert mode, and the deleted text can then be used in a subsequent snippet. The snippet I'm using is as ...
3
votes
2
answers
957
views
Detecting the Enter and Leave of Visual mode event
Are there any events similar to InsertEnter and InsertLeave that I could use for visual mode?
Looking through the helpfiles, I did not fine any.
If not, how would I be able to detect if Vim enters or ...
6
votes
2
answers
5k
views
What does g CTRL-A really do?
Today I had that old feeling of wonder on how powerful VIM is: I needed a number sequence in the start of some fields and discovered the power of g CTRL-A.
So as I always do when I discover something ...
2
votes
1
answer
66
views
Different replace patterns depending on visual/visual line mode
I've written some customizations in my .vimrc that I would like to further improve and refine.
In particular, for some key combinations, I'm doing text substitutions, like this:
vmap <C-S-w> :s/\...
0
votes
1
answer
1k
views
How can I have multiple cursors while entering insert mode after Visual Block mode?
Let's say I have some text:
ipsum
ipsum dolor
ipsum dolor sit
I want to add the word "Lorem" in front of each line.
Loremipsum
Loremipsum dolor
Loremipsum dolor sit
I can do this by:
...