2022 Developer Survey is open! Take survey.

Hot answers tagged

37 votes
Accepted

Multiple cursors at desired location

Using multiple cursor isn't a Vimmer thing As I said in the comments using multi cursors (even with a plugin) isn't really "following the Vim way", I totally understand that it is attractive for ...
user avatar
  • 45.9k
23 votes
Accepted

How do I make Vim always display several lines after EOF?

You can use ctrlE to scroll down your file, when you are at the end of the file it will add "virtual" line so the last line of the file is not at the bottom of the windows. Additionally you can use ...
user avatar
  • 45.9k
13 votes
Accepted

I can't switch to | cursor in insert mode

Neovim does not use vimrc it uses $XDG_CONFIG_PATH/nvim/init.vim. Yet, there is more to it. In Vim you should use \<esc> to represent the escape key. I can change the cursor on Arch Linux on ...
user avatar
  • 1,596
13 votes
Accepted

Is there a prepend insert mode?

If you set :set revins you can insert backwards. See also :h ins-reverse: o Typing backwards ins-reverse ---------------- In lieu of using full-fledged ...
user avatar
9 votes
Accepted

how can we put the cursor at mouse pointer

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-...
user avatar
8 votes
Accepted

Vim normal and insert mode cursor not changing in GNU screen

I think I figured it out, although I don't totally understand the fix. This appears to work for mintty, xterm, and rxvt: " Set up vertical vs block cursor for insert/normal mode if &term =~ "...
user avatar
  • 411
8 votes
Accepted

CursorLine colors

The default syntax script for vim doesn't have lightyellow listed for vimHiCtermColor. You could patch it and submit your change to the vim_dev mailing list. Or, better, ask them if that is ...
user avatar
  • 32.6k
8 votes

Change cursor shape in different terminals

As of November 2017, all the terminals you are using support the same DECSCUSR escape sequences for changing the cursor shape1. So you don't need to test for the different terminals. As such, the ...
user avatar
  • 27.4k
8 votes

How can you indent your current file without losing your cursor position?

You could define a custom command using :help winsaveview(): command! -range=% Equal let b:wv = winsaveview() | silent execute <line1> . ',' . <line2> . 'normal! ==' | call winrestview(b:...
user avatar
  • 32.6k
7 votes
Accepted

How can I get the character at the cursor position in a multibyte aware manner?

We discussed it less then 10 days ago on reddit. One solution is matchstr(getline('.'), '\%'.col('.').'c.') which doesn't mess with any register. I've put the resulting functions (we can ask for the ...
user avatar
7 votes
Accepted

getpos(".") in visual mode equals getpos("v")

The problem you're having here is that by the time show_position() is running you're already out of visual mode, since the : switched to command-line mode before that function gets called. If you ...
user avatar
  • 25.4k
6 votes

Multiple cursors at desired location

More Vim ways. First task: \section[foobar baz]{foobar baz} Workflow: \section[]{} hh ifoobar baz<Esc> $. Second task: variable1 = 2 my_variable2 = 12 var3 = 14 Command: 3:norm ...
user avatar
  • 32.6k
6 votes

Multiple cursors at desired location

Your given use-cases to me sound like to want to know the . key command (repeat last Editing command) Go to first place, press i, insert your text, <ESC> move to location 2, press . (Dot) ==> ...
user avatar
6 votes
Accepted

Move cursor to new line character

If you simply want the cursor to be able to go one past the end of the line for the purpose of starting visual mode, you want the setting set virtualedit=onemore (see :help 've). However, this does ...
user avatar
  • 12.6k
6 votes
Accepted

No_cursor_blinking doesn't work

In gvim you use: set guicursor+=a:blinkon0 In vim run in the terminal you would change the terminal setting to disable the blinking.
user avatar
  • 94
6 votes
Accepted

Reclaim cursor shape in operator pending mode of neovim while using vim-surround

If vim-surround were implemented as 's' and 'S' (pseudo-)text-objects instead of operators ds, dS, cs, cS etc, this wouldn't be an issue. I don't know if there's some technical reason for this design ...
user avatar
  • 12.6k
6 votes

Regex pattern matching cursor-position

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 &...
user avatar
5 votes

How can you indent your current file without losing your cursor position?

Expanding on Karl Yngve Lervåg's answer: maHmbgg=G`bzt`a Explanation: ma - Set mark 'a' H - Jump to the top of the window mb - Set mark 'b' gg=G - Indent from the first line to the last `b ...
user avatar
  • 6,320
5 votes

gvim Linux - GUI scroll without cursor shift

Vim doesn't remember where you've been in a file unless you made a change there (see :help changelist) or jumped there (see help jumplist). Also, Vim's cursor is always somewhere in a window, that is, ...
user avatar
  • 5,854
5 votes
Accepted

creating a ":KeepCursor" command

Can it be written? Yup. command! -nargs=* -complete=command KeepCursor \ let [s:view, s:win] = [winsaveview(), win_getid()] | \ try | \ execute <q-args> | \ finally | ...
user avatar
5 votes
Accepted

Neovim does not restore terminal cursor on exit

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 ...
user avatar
  • 1,902
5 votes
Accepted

How to move cursor to previous line automatically?

The option is called :h 'whichwrap' (or ww for short). For example, set ww+=<,>,[,] However, "right arrow" only goes onto the next line if you don't have set virtualedit=all (that you ...
user avatar
  • 15.5k
4 votes

How to restore cursor position after search and replace in autocmd

You could achieve '' on an autocmd using the following: :call setpos('.', getpos("''")) Check :help function-list for built-in functionality on VimL. Edit okay, how to combine it with search and ...
user avatar
  • 6,370
4 votes

How to scroll without forcing the cursor on screen (by letting the cursor off screen)?

I am used from other editors to use the cursor as a visual bookmark, so that after scrolling by letting the cursor off screen I can come back to its place later. If you're just scrolling through the ...
user avatar
4 votes

How do I make Vim always display several lines after EOF?

The easiest solution, in my opinion, was adding zz to j and k. It has the major side effect of centering your cursor. I don't mind and much prefer it to craning my neck. I tried scrolloff and CTRL-E ...
user avatar
4 votes
Accepted

cursor behavior when exiting <insert> mode

Thanks to the comment by @muru I was able to figure this out. I turns out in my .vimrc I had this line to remap jk to <esc> inoremap jk <esc> but there was a space inserted at the end ...
user avatar
  • 219
4 votes

How can I get the character at the cursor position in a multibyte aware manner?

The following works and is faster than the matchstr() solution: fun! Getchar() return strcharpart(strpart(getline('.'), col('.') - 1), 0, 1) endfun nnoremap GG :echo Getchar()<CR> See my ...
user avatar
  • 8,520
4 votes

Move cursor to new line character

You can use 'virtualedit' for this: :set virtualedit=onemore Note however the warnings in :help 'virtualedit': "onemore" is not the same, it will only allow moving the cursor just after the ...
user avatar
  • 27.4k
4 votes
Accepted

neovim doesn't change cursor in st terminal

This should be fixed in the release after 0.2.2. This was reported in neovim/neovim#7641 and the issue was that st's terminfo incorrectly specifies how to change the cursor shape. The fix in neovim ...
user avatar
  • 10.3k
4 votes
Accepted

Regex pattern matching cursor-position

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 ...
user avatar
  • 25.4k

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