![]() ![]() Vim close all windows but current one code#There is a Vim plugin called BufOnly, which does the same thing with some added functionality. So one day while youre hacking away you realize that VS Code just doesnt want to let you keep your file tabs open. command! BufOnly execute '%bdelete|edit #|normal `"' vimrc we can use :BufOnly to close all buffers except the current buffer. Then normal `" is the same as pressing `" in normal mode, which jumps us to our last cursor position in that buffer. However, you can view multiple windows open at once in Vim. Force close all buffers but the currently focused one. By default, the Vim opens only a single window, even if you have opened multiple files. The alternate file is the last buffer you were viewing before they all closed so :edit # opens that file. Command mode can be activated by pressing :, similar to vim. So when you run :%bdelete all buffers are deleted including the current buffer leaving you in a new empty buffer. When we run `" in normal mode we jump to the cursor position where we last exited the current buffer. The normal command allows us to execute a normal mode command from the command line. You can see the value of # with :echo expand('#') The # in this context represents the alternate filename (see :help _# and :help alternate-file). The :edit command opens a file for editing when that file is given as a parameter. :3,5bdelete will delete buffers 3 through 5), it is as if we are running :1,999bdelete except instead of 999 Vim automatically uses the largest buffer number. Since we can prefix a command with a range (e.g. The % represents from 1 up to the highest value. Using bdelete (without the % prefix) deletes a buffer. The %bdelete command deletes (closes) all buffers. So our command is actually three separate commands run one after another. ![]() but readonly :hide - close current window :only - keep only this window open :ls. This can be done with the command: :%bdelete|edit #|normal `"Ä«y separating with a bar ( |) we can put multiple commands on one line (see :help :bar). If you want, you can probably do everything from one vim session. ![]() Tip Run vimtutor in a terminal to learn the first Vim commands.Vim has a built-in command to close all windows except the current one ( :only), which is nice for focusing on a single buffer. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |