Mappings and commands for visual mode
From Vim Tips Wiki
Tip 1011 • Previous Tip • Next Tip
Created: October 6, 2005 Complexity: basic Author: Jean-Christophe Clavier Minimum version: 5.7 Karma: 0/2 Imported from: Tip#1011
For those who use visual mode, here are some commands and mappings that may be useful:
First of all gv reselects the previous visual area.
Prepare a :command on the previous visual selected area ('<,'> is slow to type):
map <M-:> :'<,'>
Copy the word under cursor in the clipboard:
nnoremap <F4> "+yiw
Copy the visual selected area in the clipboard:
vnoremap <F4> "+y
Replace the word under cursor with the content of the clipboard:
nnoremap <F5> viw"+p
Replace the visual selected area with the content of the clipboard:
vnoremap <F5> "+p
Prepare the :command to replace the word under cursor:
nnoremap <S-F4> "+yiw:%s/\<<C-r>+\>/<C-r>+/gc<LEFT><LEFT><LEFT>
Prepare the :command to replace the selected area:
vnoremap <S-F4> "+y:%s/\<<C-r>+\>/<C-r>+/gc<LEFT><LEFT><LEFT>
I use the clipboard but you can use whatever register you want.
This puts "" around the word under cursor:
nnoremap <M-"> ciw"<C-r>+"<esc>
This puts "" around the visual selected area:
vnoremap <M-"> c"<C-r>+"<esc>
[edit] Comments
One key <F7> does everything. Good for inter-window copying and pasting.
"copy vmap <F7> "+ygv"zy`> "paste (Shift-F7 to paste after normal cursor, Ctrl-F7 to paste over visual selection) nmap <F7> "zgP nmap <S-F7> "zgp imap <F7> <C-r><C-o>z vmap <C-F7> "zp`] cmap <F7> <C-r><C-o>z "copy register autocmd FocusGained * let @z=@+
