Reputation: 55650
In most text editors, I can select text by clicking and dragging with my mouse, and then using Ctrl-C
to copy that text, or Backspace
to delete it.
However, since vim
runs in the console, if I highlight some text with the mouse, my vim
commands don't affect what I have selected.
What is the equivalent way to select text in vim
?
Upvotes: 116
Views: 138737
Reputation: 11800
First of all I would like to recommend highlight yanked text: https://github.com/machakann/vim-highlightedyank (vim and neovim)
This is useful because it will give you a visual hint of what you have just copied.
augroup highlight_yank
autocmd!
au TextYankPost * silent! lua vim.highlight.on_yank({higroup="IncSearch", timeout=700})
augroup END
Start spending more time reading about vim/neovim and you will not going back to any other editor.
Copy a whole paragraph to the clipboard:
"+yip
"+ .................... clipboard register
y ..................... copy
ip .................... inner paragraph
Copy the whole file to the clipboard
:%y+
Test some vim commands from the clipboard
:@+
The above command allows you to run functions and vim commands even if did not pasted them into your vimrc, there are some exceptions but in general it will work.
" vim line text-objects
xnoremap al :<C-u>norm! 0v$<cr>
xnoremap il :<C-u>norm! _vg_<cr>
onoremap al :norm! val<cr>
onoremap il :norm! vil<cr>
So you can use vil
or dil
Sometimes you don't need to select to copy If you wan to copy the second line to the end of the file you can do:
:2t$
If you want to move lines 4-7 to the beggining of the file you can do:
:4,7m0
ma .................. mark current line as mark a
Jump to a second place in your file and then
mb .................. mark current line as mark b
finally:
:'a,'by+
from mark a to mark b copy to the clipboard
Upvotes: 1
Reputation: 55650
In vim
, text is selected by entering Visual mode. This can be done in multiple ways.
:set mouse=a
.Once you have selected the text you want, you can use all sorts of commands on them. Some of the more useful ones are:
You can learn more about Visual mode by typing :help v
while inside vim
.
Upvotes: 196