Hot answers tagged

8

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. One ...


4

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> :inoremap <F2&...


4

Found a related discussion. cnorm on my machine is \E[?25h\E[?0c 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 ...


4

You can define your special version of "put" like this: command! -bar -bang -range -register Put call append(<line2> - <bang>0, getreg(<q-reg>, 1, 1)) Now 13Pu works without any jumping around.


4

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... func! ModifiedZZ() norm! zz let max_gap = 10 let adjust_trigger = 5 let to_scr_end = winheight(0) - winline() let to_buf_end = getpos('$')[1] - getpos('.')[1] if to_buf_end < ...


3

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 ...


3

You can only change GUI vim cursor color in vim: augroup tune_colors | au! au ColorScheme * hi Cursor guibg=red guifg=white augroup END If you use terminal vim, change cursor colors in terminal settings.


3

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: set virtualedit+=onemore PS, some external plugins ...


3

You can and add this to your init.vim: augroup RestoreCursorShapeOnExit autocmd! autocmd VimLeave * set guicursor=a:hor20 augroup END See :h guicursor for details. The reason it isn't done automatically is there's no way to query the terminal cursor shape


3

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) ...


2

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 ...


2

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 ...


2

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 text property.


2

See :h getcurpos() Basically there is an example: This can be used to save and restore the cursor position: > let save_cursor = getcurpos() MoveTheCursorAround call setpos('.', save_cursor) So you can try it with smth like (untested): nnoremap <C-f> :let save_cursor=getcurpos() <bar> %!clang-...


2

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 ...


2

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 ...


2

You need to set virtualedit=all. The virtualedit option controls where you can edit outside of the actual text (there are other options). Read :help 'virtualedit' for more.


2

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() ...


2

Normal mode For normal mode, rather than remapping scroll commands, I would use an autocommand: augroup KeepCentered autocmd! autocmd CursorMoved * normal! zz augroup END Insert mode 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 ...


1

Bash 4.4 provide PS0: 'PS0' The value of this parameter is expanded like PS1 and displayed by interactive shells after reading a command and before the command is executed. We will use it to restore cursor to block before executing a command, add this to your bashrc: PS0='\[\e[2 q\]' If you use tmux: PS0='\[\ePtmux;\e\e[2 q\e\\\]' If you ...


1

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,...


1

You can turn on search match highlights like this. :set hlsearch To turn it off until the next time you search, use this. :noh To change highlight to a specific color: :hi Cursor guibg=#rrggbb or :hi Search guibg=<colorname>


1

Every strange question have quite simple answers. Refer this thread. All that I had to do was enable cursor blinking in the terminal preference itself :/


1

Not an answer to your question. But thought I'd mention that this exists: https://github.com/terryma/vim-smooth-scroll


1

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 ...


Only top voted, non community-wiki answers of a minimum length are eligible