Making the Most of the Vim editor
Nessun commento » Open Source , System , Tips & Tricks No Comments »
There are advanced features of Vim that does not use often, as we are sure that working from remote command line must necessarily mean having few facilities available.
One of the most misunderstood feature concerns the possibility to edit multiple files. Thanks to his unique approach to buffering, Vim can handle a virtually unlimited number of files. The only real limitation is the display mode: to work on multiple files Vim's interface is split - horizontally or vertically, see below - by progressively reducing the area allocated to each file.
To open two files at once by dividing the work area orizzontalmentesi uses the-o option:
$ vim -o file1.txt file2.txt
To open two files at once by dividing the workspace horizontally-O option is used:
$ vim -O file1.txt file2.txt
To switch between windows using the following shortcut:
- CTRL + W + <Down sinistra> active window on the left
- CTRL + W + <Down destra> the active window to the right
- CTRL + W + <Down up> the active window up
- CTRL + W + <Down Arrow> active window at the bottom
- CTRL-W CTRL-W + (twice CTRL + W) moves rapidly from one window to another
To close the current window, simply proceed with the usual sequence
[ESC]+:q
just like when you're editing a single file at a time.
To open a new file from within Vim using the sequence
[ESC]+:new nomefile.txt
If the file exists will be edited, otherwise it will be created from scratch.
To resize the current window, before you type the number corresponding to the amount of rows you want to resize and then proceed with the key combination "CTRL-W + + / -":
[ESC] + 5 + CTRL + W + -
In the example abiamo reduced the current window of 5 rows.
After working on multiple files, you may need to close everything and go a little fun. These are the commands with which to close a session of multiple Vim:
[ESC]+:wqall
[ESC]+:qall!
In the first case, close all windows after saving the changes to each. The second asks you to close all ignoring any changes made to files.







