Posts Tagged ‘vi split window’
Split Windows and Shell Commands in VI
Been working on a project to learn Ruby and decided it was also a great opportunity to learn VIM. One of the gripes i was having was needing to close vim to open another file or run commands on the shell. I figured there should be another way to do this so i googled around and found a way to do it.
The sp command will split you window horizontally and spw will split it vertically. Let’s say you want to edit another file and split the window horizontally you use the command:
:sp filename
This will split the window with your new file on the top pane, and your old file on your bottom pane. You can also decide how big your new pane should be by supplying the line number before issuing the command:
:20 sp filename
The above command splits the window and gives your top pane 20 lines, leaving the rest for the bottom pane.
To switch between panes just us Ctrl-w [up|down|j|k], you can also change the pane size with Ctrl-w[number+|number-] (where number is the number of lines to grow or shrink). If you want to split the window without opening a new file just use Ctrl-ws
A small note: you have other options besides split to edit multiple files since VI supports buffers easily, use :
:e filename
to open a new file in a new buffer and :bn or :bp to cycle between them.
Now i just needed a way to call the ruby interpreter on the shell without being forced to quit vi. Found its pretty easy to run code on the shell. just use :
:!command
So to run ruby on some file (on the folder i ran vi) i just typed
:!ruby file
Also you can run a command on the file in the current buffer by using the % character:
:!ruby %
Even though i used ruby as an example you can run any shell command you need.
For further explanations visit links bellow.
References:
Categories: vi
Tags: learning vi, vi shell command, vi split window, vi viewport
Archives
3gmodem
acer aspireone
acess private field
ant
automount usb
big o notation
chmod
chmod shorthand
Code Smell
cygwin
cygwin portable
Dependency Injection
ejb3
ejb3 jndi
ejb3 naming
Emacs
emacs backup
Exception Handling
firefox
firefox addon
Gnu Screen
gtk-sharp
hibernate
java
javascript
JPA
learning vi
linpus
Linux
microsoft browser
Mono
MonoDevelop
NPE
oAuth Requests
oAuth Signature
Object Validation
oracle
oracle data type
OVal
permissions
POJOConfigurer
portable emacs
prototype
proxy authentication
root password
ruby
runtime error
ServiceLoader
sudoku
task management
taskplan
terminal
Twitter Authorization
vi
virtualbox
vi shell command
vi split window
vi viewport
web development
weblogic
Weblogic EJB3
weblogic integration
weblogic workshop
window
windows
wlappc
wlcompile
wldeploy
wlpackage
worklists
workshop bugs
WTF
xfce
zte mf622