Vim change block cursor when in insert mode - linux

Not sure what the terminology is for it but on Vim the 'cursor' is always like an insert/replace cursor instead of the blinking line cursor I'm used to in other gui editors. Is there any way to change this when in insert mode?

I know this is an old question but hopefully this will help anyone else facing the same scenario.
Actually I'm using iTerm2 and using Vim inside my terminal on Mac. And when entering to insert mode, the cursor still being a block and is kind of confusing when you are at insert mode or normal mode.
I wanted to show a thin line as cursor when in insert mode and back to block when in normal mode as MacVim does. And to do so it's pretty simple, just added this to my .vimrc file as described here:
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
But as you can see there was a delay when hitting ESC to exit insert mode back to normal mode and show the block as cursor again. So to fix it I found this:
set ttimeout
set ttimeoutlen=1
set listchars=tab:>-,trail:~,extends:>,precedes:<,space:.
set ttyfast
And now it works pretty fine as you can see:
I hope it could help any one else! 👻

The gcr option does this, although I'm not sure exactly how it needs to be set to get the results you want.
:help gcr
If you read the manual and play around with it, you should be able to figure it out.
The blinking cursor in insert mode is usually the default. Maybe the gcr option got changed in your .vimrc

This plugin for vim will actually change the cursor on the fly in iterm (and tmux)
It has a few bugs if you're in tmux, but works great outside of it: https://github.com/sjl/vitality.vim

I was connecting using iTerm on mac. It seems there is a setting in iTerm for it. Quick change and its working.

Related

Neovim: How do I set guicursor to make the cursor blink?

The cursor blinking is off by default in Neovim and I want it back. I have tried to apply different arguments to guicursor, but didn't succeed. Since I want it to blink the same way in every mode, I think, I need something with the letter 'a' in it.
Here's what I have tried so far:
:set guicursor=a:blinkwait700-blinkon400-blinkoff250 (I also tried with 'i')
:set guicursor=a:blinkon100 (as the opposite of a:blinkon0 which switches it off)
I've already looked into the help but it didn't help me unfortunately.
Update:
What is peculiar is that :set guicursor=a:blinkon100 enables the blinking in gVim, but not in Neovim.
From neovim 0.2 onwards, setting guicursor does achieve the desired effect:
" Enable blinking together with different cursor shapes for insert/command mode, and cursor highlighting:
set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20,o:hor50
\,a:blinkwait700-blinkoff400-blinkon250-Cursor/lCursor
\,sm:block-blinkwait175-blinkoff150-blinkon175
Find more by typing :help 'guicursor' from inside nvim.
For more info, see the official wiki
Finally, if you use st, you can patch it to get this working:
https://st.suckless.org/patches/blinking_cursor/
EDIT: I noticed from the comments of the first answer that OP was talking about nvim-qt, for those interested in that, a fix for it has been merged at the beginning of this year.
If you are using the st terminal by Suckless then that does not support cursor blinking I belive, otherwise if your terminal does support it try setting the option let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1 in your init.vim file. You could also pass that on the command line such as NVIM_TUI_ENABLE_CURSOR_SHAPE=1 nvim.

Weird characters are added when I press alt-tab in vim's insert mode

Hello Dear Vim Lovers,
The situation is this.
I am editing something in vim. While I am in insert mode, I press alt-tab key to switch to another window. When I return back to vim, I am seeing alt and tab keys were captured by vim and inserted into my text.
It seems like [O[I[O[I[O[I[O[I.
I am working in gnome-terminal. I do not recall this behavior in my previous setups. There must be something wrong but I could not figure it out yet. In case anyone knows how to fix it, please let me know.
Thank you!
I was running into this problem after remapping <Esc> to a noop as recommended here. Deleting the remap stopped the characters from being inserted.

Vim cursor going outside of character bounds in normal mode

Some setting changed on my vim. In normal mode, I can now click anywhere and my cursor will go there. (This is in normal mode.)
The behavior used to be that if I clicked past the end of the line, the cursor would go to the last character of the line.
I hope I've explained this sufficiently, but is there a way to get the old behavior back?
Thanks!
You probably set the option virtualedit somewhere. To turn it off for the instance you can use :set virtualedit=. Or to permanently disable it remove it from your vimrc.
The feature is call virtual edit. You can disable this with:
:set virtualedit=
See :h 've' for more information.

How do I switch between command and insert mode in Vim?

I just started using Vim as an IDE. I was using it as a test editor for a while now, so I didn't have to go to command mode very often. But, since I program in Java, I have to go to command mode to make the file, compile/run it... etc.
The problem is: I need a good way to switch between the two modes.
I looked online and it says that the <Esc> key is supposed to do that, but that doesn't work for me (maybe it's not for gVim? I don't know why.)
I have to press CTRLO every time to go to command mode; the escape key works from that mode... it brings me back to insert mode. But is there a better, or easier, way of switching between command mode and insert mode?
Pressing ESC quits from insert mode to normal mode, where you can press : to type in a command.
Press i again to back to insert mode, and you are good to go.
I'm not a Vim guru, so someone else can be more experienced and give you other options.
Looks like your Vim is launched in easy mode. See :help easy.
This happens when Vim is invoked with the -y argument or as evim, or maybe you have a :set insertmode somewhere in your .vimrc configuration. Find the source and disable it; temporarily this can be also done via Ctrl + O :set noim Enter.
This has been mentioned in other questions, but ctrl + [ is an equivalent to ESC on all keyboards.
Using jj
In my case, the .vimrc (or in gVim it is in _vimrc) setting below.
inoremap jj <Esc> """ jj key is <Esc> setting
Coming from emacs I've found that I like ctrl + keys to do stuff, and in vim I've found that both [ctrl + C] and [alt + backspace] will enter Normal mode from insert mode. You might try and see if any of those works out for you.
For me, the problem was that I was in recording mode. To exit from recording mode press q. Then Esc worked as expected for me.
There is also one more solution for that kind of problem, which is rather rare, I think, and you may experience it, if you are using vim on OS X Sierra. Actually, it's a problem with Esc button — not with vim. For example, I wasnt able to exit fullscreen video on youtube using Esc, but I lived with that for a few months until I had experienced the same problem with vim.
I found this solution. If you are lazy enough to follow external link, switching off Siri and killing the process in Activity Monitor helped.
You can use Alt+H,J,K,L to move cursor in insert mode.

Not able to hide <# and #> with parameters for clang_snippets=1 with clang_complete

I've set this on my .vimrc:
let g:clang_snippets=1
let g:clang_snippets_engine='clang_complete'
let g:clang_conceal_snippets=1
set conceallevel=2 concealcursor=inv
I don't know how conceal is expected to work, maybe the clang_complete's docs should have a tip for a specific setting to hide the snippets adorns.
How do I hide it? I'm using MacVim built with +conceal, but it's not working. This is my messy .vimrc by now.
NOTE:
I'm sticking with g:clang_snippets_engine='clang_complete' because it seems to be more smart than the snipMate parameter completion, switching to NORMAL mode is a wiser choice to navigate between parameters since I can use SuperTab completion for params in INSERT mode while being able to navigate through them with the same tab at NORMAL mode. snipMate engine was acting weird to me sometimes too, sometimes it switched to a parameter after a completion, sometimes not.
Also, I'm missing a final tab to go after the last parameter, right after the function call (snipMate does that), so I can just insert ; and hit Enter.
Disclaimer: This question is related with the issue at https://github.com/Rip-Rip/clang_complete/issues/176.
EDIT:
My problem was with this line at my .vimrc:
au BufNewFile,BufRead *.cpp set syntax=cpp11
I'm using C++11 Syntax Support and #xaizek has discovered and pointed it out as the problem in the comments bellow in the accepted response, it seems the root cause is the use of the syntax clear command in it.
According to :help 'concealcursor':
Sets the modes in which text in the cursor line can also be concealed.
When the current mode is listed then concealing happens just like in
other lines.
n Normal mode
v Visual mode
i Insert mode
c Command line editing, for 'incsearch'
So with concealcursor=iv you asked Vim to hide concealed text in insert and visual modes, but show it in normal mode. So just do:
:set concealcursor=inv

Resources