vimtricks.wiki Concise Vim tricks, one at a time.

How do I control how many columns Vim scrolls horizontally at once when the cursor reaches the screen edge?

Answer

:set sidescroll=1

Explanation

When wrap is off and the cursor moves past the edge of the screen, Vim jumps the view horizontally by a number of columns determined by sidescroll. Setting it to 1 gives the smoothest one-column-at-a-time scrolling. The default value of 0 jumps by half the screen width, which can be disorienting on wide files.

How it works

  • :set nowrap — required to enable horizontal scrolling (wrap mode keeps all content visible)
  • sidescroll=0 — the default; when the cursor hits the edge, the view jumps by half the window width
  • sidescroll=1 — the view scrolls smoothly one column at a time as the cursor moves
  • Higher values increase the jump size per scroll step

Example

For smooth horizontal scrolling when editing long lines:

:set nowrap
:set sidescroll=1
:set sidescrolloff=5

With these settings:

  • The view doesn't wrap long lines (nowrap)
  • Horizontal scroll advances one column at a time (sidescroll=1)
  • The cursor always stays at least 5 columns from the left or right edge (sidescrolloff=5)

Tips

  • Pair with sidescrolloff to keep a margin between the cursor and screen edge, preventing the view from repositioning exactly at the edge
  • Use zL and zH to manually scroll the view left/right by half the window width without moving the cursor
  • Use zl and zh to scroll one column at a time without moving the cursor
  • To persist the setting, add it to your vimrc

Next

How do I open the directory containing the current file in netrw from within Vim?