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
6
votes
1answer
348 views

Which text object defines text enclosed in space?

Since I need to operate on a sequence of symbols between spaces I'd like to know which text object defines it. Here is an example: 45908 Sep 24 21:31 [r].t3891993.tr some another text. ...
0
votes
2answers
686 views

Use visual mode to convert text to unicode bold formats?

How can I make it so when in visual mode, pressing b will toggle highlighted text to its bold unicode counterpart? This is what I mean by its Unicode counterpart: http://qaz.wtf/u/convert.cgi?text=...
3
votes
1answer
158 views

Search and replace a visual selection in the whole file

I want to search and replace the selection I made in Visual mode. For example I have the following text: Lorem ipsum dolor sit amet. Consectetur adipiscing elit. Sed quis gravida lectus amet. And ...
1
vote
1answer
38 views

How would I modify this function to restore from a specified register?

Currently I have the following mapping in my vimrc nnoremap d "_d nnoremap D "_D nnoremap C "_C nnoremap c "_c nnoremap <leader>d "*d nnoremap <leader>D "*D" The result of the above ...
1
vote
1answer
535 views

How can I create a mapping only in “plain” visual mode?

Currently, my vimrc contains the lines nnoremap j gj xnoremap j gj nnoremap gj j xnoremap gj j nnoremap k gk xnoremap k gk nnoremap gk k xnoremap gk k This way, the j key in both visual and normal ...
2
votes
2answers
7k views

How do I restore visual mode selection highlighting?

Somehow, over the last few days, the visual mode in Vim no longer flips the background highlight, as it used to. Now, if the file is recognized by something it can syntax highlight, it seems to ...
2
votes
1answer
230 views

Using visual mode without changing gv

I'm working on a plugin and I use visual selections all the time in my code. Stuff like normal! v{:call whatever()\<cr>. The problem is that if the user does gv in his file it won't select his ...
2
votes
1answer
63 views

Running find-and-replace in Visual Mode :'<,'>s/^/string/g inserts “string” at 0 position instead of ^ (first non-whitespace) position

I have some visual-mode commenting macros that should place a comment character g:CommentChar before the first non-whitespace character of each line in the selection. However, it places it right of ...
2
votes
2answers
693 views

How to keep Vim from exiting Visual Mode due to mouse clicks while mouse=a?

Currently when I click somewhere in the terminal with mouse=a enabled, Vim exits visual mode. How can I force Vim to remain in Visual mode, and thereby use mouse clicks (not drags) to create a ...
1
vote
1answer
922 views

How to set functionality of <BS>

I just realized that the standard setting of is actual not 'going back one space', but deleting everything selected. Is there some basic way to get that some functionality in Vim visual mode, without ...
1
vote
4answers
135 views

Way to do mulitple substitutions on selection

When I visually select text and enter : I'll get this: :'<,'> Now I can enter a substitution to be done on those lines. However, what if I wanted to do several substitution, e.g. foo to bar ...
0
votes
2answers
105 views

How to paste a line inside another line ? i.e. How to paste a line as words?

I would like to easily transform these two lines : One line. long line with many words in this example into the line : One long line with many words in this example line. How I currently do ...
6
votes
5answers
414 views

How to ignore a column when visually selecting a paragraph

I have a file that looks like this: # Section 1 # # new: a.txt # new: b.txt # # # Section 2 # # [n]ew: c.txt # new: d.txt # new: e.txt # My cursor is on the first new of the second section and I ...
8
votes
1answer
228 views

Perform previous substitution for different selection with single keystroke

I performed following command :'<,'>s/2/digit/g on the code below manually visually selected: return _.round(this.getTotalAbs(), 2).toFixed(2); And it worked as intended return _.round(...
16
votes
3answers
1k views

How do you indent > < without leaving visual mode and losing your current selection?

I often have to manually indent, but when I enter a visual mode, select my lines to indent, and press < or >, I leave visual mode whether I want to or not. I would rather have it so I stay in ...
6
votes
1answer
605 views

Expand visual selection to inner curly braces

Let's say I have this piece of code (cursor/selection is represented by []): [f]unction a() { // ... } If I want to select the function declaration and the curly braces (and of course the ...
2
votes
1answer
242 views

Why is the visual selection represented by these characters: '<,'> ? Can it be parsed?

While I can understand the percentage sign % being chosen to represent the current file, just because you need to choose some character for that, I am curious as to why '<,'> is representative ...
5
votes
1answer
2k views

How to I get around “normal” exiting visual mode?

I'm trying to write a vimscript function that moves the cursor all the way up or all the way down without changing the column. (similar to the way :set nostartofline works). It works, but when I ...
5
votes
3answers
387 views

Way to get content of Visual Selection?

Now if I select something in visual mode, is there some way to get the selected area without having to yank it to some register? I looked through :h functions but didn't find anything.
4
votes
5answers
5k views

Copying lines when v is not implemented?

Is there any way to copy / paste blocks of text when v is not implemented?`
4
votes
1answer
161 views

Motion to jump back one level of indentation, not including blank lines

I've been authoring a lot of F# in Vim lately. Like Python it is pretty strictly indentation-based. However, unlike Python mode for Vim, it does not appear that the standard F# Vim plugin supports any ...
2
votes
1answer
73 views

Use motion in normal mapping calling a function

I have this function which displays line numbers. I want it to be called in different ways: from a command, specifying the lines as arguments with a visual selection, printing the first and last line ...
3
votes
1answer
78 views

How do I loop over a list of files from a visual selection?

Code in .vimrc which starts graphical Neovim on a filename when pressing gff % http://unix.stackexchange.com/q/277918/16920 :nnoremap gff :silent! exec "!gnvim " shellescape('<cfile>') <bar&...
0
votes
0answers
161 views

Why doesn't select mode appear in the status line?

Regardless of the mode I select, it appears on the status line. But when I switch to select mode, it is not shown on the status line in Vim, whereas it is shown in gVim. How do I make it work?
2
votes
1answer
480 views

How do I :substitute inside a selection? [duplicate]

The command :'<,'>s/search/replace/g will replace in the whole line of the current selection, but what if I want to substitute only inside the current selection, not the whole line? Update: ...
2
votes
1answer
762 views

CTRL-A with visual mode not working

According to the Vim help, using g CTRL-A with visual mode should change several lines in A to that in B: A: 1. 1. 1. 1. B: 1. 2. 3. 4. In my Vim, the CTRL-A is working in ...
11
votes
1answer
3k views

Mapping a command in Visual Mode results in error E481: No range alllowed

I'm trying to make a keyboard binding in Neovim that would send a selected block to the opened Neovim terminal. I've used these answers as guidelines https://vi.stackexchange.com/a/3390/3405 https://...
9
votes
1answer
180 views

How to modify visually selected block with external command?

I have a file that is made up of two vertical parts. On the left side, the data is already formatted and I don't want to change it. I only want to format the data on the right side. Say I have a file ...
2
votes
1answer
470 views

How to add some text to selected text and reselect it again in visual mode?

I'm using QuickRun to execute php files or part of php code by selecting it in Visual Mode. I have this mapping in my .vimrc nnoremap <leader>r :QuickRun<CR> vnoremap <leader>r :...
4
votes
2answers
935 views

How to visual select from vimscript

In Mac OS, I am trying to write a function that will say the current paragraph without moving the cursor, but something doesn't seem to work. This is what I have so far: function! SayIt() let l:...
4
votes
2answers
156 views

Why is substitution applied outside the selected region?

Consider this string: 1 1 1 When I mark the first two 1s in visual mode and then :'<,'>s/1/2/g, all 1s on the line are replaced by 2s, not just those in the selected region. Why is this the ...
5
votes
1answer
704 views

Visual block editing: map i

How to map i to start editing on visual block mode? I want the same behavior for <shift>-i and i.
5
votes
1answer
221 views

How to disable the clipboard being overwritten when highlighting text in visual block mode?

Say I've got a URL in the clipboard, I enter vim, I hit <C-Q> and highlight a word. Then I hit I<C-R>+ to insert the clipboard at the start of the selection. What actually happens is the ...
3
votes
1answer
354 views

Visual block insert into multiple areas with no text with virtualedit=all

When I do a visual block insert with virtualedit=all I want to insert into all selected lines regardless of what text is already in those lines. Instead the behavior I get is that the line where I ...
3
votes
1answer
204 views

Can I edit visually selected text in a different buffer?

I often use vim via terminal wrapper (e.g. gnome-terminal --disable-factory --command='vim /tmp/firefox12345.txt') to edit a textarea on websites, e.g. when writing this question. Whenever I put in a ...
1
vote
0answers
29 views

Is there a way to reselect the last pasted text, rather than the last actual selection, starting at the current cursor position? [duplicate]

I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to select the block of text that I just pasted. This is useful e.g. for sending example ...
9
votes
2answers
2k views

Is there a way to reselect the last visual shape, rather than the last actual selection, starting at the current cursor position?

I know that gv reselects the last visual selection. This is great and I use it frequently. But sometimes I want to do something related but different: from the current cursor position, select a block ...
3
votes
1answer
345 views

Visually select a few lines given start and end positions in vimscript

I want to write a function that will remove blank lines given a set of visually selected lines by the user. After removing the blank lines, I want the input lines still be visually selected. How ...
2
votes
2answers
1k views

visual mode gq not reflowing comment block

I am looking for an easy way to reflow blocks of comments (in GO). According to this post I should be able to just run gq on a block and it will reflow automatically, but this doesn't seem to work. ...
13
votes
3answers
3k views

How can I source a visual selection of vimscript?

If I have a couple of lines of vimscript that I want to test before putting in my vimrc, is it possible to visually select, then source them? I have tried make visual selection v, then motions to ...
3
votes
3answers
218 views

Moving the Visual Area at once

Is there a shortcut to move the Visual area as a whole? For instance, after entering Visual mode linewise to make the next line selected. Right now this is achieved by: V Start Visual mode linewise ...
3
votes
1answer
2k views

Select text till and including pattern

I want to select text from multiple lines up till and including the pattern pattern. When I use v/pattern the text till attern is selected (not including attern). How can I select text including ...
2
votes
1answer
187 views

Displaying the number of lines you have selected in Visual Mode?

Is there a command to display a count of the number of lines you have selected in Visual Mode in VIM?
1
vote
1answer
49 views

Is there a way to perform more than one Ex-mode action on the current visual selection?

This would be particularly useful for macros, i.e., select visually the exact lines I want to perform the macro on, and then run the macro. But currently when it finishes the first action, the visual ...
3
votes
1answer
668 views

Can I select and edit specific positions in lines while in visual block mode?

say for example, I have this text: <div class="test1"></div> <span class="highlight"></span> <nav class="tester"></nav> <aside class="wrapper"></aside> ...
5
votes
1answer
161 views

Applying an ex command to a visual selection or text object

Is it possible to apply an ex command to something smaller than a line? For instance, I tried to define a mapping that would remove an \emph{} from the enclosed word. The best I could do was: ...
53
votes
1answer
13k views

What is the select mode and when is it relevant to use it?

I accidentally pressed gh in normal mode and started a selection, so I looked up the doc and found :h Select-mode. From what I understand the select mode is close to the visual mode excepted that: ...
6
votes
2answers
932 views

How to paste a line in a vertical selection block?

Consider the following text: long foobar=(test); int barbar=(something); char foofoo=(); Suppose I have yanked some chunk of code which I want to place before each opening parenthesis, e.g. ...
19
votes
8answers
10k views

Quickly calculate the total of a column of numbers

I'm writing down a markdown table which looks like this: | 13/05/15 | 09:30-16:00 | 6.5 | | 14/05/15 | 10:00-16:30 | 6.5 | | 16/05/15 | 15:30-01:00 | 9.5 | | 21/05/15 | 09:00-16:30 | 7.5 | | 22/...
11
votes
3answers
23k views

How to add space on multiple lines when pressing spacebar (without extra configuration)?

I tried visual block, but visual block only allow to highlight or delete characters on multiple lines. Is there any function that allows to add space before the first character of multiple lines when ...