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
2 answers
21 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 ...
serii 's user avatar
  • 91
1 vote
1 answer
25 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 ...
Sasgorilla's user avatar
0 votes
1 answer
23 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 ))
chapel's user avatar
  • 11
0 votes
0 answers
27 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....
abbood's user avatar
  • 733
0 votes
2 answers
77 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 ...
Sasgorilla's user avatar
0 votes
1 answer
40 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>...
Sasgorilla's user avatar
0 votes
1 answer
34 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 ...
abbood's user avatar
  • 733
0 votes
1 answer
35 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", ...
robertspierre's user avatar
2 votes
3 answers
111 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, > ...
robertspierre's user avatar
4 votes
1 answer
397 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 ...
fbence's user avatar
  • 677
1 vote
1 answer
39 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 ...
Rizhiy's user avatar
  • 143
1 vote
1 answer
39 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 ...
N. Syiemlieh's user avatar
2 votes
1 answer
403 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....
Jethro Cao's user avatar
0 votes
1 answer
72 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>, ...
Le-Kat's user avatar
  • 3
2 votes
2 answers
137 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 ...
Taimoor Zaeem's user avatar
1 vote
2 answers
134 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 ...
Feedforward's user avatar
0 votes
2 answers
133 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 ...
linrongbin's user avatar
1 vote
1 answer
73 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 :...
Steve Ward's user avatar
1 vote
1 answer
74 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 ...
Vinn's user avatar
  • 781
0 votes
0 answers
124 views

Search forward / backward (`*` / `#`) in visual select mode

This seems to be a mismatch in behavior between Vim and Neovim. In Vim, when in visual selection mode, * and # work as expected: they jump forward / backward to the next occurrence of the word under ...
phg's user avatar
  • 197
1 vote
1 answer
47 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 ...
minseong's user avatar
  • 2,323
0 votes
0 answers
46 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) ...
chipfall's user avatar
  • 103
-1 votes
1 answer
43 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 ...
minseong's user avatar
  • 2,323
1 vote
5 answers
473 views

Yank lines without leading whitespace

If I have code like this: const treeData = { name: "Parent", children: [ { name: "Child 1", children: [ { name: "Grandchild 1" ...
minseong's user avatar
  • 2,323
1 vote
2 answers
648 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 ...
Steven Lu's user avatar
  • 2,251
1 vote
2 answers
42 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 ...
Konstantin Glukhov's user avatar
0 votes
1 answer
352 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} #| ...
alejandro_hagan's user avatar
0 votes
1 answer
68 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 ...
Puya's user avatar
  • 15
1 vote
1 answer
34 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 ...
Zantier's user avatar
  • 111
1 vote
1 answer
194 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 ...
Dugesia7's user avatar
0 votes
2 answers
53 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 ...
shalomb's user avatar
  • 101
2 votes
3 answers
77 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 ...
Ana's user avatar
  • 141
2 votes
0 answers
328 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;...
Aaron Parisi's user avatar
1 vote
1 answer
36 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 ...
lo tolmencre's user avatar
1 vote
2 answers
977 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 ...
lo tolmencre's user avatar
2 votes
1 answer
128 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 ...
Ana's user avatar
  • 23
1 vote
1 answer
220 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/' ...
balki's user avatar
  • 355
1 vote
1 answer
269 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 ...
Amarakon's user avatar
  • 261
1 vote
1 answer
217 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 ...
Alex867's user avatar
  • 33
3 votes
2 answers
788 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 ...
unrealapex's user avatar
6 votes
2 answers
4k 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 ...
Nelson Teixeira's user avatar
2 votes
1 answer
64 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/\...
Jonas Mechtheim's user avatar
0 votes
1 answer
957 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: ...
Amarakon's user avatar
  • 261
1 vote
1 answer
165 views

Automatically highlight visual selection matches

Since there are no VisualEnter and VisualLeave events, I am trying to make a function that will activate on every cursor movement in visual mode, i.e. it will automatically highlight all the matches ...
lobelk's user avatar
  • 21
3 votes
1 answer
336 views

Duplicate selected lines programmatically

I'm creating a Vim script and a critical part of it is duplicating the selected lines. To duplicate lines, I have this mapping which works as intended: vnoremap <Leader>d :copy '><CR> ...
Ranel Padon's user avatar
3 votes
1 answer
377 views

How can I call function in visual mode

I want a function to change underline word to little camel for one line. When I use <shift+v>:s/_\(\w\)/\u\1/g, it work fine. And then I want to make a function to simplify it, <shift+v>:...
Sangria's user avatar
  • 33
2 votes
2 answers
1k views

Stop Vim from yanking visual selected text

Let's say I have a file like this (abc) (123) (456) I want to yank abc and paste it in place of 123 and 456. I would yi) on the first line. Then go down a line and paste it with vi)p. But for the 456,...
Tai Nguyen's user avatar
1 vote
1 answer
153 views

Directly using keymapping inside a function

So, I'm usually used to making (decently) complex mapping, and sometimes, I'd like to run mapping on very specific conditions. Let's take for example a simple premise: first line second ... long text ...
Nordine Lotfi's user avatar
0 votes
1 answer
70 views

Run macro on visual selection only. [Evaluate an Iterator to consecutive numbers]

How can we run the macro on only the visual selection? The macro that we want to run is / id: 1,^Mf1s^R=i^M<C-c>:let i += 1^M (where (as given in this SO answer) ^M happens to be the way vim ...
HarshvardhanSharma's user avatar
0 votes
0 answers
54 views

Detect new visual selection with vimscript

I asked a related but different question here. I'm writing the vim-visual-history plugin that keeps a traversable history of previous visual selections. To detect the selections, I'm using: autocmd ...
mattb's user avatar
  • 1,131

1
2 3 4 5
7