I know I can do this by pressing Insert in INSERT mode, but that requires some stretching. Is there any more convenient shortcut to go directly from NORMAL mode to REPLACE mode?
From the ViM manual:
5. Replace mode *Replace* *Replace-mode* *mode-replace*
Enter Replace mode with the "R" command in normal mode.
Of course you can map any key to R, for example by doing
:map <F5> R
You can press R and you'll get into the REPLACE mode.
R brings you into replace mode.
You have to press R to go to replace mode. For this, you must first be in non-editing mode
In normal mode, press Shift+R.
r will replace a single character.
Related
I want to achieve the following using a key shortcut in Vim:
hi
| <-my cursor is here
there
press shift+o
hi
| <-my cursor is here
there
press enter
hi
| <-my cursor is here
there
The following mapping should be enough
nn <Leader>o O<CR><Esc>
Note
<Leader> is a "special key" that you can set (cf. :h <Leader>)
you can choose your own key combination to trigger the mapping, not necessarily <Leader>o
<Esc> is to go back to normal mode. Given How O and o work maybe you want to remain in insert mode? If so, remove <Esc>.
You are looking for :help mapping. Mapping keys is when you map one key or several keys to act like other keys. In your case, this is a map you might use:
nnoremap (your chosen key(s)) O<CR>
This means that in normal mode, when you hit your chosen key(s), vim will instead act as though you hit O and then <CR>. <CR> is how you indicate the 'Enter/Return' key.
This is assuming you meant you wanted to start from normal mode.
gVim 8.0
When I press Ctrl+V in insert mode (or in Ctrl+: mode) I got this v-like symbols inserted instead of my current clipboard text.
Why does it happen? How do I get it back to normal?
Thank you.
CTRL-V means "Insert next non-digit literally." I.e. if you press Ctrl-V twice vim inserts "CTRL-V" into the text and displays it as "^V".
To paste a buffer switch to normal mode and use p or P. You can temporary switch to normal mode with Ctrl-O; e.g. Ctrl-Op.
The problem was caused by the omission of this line: source $VIMRUNTIME/mswin.vim from _vimrc file.
If you are on insert mode use Ctrl-r + .
Looking at :h registers you will see that + means clipboard register and Ctrl-r helps us to insert any register on insert mode.
In normal mode you can just type: "+p
As being said Ctrl-v on insert mode is used to insert special chars. To learn more :h i_Ctrl-v
*i_CTRL-V*
CTRL-V Insert next non-digit literally. For special keys, the
terminal code is inserted. It's also possible to enter the
decimal, octal or hexadecimal value of a character
|i_CTRL-V_digit|.
The characters typed right after CTRL-V are not considered for
mapping.
Note: When CTRL-V is mapped (e.g., to paste text) you can
often use CTRL-Q instead |i_CTRL-Q|.
Based on the idea of quick command in insert mode I want to insert my OS clipboard when I am in the insert mode. To make that happen as I want, I have to add a whitespace in the inoremap call, but I do not know how?
This is done with
inoremap VV <Esc>"+gP
Using this:
"vim" is in the OS clipboard
Typing in insert mode "work smart with VV"
leads to the result
work smart withvim
What I want is a whitespace between with and vim
work smart with vim
Any suggestions?
Your issue is caused by the P in "+gP and by the fact that leaving insert mode moves the cursor one character to the left, on the <space>.
P pastes before the cursor so your mapping pastes before the <space>. Changing the P to p should "fix" your problem, in a superficial way.
Here is a more solid alternative that inserts the content of the clipboard register right after the cursor without leaving insert mode:
inoremap VV <C-r>+
Well… what about simply using <C-r>+?
Working around a side effect (here, pasting after the cursor) is not the same as avoiding that side effect (here, not leaving insert mode to begin with). Guess which one is the right approach? ;-)
Use
inoremap VV <Esc>"+gp
P places the clipboard before cursor, p after cursor.
Option 1.
inoremap VV <C-R><C-o>+
Ctrl-R tells vim to insert the contents of a register, and + is the OS clipboard register. It inserts the clipboard contents as if you typed them. The additional <c-o> makes the register contents get inserted literally, so that things like <esc> or ^H (backspace) aren't interpreted like you typed them, but are inserted as text.
Option 2.
inoremap VV <C-o>"+gp
C-o tells vim to go to normal mode for just one command, so you don't need to add <Esc> at start, or i at the end.
Is there a method in OS X such that Vim will enter insert mode automatically and copy text, instead of having to enter insert mode first and press command + V?
Or more generically, how to map command keys in Vim in OS X? I use command line Vim, not MacVim.
Add this to your vimrc:
nnoremap <c-v> p:startinsert!<cr>
This will insert your clipboard content and place the cursor after the inserted text and change to insert mode.
But why you want insert mode altogether? Just press p in normal mode!
Is there a way to jump to the next word when in the insert mode. Something similar to w when in non-insert mode or Ctrl+Left or Ctrl+Right in windows?
There's a very useful table of insert mode motions at :h ins-special-special.
<S-Left> cursor one word back (like "b" command)
<C-Left> cursor one word back (like "b" command)
<S-Right> cursor one word forward (like "w" command)
<C-Right> cursor one word forward (like "w" command)
You'll find that Shift-Left/Right and Ctrl-Left/Right will do the trick.
Ctrl/Shift with cursor keys isn't guaranteed to work flawlessly in all terminals, however. You can avoid any problems entirely by using a mapping. Here's one right on to the home row:
:inoremap <C-H> <C-\><C-O>b
:inoremap <C-L> <C-\><C-O>w
Now use CTRL-H and CTRL-L to move by word in insert mode.
However, please be aware that many Vimmers prefer not to move at all in insert mode. That's because once you have moved in insert mode, the . command loses its utility, as does CTRL-A and maybe some other commands.
For me, the Vim way of jumping to the next word in insert mode is <C-[>wi and it's become completely automatic.
With <CTRL-O>, you can execute one command without exiting insert mode.
So you can try <CTRL-O>w, <CTRL-O>3w, etc.
You can move one word forwards/backwards in Insert mode by holding down either Shift or Control and pressing the right or left arrow key.