How do I open the alternate file in a new split window without typing its name?
Answer
<C-w><C-^>
Explanation
Press <C-w><C-^> (Ctrl+W followed by Ctrl+6) to open the alternate file in a horizontal split. The alternate file is the last file you visited — tracked by the # register — making this the fastest way to side-by-side compare or context-switch between two files.
How it works
- Vim keeps a special alternate file pointer (
#) that always refers to the previous buffer you edited in the current window. <C-^>alone (Ctrl+6) toggles between the current and alternate file in the same window.<C-w><C-^>does the same but opens the alternate file in a new horizontal split, so both files are visible at once.- The two windows are independent — you can scroll, edit, and close either one without affecting the other.
Example
1. You edit config.yaml (current file)
2. You then edit app.go (current file, config.yaml becomes alternate #)
3. Press <C-w><C-^> → app.go stays open, config.yaml opens in a new split above
Tips
- Use
:echo expand('#')or:lsto see which file is the current alternate. - Combine with
<C-w>Tto immediately move one of the panes into its own tab if you need more space. - For a vertical split instead, use
<C-w>vto open a vertical split, then<C-^>in the new window — there is no single-key vertical alternate-split command. - The alternate file is per-window, so different splits can have different alternate files.