I assume you're using Vim in a terminal?
The way the mouse works in a terminal is kinda weird: by default, it's the terminal that handles the mouse and Vim never sees anything. Because it's all text-based this actually works reasonably well: you can select, copy, paste, etc. But this is all on the terminal level, rather than the application (Vim) level.
You can set the cursorcolumn and/or the cursorline to highlight the line and/or column the cursor is on:
:set cursorcolumn cursorline
By adding a ! to the end of the option you can toggle the value, which is useful especially if you want to map this to a key, for example:
:nnoremap <F2> :set cursorcolumn! cursorline!<CR>
Found a related discussion.
cnorm on my machine is
The tail \E[?0c will always reset cursor shape.
I thought I can use t_SI and t_EI if I remove it from cnorm (it's termcap code is ve):
let &t_ve= "\e[?25h"
let &t_SI = "\e[?0;c"
let &t_EI = "\e[?6;c"
But I can't see my cursor after executing above commands, looks like one has ...
If you're willing to bring a function into the mix I whipped this up. I won't pretend it's super pretty or slick but it seems to do the trick...
let max_gap = 10
let adjust_trigger = 5
let to_scr_end = winheight(0) - winline()
let to_buf_end = getpos('$') - getpos('.')
if to_buf_end < ...
The angled brackets < and > are the shift commands.
The reason it's a short block is that vim enters operator-pending-mode, and is waiting for you to complete the command. >> is used to shift the current line by one shiftwidth right, and << is used to shift the current line one shiftwidth left. The brackets can also be followed by a ...
You can only change GUI vim cursor color in vim:
augroup tune_colors | au!
au ColorScheme * hi Cursor guibg=red guifg=white
If you use terminal vim, change cursor colors in terminal settings.
Why does it do this?
Cursor is on a character that has actual place in a buffer. After the last character there is no actual place to put cursor on. Unless you use virtual place.
And is there a way to change this behavior?
To make it have one more character after the end of line use virtualedit option:
PS, some external plugins ...
You can and add this to your init.vim:
autocmd VimLeave * set guicursor=a:hor20
See :h guicursor for details.
The reason it isn't done automatically is there's no way to query the terminal cursor shape
All "long" jump commands, such as gg, automatically save the bookmark for the previous poisition (note that G here is a "motion", so it does not overwrite the bookmark again), so all you have to do is to go back by that bookmark with two backticks:
nnoremap <leader>= gg=G``
Or you can use CTRLO and CTRLI to navigate through the jumplist (:h jumplist) ...
Damian Conway wrote some functions to help him find his cursor when jumping around with n. I'm sure they could be adapted for your use case (i.e., instead of the right-hand side being n:call ..., just do the call).
" This rewires n and N to do the highlighing...
nnoremap <silent> n n:call HLNext(0.4)<cr>
nnoremap <silent> N N:call ...
You should use the win_execute() command to run commands in a different window.
It takes your command to be executed as a string, or it can also take a list of strings to execute multiple commands.
The main advantage of using win_execute() over switching to a window is that it will avoid pitfalls such as window event triggers, modifications to the previous ...
What about the new text-properties? They seem to have the property (sic) to follow.
Text properties can be attached to text in a buffer. They will move with the
text: If lines are deleted or inserted the properties move with the text they
are attached to. Also when inserting/deleting text in the line before the
See :h getcurpos()
Basically there is an example:
This can be used to save and restore the cursor position: >
let save_cursor = getcurpos()
call setpos('.', save_cursor)
So you can try it with smth like (untested):
nnoremap <C-f> :let save_cursor=getcurpos() <bar> %!clang-...
How do I get the column of the cursor independently of how the selection was made?
Let's make it clear: at this point you're already in the normal mode. All you can get is the selection range, not the cursor position at the time it was made. And so col('.') correctly returns the current cursor position, not the previous one.
Your confusion is based on an ...
There's no way to change this behavior for all operators (short of mapping them all.)
But you can make your <F4> keep the cursor position (and window view) by saving and restoring it before and after it's used.
Note that since <F4> ends in an operator-pending g@ command, saving and restoring need to happen in different contexts, you should save ...
Try this instead:
col('.') >= col('$') - 1
col('$') returns the number of the bytes in the cursor line plus one. Unless you have 'virtualedit' set, the cursor will never be in that position. (I'm using >= instead of == in case you do have 'virtualedit' set.)
I'm not 100% sure what you mean by these tests, but you can find the documentation for col() ...
For normal mode, rather than remapping scroll commands, I would use an autocommand:
autocmd CursorMoved * normal! zz
For insert mode, as you've discovered, simple autocommands won't suffice. Instead, note that there are very few keystrokes that can cause the cursor to change lines when in ...
Bash 4.4 provide PS0:
The value of this parameter is expanded like PS1 and displayed by
interactive shells after reading a command and before the command
We will use it to restore cursor to block before executing a command, add this to your bashrc:
If you use tmux:
If you ...
Why using 0 is not enough to put the cursor at the beginning of the line after abbreviation?
When you press space, Vim expands @@t into <esc>0, then the space command is executed. In insert mode, the space command inserts a space, but in normal mode it moves the cursor 1 character forward (see :h <space>).
To prevent the space from interfering,...
You can turn on search match highlights like this.
To turn it off until the next time you search, use this.
To change highlight to a specific color:
:hi Cursor guibg=#rrggbb
:hi Search guibg=<colorname>
Not that it answers the question about the root cause but I found a better way (IMO) to reset the cursor on startup. The main problem is that vim only sends the "t_EI" escape sequence when is exiting either Insert mode or Replace mode (see :help termcap-cursor-shape) and since vim starts on Normal mode "t_EI" is not sent. An obvious solution to this is to ...