Questions tagged [visual-mode]
Visual mode is a flexible and easy way to select a piece of text for an operator.
261
questions
3
votes
1
answer
66
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
57
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>:...
0
votes
2
answers
51
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
39
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
0
answers
12
views
Insert ordered list in visual mode? [duplicate]
In visual (or visual block) mode, how do I insert an ordered list?
For example, convert
foo bar baz quux
corge grault garply
waldo fred plugh
xyzzy thud
to
1. foo bar baz quux
2. corge grault ...
0
votes
1
answer
28
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
19
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
49
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
33
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
24
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
24
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
40
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
41
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
86
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 ...
3
votes
0
answers
42
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
34
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
86
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
393
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
22
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, ...
0
votes
1
answer
82
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
58
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 :'&...
1
vote
2
answers
98
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
57
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
51
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
41
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
34
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
39
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
36
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
211
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 ...
0
votes
1
answer
37
views
"Visual around two Words"?
If I type 2daW, I can delete the current Word and the next (though I can't really see that case covered in the manual).
Is there a way to visual-select around two words? I tried 2vaW, but of course (...
1
vote
1
answer
55
views
Configure Vim 8 behavior regarding substitution in visual selection
When I select a section of text within a line, then indicate I want to substitute on that line with :s, the result is that the entire line is affected.
In order to actually do what I intend, I have to ...
3
votes
2
answers
67
views
Why \%V is not added in visual mode during substitution by default?
\%V can be used to restrict match within the visual selection. However, I can't think of a situation when one would not want to do just that in visual mode.
0
votes
1
answer
69
views
Cause vi's visual mode to go in opposite directions? [duplicate]
If I enter visual mode I can select lines either up xor down, but not both. Is there a way to make vim do both?
I'm particularly interested in this for purposes of searching, entering visual mode, ...
1
vote
2
answers
36
views
How to remove periods within visual selections in a cmd composition?
I'd like to remove the period between the 6th comma and the 9th comma for the multiple lines of the following texts.
Change from:
4,Afghanistan,2,Medium,1951,1951.5,4134.756,3705.395,7840.151,12.009
4,...
0
votes
1
answer
39
views
Yanking into register within a script is not working
Given a file like this:
Roy
Maurice
Jen
Douglas
If I were to type the following commands: ggVj"zy, followed by :reg z, I would see Roy and Maurice.
Now I want to yank Jen and Douglas into the z ...
2
votes
3
answers
116
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
1
answer
87
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
1
answer
119
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
2
answers
1k
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
2
answers
220
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:...
4
votes
2
answers
3k
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.
Or, select multiple ...
3
votes
1
answer
52
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
1
answer
921
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 ...
1
vote
1
answer
5k
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
1
answer
143
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
1
answer
35
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
0
answers
29
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
1
answer
80
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
3
answers
280
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
1
answer
136
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 ...