pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

commit f950b64f9e27088d68cdc6bbcae53ea0a3d48382
parent f369ff49e5f79c10b8e74578b51f8834b15bb85a
Author: pyratebeard <root@pyratebeard.net>
Date:   Tue, 11 Apr 2023 23:03:27 +0100

vim_-_buffer_me_up

Diffstat:
Mentry/vim_-_buffer_me_up.md | 36+++++++++++++++++++++++++++++++++---
1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/entry/vim_-_buffer_me_up.md b/entry/vim_-_buffer_me_up.md @@ -1,10 +1,10 @@ -This is the first entry in a three part series on everyone's favourite text editor, [Vim](TK){target="_blank" rel="noreferrer"}. There are plenty of Vim guides and tutorials on the internet already, from first steps to hardcore power user tips. My entries are going to be somewhat of a middle ground. +This is the first entry in a three part series on everyone's favourite text editor, [Vim](https://www.vim.org/){target="_blank" rel="noreferrer"}. There are plenty of Vim guides and tutorials on the internet already, from first steps to hardcore power user tips. My entries are going to be somewhat of a middle ground. I have been using Vim as my main (read "_only_") text editor for many years. Over this time I have continuously learnt new ways of working and using Vim's functions properly. -In the past couple of years I have been working on enhancing my Vim workflow and the first step was to master [buffers](TK){target="_blank" rel="noreferrer"}. +In the past couple of years I have been working on enhancing my Vim workflow and the first step was to master [buffers](https://vim.fandom.com/wiki/Buffers){target="_blank" rel="noreferrer"}. -When I switched to Vim from [Sublime](https://www.sublimetext.com/){target="_blank" rel="noreferrer"} I had trouble getting over the use of tabs for open files. Sublime, like a lot of GUI text editors, would open files in tabs at the top of the window. Vim does have tabs but they are not used in the same way (more on this later TK). +When I switched to Vim from [Sublime](https://www.sublimetext.com/){target="_blank" rel="noreferrer"} I had trouble getting over the use of tabs for open files. Sublime, like a lot of GUI text editors, would open files in tabs at the top of the window. Vim does have tabs but they are not generally used in the same way. Opening a file in Vim creates a buffer, by default filling the window. If you open another file the new buffer will fill the window, replacing the original buffer. To view your buffers incant ``` @@ -44,4 +44,34 @@ nnoremap <leader>b :ls<CR>:b With this I type `\b` (backslash is the default 'leader' key) to view my buffers and the prompt will wait for me to type a number and hit enter. It has made managing a large number of buffers quite easy. Vim also has a built in auto-complete. By entering `:b <TAB>` Vim will cycle through the buffers, or start typing part of the filename or filepath and it will auto-complete. +You can find out more about buffers using Vim's help pages +``` +:help buffers +:help :buffers +``` + +## split the difference +Vim has the ability to split the window in order to show multiple buffers. With a buffer already open incant +``` +:split <filename> +``` +This will split the window horizontally and load the new buffer so you can view both files at once. It is also easy to split a loaded buffer with +``` +:sb<number> +``` + +To vertical split the window incant +``` +:vert split <filename> +``` + +or +``` +:vsplit <filename> +``` + +To vertical split a loaded buffer incant +``` +:vert sb<number> +```