After entering some text at the end of the line and exiting insert mode I have the cursor moved to the beginning of the next line. I would like to prevent this.
It suprisingly was a linefeed character (or maybe some other character) in .vimrc interpreted by vim as command.
I have the following lines to remap mode change to '
:nnoremap ' i
:inoremap ' <esc>
Apparantly CR somehow occured to be after <esc>. Since there is no text after, I presumed it could be some whitespace character. All I had to do is to place the cursor after <esc> and delete all trailing invisible symbols. And it did the trick.
Related
I have my cursor between two lines in vim:
I would do this in a 'normal' editor by pressing ctrl-d to delete the characters after the cursor. What would be the most efficient way to do this in vim?
Your current cursor is at ,:
if you want to remove the linebreak: press J
if you want to remove the ',' : press x
if you want to remove the closing single-quote ': press X
If you want to join lines with no space in beewin them press
gJ
If you want to remove the rest of the line in insert mode:
Ctrl-o D
To map this action, you can put this on your ~/.vimrc
" delete the rest of the current line
inoremap <c-k> <c-o>d
I'm not suggesting maping Ctrld because it is already mapped to decrease indenting, in oposition to Ctrlt
I am trying to have a remap in my vimrc that adds a snippet, then goes to the next line in Insert mode:
:nnoremap <leader>b oimport pdb;pdb.set_trace()<esc> o
The snippet import pdb;pdb.set_trace() gets inserted into my current buffer, but the cursor in vim remains on the same line. Is there any way to have the cursor move to the next line after inserting the snippet?
For me, your mapping works, except at the end of the buffer (where it beeps and keeps the cursor at the end of the inserted line, as you report).
The reason is the space between the <esc> and o. :help <Space> is a motion (to the right, just like l), and if the cursor cannot move there (at the end of the buffer, maybe also elsewhere depending on the 'whichwrap' option), Vim beeps and aborts the mapping; i.e. all keys that come after that are ignored.
The fix is easy: Drop the superfluous whitespace, and the mapping will work everywhere!
nnoremap <leader>b oimport pdb;pdb.set_trace()<esc>o
How about this:
nnoremap <leader>b oimport pdb;<CR>pdb.set_trace()<CR>
If I press Enter in Vim it always takes the cursor to the beginning of line. I need it to be tab ordered just like in Visual Studio, please let me know the required settings.
Depends on what you mean by "tab ordered"
if you mean automatically indenting on a newline in insert mode then the setting is: filetype indent on
if you mean to go to the first non-whitespace character on the next line in normal mode then you can use nnoremap <CR> <CR>^
I have remapped <C-Space> to <Esc> using the this line in my .vimrc:
inoremap <C-Space> <Esc>
when running under MacVim or gVim (I use inoremap <Nul> <Esc> when I don't have gui_running)
It works fine except when I leave insert mode with the cursor at the end of the line. That is, if I do A to put the cursor at the end of the line, and then type <C-Space>, the cursor moves down to the first column of the next line. Hitting <Esc> leaves the cursor on the last character.
Why does it do this, and how can I stop it? The <Nul> remapping doesn't have this problem.
Most likely you have a trailing space in your mapping. Removing it should solve your problem. Space move the cursor one character forward.
When I am editing a python file, after I insert a new line then press <ESC>, the cursor moves all the way to the beginning of the line (ie. column 0). How do I stop this behavior? It's really annoying when I want to paste something on the new line.
Here are my relevant .vimrc settings:
set softtabstop=2
set expandtab
set shiftwidth=2
set smartindent
If your goal is to paste something on the new line after just starting it using o or O, you do not have to enter normal mode for it.
Just type Control-R " to paste from the default register directly from insert mode.
More generally, you can type Control-R <RegisterName> to paste from that register from insert mode.
If you edit the line (e.g. by pressing SpaceBackspace) before pressing Esc then Vim will leave the indentation intact.
From normal mode, a quick == will indent the line to whatever position it should be at using your indentation settings. At least, that's how it's working for me. My relevant indent section in my vimrc:
if has("autocmd")
filetype plugin indent on
endif
You can add mapping so when the auto indentation is triggered a single character is inserted and then deleted:
:nnoremap o ox^H
:nnoremap O Ox^H
:inoremap <enter> <enter>x^H
^H must be introduced by pressing ctrl+vctrl+h.
So do not copypaste.
If you already pressed Esc or are coming back to the line later, it is very easy to get the indent back for editing or pasting.
Just use cc to edit the line, re-applying the automatic indent and landing you in insert mode. Then you can start typing or use CTRL+R+ for example to paste from the system clipboard from the current cursor position.
Note Vim will remove the indent again if you stop editing the line without entering any text. This is intentional as it prevents wasteful trailing whitespace littering the file.