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
1 vote
1 answer
29 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
1 vote
1 answer
66 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
39 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
50 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
103 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
101 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
63 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
72 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
  • 627
0 votes
0 answers
86 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
0 votes
1 answer
40 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 ...
theonlygusti's user avatar
  • 2,219
0 votes
0 answers
34 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
30 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 ...
theonlygusti's user avatar
  • 2,219
1 vote
5 answers
295 views

Yank lines without leading whitespace

If I have code like this: const treeData = { name: "Parent", children: [ { name: "Child 1", children: [ { name: "Grandchild 1" ...
theonlygusti's user avatar
  • 2,219
1 vote
2 answers
294 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,231
1 vote
2 answers
39 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
221 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
58 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
31 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
131 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
49 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
0 votes
0 answers
15 views

Getting mode after feedkeys

I'm trying to run keys through feedkeys and extract what mode I end up with. Sadly every time feedkeys is run either it ends up in normal or the method hang. I tried with the "\<Ignore>&...
user1779331's user avatar
2 votes
3 answers
70 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
219 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
28 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
549 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
123 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
179 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
154 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
189 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
1 answer
548 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
3k 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
59 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
692 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
135 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
281 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
306 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
791 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
123 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
62 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
48 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,091
1 vote
1 answer
287 views

Vimscript: how to detect selection of a text object in visual mode?

I'm writing what may become a plugin that needs to know what is currently visually selected. To do it, I'm using the autocmd CursorMoved event to detect the creation of visual mode selections on the ...
mattb's user avatar
  • 1,091
1 vote
1 answer
435 views

Visually select two words in Vim

Say I have a phrase is later found at and what to delete a phrase later found, then what I do would be In the normal mode, I put a cursor on l, and press vww. This will select from l to a of at. This ...
Tom's user avatar
  • 379
1 vote
1 answer
661 views

Command to go to Normal-mode and Visual-mode (or exiting insert-mode) - pressing ESC without the escape-key

I'm working on a server, that I can only SSH into via a browser. In there, I have to edit some files. The problem is, that let's say I go to INSERT MODE and write some text. If I then want to go back ...
Zeth's user avatar
  • 395
0 votes
1 answer
178 views

Place visual selection inside of a variable inside of a command

I want to write a command that works with a visual selection, so I wrote something like this: command! -range Foo \ exec "norm \"ay" | \ echo "[" . @a . "]" ...
Jake's user avatar
  • 213
0 votes
1 answer
51 views

How to select a whole line except beginning tab/space and last enter?

I'm dealing with the following text and want to select "abc def": 123 abc def 456_4 I've tried viw but it can only select a whole word isolated by spaces, and v$ starting with ...
Mactarvish's user avatar
0 votes
1 answer
74 views

How can I detect which way vim is going into visual mode (from up to down or from down to up)?

This is related to better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code. I need to be able to detect which way vim is going into visual mode so that I can ...
Mega Bang's user avatar
  • 199
2 votes
1 answer
398 views

better copy-paste multiple lines in visual mode where vim pastes after that visual chunk of code

I want to select multiple lines in vim, copy them, and paste after that chunk of code (with cursor at the beginning). yp doesn't work because in visual chunk of code, vim pastes after the 1st line of ...
Mega Bang's user avatar
  • 199
4 votes
0 answers
205 views

Pasting from vim to an ipython terminal

I have an open ipython terminal open, and I'd like to paste the visual selection to it, with prepending "%cpaste" and appending "--" This is what I came up with function! ...
Uri Goren's user avatar
  • 141
0 votes
0 answers
139 views

Is there a modification to make the dot command work intuitively in visual mode?

This is a repeat of a question that I asked on the Vim subreddit but didn't receive a helpful answer for. I think that this should be do-able, but I'm not good enough at Vimscript or Lua yet to ...
Jordan Mandel's user avatar
3 votes
2 answers
319 views

Is it possible to properly repeat a visual replacement?

It is possible in vanilla vim to: visual select some number of characters, e.g. a variable name in code type c to begin replacing selection in insert mode type a replacement (variable name) exit ...
Steven Lu's user avatar
  • 2,231

1
2 3 4 5 6