Files
Vim-tutorials/my-learning/buffer-tut.txt

211 lines
4.7 KiB
Plaintext

Buffer
----------
Defination: It is the in-memory defination of a file.
It represent the content of the file by
storing it inside memory.
Opening multipe files in Vim.
* From terminal
vim <file-1> <file-2> ....
* Shell expansion shortcuts:
vim file*
This will open all the file which follow pattern
in their file name that is mentioned as an argument
here.
* To see all the open buffers:
Use commands: :buffers
* To know more on buffers:
Use commands: :h :buffers
* To change the buffer to another opened file
:buffer <buffer number>
:buffer <filename>
Note : Instead of :buffer, we can use :b.
* To open to the next buffer of the current opened buffer.
We can use: :bnext or :bn
To do this in opposite direction we can use:
:bprevious or :bp
* To go to the first buffer.
:bfirst or :bf
* To go the last buffer.
:blast or :bl
* Shortcut key-binding to move to the previously editing buffer.
CTRL + ^
* The %a and # symbol meaning.
%a : Represent the active buffer and currently loaded.
# : Represent the previously editing buffer.
* Another way to move back to the alternate buffer.
:b#
%% TIPS %%
When we try to do the editing on the current buffer and check the
buffer list.
It will present a '+' indicating that the editing done is not saved.
And when we try to change the buffer, it wil throw error.
We can still force to change the buffer by using '!'.
------------------------------
There are three states of buffer.
-> Active state and showing the buffer.
-> Inactive state and not shown in the buffer.
-> Inactive state but in the memory. (#h +)
* To allow the buffer to be hidden without writing it into the file.
We can use option:
:set hidden
This allow to edit multiple buffer without necessarily writing it.
* To abandone all the changes of all the buffer.
:qall!
* To save all the changes of all the buffer.
:wall
* To open another file without switching to that new window of the same file.
:badd <filename>
* To unload a currently active buffer.
:bdelete or :bd <name or number> -> This is optional if the buffer is not the current active file.
* To delete range of buffer.
:<start-number>,<end-number>bd
and
To delete all the buffer.
:%bd
* To execute a line command on each and every buffer.
:bufdo set <option>
:bufdo ....
* To execute multiple line command in line-command mode.
We can use '|' symbol.
----------------------------------------------------------------------
Explore
--------
Command: :Explore or :E
It is file explorer CLI which allow to navigate directory and open any file in the buffer.
This CLI like look also a special buffer which we can delete using :bd command.
--------------------------------------------------------------------------------------------------
Multiple Buffer:
----------------
Command: vim <filename-pattern>*
To open all the file name following the pattern.
Command: :sp or :split
To split window horizontally and open two buffer at the same time.
To achieve same thing we can use "CTRL+w s"
Command: :vs or :vsplit
To vertically split the window and open two buffer at the same time.
To achieve same thing we can use "CTRL+w v"
Command: CTRL+w q
To close the current active buffer window.
Command: :on or :only or CTRL+w o
To close the all the window except the current active window.
--> To Navigate through windows using h,j,k,l
Same motion for these key can be used for window navigation using
CTRL+w h,j,k,l. (left, down, up, right)
--> To adjust and modify the size of the window.
CTRL+w +: To increase the height of the window.
CTRL+w -: To decrease the height of the window.
CTRL+w >: To increase the width of the window.
CTRL+w <: To increase the width of the window.
CTRL+w _: To set the height of the window to maximum.
CTRL+w |: To maximize the width fo the window to maximum.
CTRL+w =: To make all the window equal in size.
--> To arrange the windows buffer.
CTRL+w r: To rotate the respective buffer in clockwise-direction.
CTRL+w R: To rotate the respective buffer in opposite-direction
CTRL+w h: To move buffer to edge left with full height.
CTRL+w j: To move buffer to bottom edge with full width.
CTRL+w k: To move buffer to top edge with full width.
CTRL+w l: To move buffer to right edge with full height.
Command: :ball
To open all the buffer and split is horizontal.
Vim will try to open all buffer. But, if enough space
is not present then it will stop opening remaining buffer.
--> To execute a action command on every opened window.
Use ":windo <command>". <command> can be, for example,
substitution command.