pyratelog

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

commit 7923d09e3f8177e176567e90f16c80db374a9eaa
parent 05d191a4ad09cfc8c7876afa2088718b9a7532f0
Author: pyratebeard <root@pyratebeard.net>
Date:   Mon, 10 Apr 2023 21:39:37 +0100

vim_-_buffer_me_up

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

diff --git a/entry/vim_-_buffer_me_up.md b/entry/vim_-_buffer_me_up.md @@ -1,9 +1,45 @@ -This is the first entry in a three part series on [Vim](TK){target="_blank" rel="noreferrer"}. There are plenty of Vim guides and tutorials on the internet already, everything from first steps to hardcore power user tips. My entries are somewhat of a middle ground. +This is the first entry in a three part series on everyones 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. -I have been using Vim as my main (read _only_) text editor for many years, over which I have continuously learnt new ways of working, or really focused on using Vim's functions properly. +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. The latter is what I am going to cover in three parts. In the past couple of years I have been working of enhancing my Vim workflow and the first step was to master [buffers](TK){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). -Opening a file in Vim creates a buffer. +Opening a file in Vim creates a buffer. By default this buffer will fill the window. If you then open another file then the new buffer will fill the window. To view your buffers incant +``` +:buffers +``` + +or +``` +:ls +``` + +This will list all open buffers with a unique number, one or more indicators, the file in the buffer, and the line the cursor is on. For example +``` + 1 a "entry/vim_-_buffer_me_up.md" line 9 + 5 #h "pyratelog.sh" line 1 +``` + +In this example there are two buffers open, numbered 1 and 5. The `a` indicator on buffer 1 means it is the active buffer, i.e. what is currently loaded in the window. The `#` and `h` indicators on buffer 5 mean it is the alternate buffer (`#`) and it is hidden (`h`), i.e. it is loaded but not visible. + +The alternate buffer indicator is normally the previously active buffer. You can quickly switch to this buffer with `CTRL-^` (that's `CTRL`, `SHIFT`, `6`, although most terminals will do the same with `CTRL`, `6`). This means if you are working on two files you can quickly toggle between them using `CTRL-^`. + +The unique number of a buffer doesn't change once it is open. If you know the number of a buffer you can switch to it using `<number> CTRL-^`, or incant +``` +:buffer <number> +``` + +or +``` +:b<number> +``` + +#### quick tip +In my ~/.vimrc I set the following keymap +``` +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 using buffers quite easy.