Using buffer is simply a way to open multiple documents in a single vim session.
For example, you want to open /etc/passwd, and copy some of it contents into a new file called /tmp/mylist.
What you would do:
1. open /etc/passwd
$ vim /etc/passwd
2. while in vim, open a new buffer
:e /tmp/mylist
3. To list all opened buffers, we can use :ls. This is also a way you can know the buffer number
:ls
4. To move to a buffer number
:b <buffer number>
5. We can also use some part of the file name to move to the buffer that the file is opened
:b passwd
6. We can also use :bn to go to the next buffer in the list, or :bp to go to the previous buffer in the list
7. To copy contents between buffer
- highlight the text that you want to copy in the current buffer (v)
- then use the usual yank (y) to copy the highlighted texts
- switch to the target buffer using (:bp), (:bn), (:b number) or (:b filename)
- paste using paste command (p)
No comments:
Post a Comment