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

How do I switch to a specific buffer by number?

Answer

:b {number}

Explanation

The :b command followed by a buffer number switches directly to that buffer. Use :ls first to see buffer numbers.

How it works

  • :b 3 switches to buffer number 3
  • :b filename switches by partial filename match
  • :sb 3 opens buffer 3 in a new split

Example

:ls           " Shows: 1 main.go, 2 utils.go, 3 test.go
:b 2          " Switch to utils.go
:b test       " Switch to test.go (partial match)

Tips

  • Tab completion works with :b : type :b then press Tab
  • :b with no argument switches to the alternate buffer
  • :bd 3 deletes (unloads) buffer 3
  • Buffer numbers do not change when buffers are deleted

Next

How do you yank a single word into a named register?