Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
282
questions
-1
votes
0
answers
29
views
The key i to insert two double quotes at the current position is not working
On Vim, I try to record a key sequence macro to surround a selected text in double-quotes.
First, I select a string of text and press key q
followed by a register key to associate the macro, here I ...
1
vote
2
answers
41
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
31
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
51
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}
#| ...
-1
votes
1
answer
31
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
20
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
30
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
41
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
...
0
votes
0
answers
13
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>&...
2
votes
3
answers
55
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 ...
1
vote
0
answers
75
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
25
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
118
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
115
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
61
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
39
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
90
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
1
answer
230
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 ...
5
votes
2
answers
2k
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
51
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
219
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:
...
1
vote
1
answer
74
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 ...
3
votes
1
answer
156
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>
...
2
votes
1
answer
184
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>:...
2
votes
2
answers
411
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,...
1
vote
1
answer
73
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 ...
0
votes
1
answer
42
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 ...
0
votes
0
answers
36
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 ...
0
votes
1
answer
167
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 ...
1
vote
1
answer
189
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 ...
1
vote
1
answer
134
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 ...
0
votes
1
answer
113
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 . "]"
...
0
votes
1
answer
47
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 ...
0
votes
1
answer
53
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 ...
2
votes
1
answer
313
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 ...
4
votes
0
answers
140
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! ...
0
votes
0
answers
72
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 ...
3
votes
2
answers
221
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 ...
7
votes
1
answer
522
views
How to prevent Vim from clearing the system clipboard (:reg +) on exit?
After copying text to the system keyboard clipboard in vim, I'm unable to paste the text after exiting vim.
I find this behavior frustrating, since I often copy text in files to paste it on the ...
0
votes
0
answers
61
views
How can I highlight in visual block mode all text between two delimiters over multiple lines?
I have a tab-separated spreadsheet and I'd like to highlight in visual block mode by selecting a character, expanding the visual highlight region to the whole entry between the two tab characters, ...
1
vote
1
answer
282
views
How to delete .yaml elements like maps or arrays efficiently in Vim?
I often need to edit huge .yaml files, where I need to delete entire maps or arrays.
My current approach is to go into visual (line-wise) mode (Shift + V) and mark the lines manually, but that feels ...
1
vote
1
answer
115
views
What is the `:'<,'>` in the command line?
When I press : from visual mode, the command line is pre-populated with :'<,'>. It seems to affect how my substitutions work.
What do the characters mean and why are they inserted?
How does :'&...
2
votes
2
answers
293
views
How to make an user-defined command that works in normal and visual mode?
Goal
I would like to create a command that can automatically put an x inside a [].
This command should work in both normal mode and visual mode.
normal mode
If it is in normal mode, and the cursor is ...
0
votes
1
answer
75
views
Visual Select Range of Lines and Sort IP Adresses
I have a mapleader macro to sort IP addresses and delete leading 0 in IP addresses
let mapleader='ip'
map <leader>ips :%s/0\+\([0-9a-f]\)/\1/ | %sort n /.*\./ | %sort n /\.\d\+\./ | %sort n /\./ ...
2
votes
0
answers
114
views
Remove one level of all Vimwiki headers in a selection
In Vimwiki, a header level can be decreased, by pressing -.
Is there a native Vimwiki command to remove a level from all headers within a visual selection?
Keep in mind that Vimwiki supports a number ...
0
votes
1
answer
111
views
Can I execute the make command only on selected lines?
Let's say I have the following script:
sudo apt update
sudo apt upgrade
sudo apt install jq
sudo apt install jo
If I use the command :set makeprg=bash\ % | make inside Vim, the system will ask me my ...
0
votes
0
answers
35
views
Chronologically store visual selections in a buffer
My goal is to enhance the usage of gv with counts, in order to access older selections quickly. Such that 2gv would reselect the selection made before the last.
Vim doesn't have events for entering ...
1
vote
1
answer
42
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
1
answer
106
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
0
answers
503
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 ...