Hot answers tagged

6

You can use the atom /\&. This is like forcing two different regular atoms to match at the same position. Now it becomes a bit complicated, since the cursor position can be anywhere inside the <<..>> and then you also want to allow whitespace inside those <<..>>. This makes it a bit complex to match the correct item if there are ...


4

One solution is to use a lookahead before the regex and a lookbehind after the regex. That ensures the cursor is after the start of the match, and before the end of the match. One issue with the regex you're using is .\{-} which is a non-greedy operator. If you add anchors for the cursor position, this will end up matching from the beginning of <<one ...


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

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

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

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

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

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


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.


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

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.


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


1

:nnoremap <Down> <Nop> :nnoremap <Up> <Nop> does the trick (in conjunction with :set mouse=). Of course, you can't use the arrow keys any more, but if you're using vim, you didn't care anyway. Edit: Need to this in insert mode too, so add the following: :inoremap <Down> <Nop> :inoremap <Up> <Nop>


1

I can't tell what machine your using, but on my iMac I had the exact same issue and I've finally fixed it. The solution was to go to preferences and uncheck "Use Core Text renderer". I no longer have the issue and as far as I can tell, there hasn't been any adverse affects from doing this.


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