These useful commands are taken from various sources including net, books. Hopefully it will be useful:
(Note : ~/.exrc file : is the file for making permanent settings to your vi editor, if you place the following commands in this file, these commands will be available to all your vi sessions.)
Commands
1) :abb - for abbreviation
eg.
#:abb etl Elitecore Technologies Limited, Ahmedabad
so whenever u type etl and press enter, space or tab, "etl" will be replaced by "Elitecore Technologies Limited, Ahmedabad"
I use it to create template C and C++ programs, like
#:abb CPP #include<iostream>^M using namespace std;^M int main()^M {^M return0;^M }
(here ^M is for new line, NOTE : make sure u dont type ^M, for ENTER u have to
a) ctrl+v
b) press ENTER
it will display like ^M as above but it means ENTER/new line)
So, now every time I need a C++ template, I just type CPP and press enter, space or TAB,
It gives me a nice C++ program template to work on.
You can use the same for similar purpose.
2) :map - is for mapping some command to some shortcut
eg
the vi command :set number is used to show numbers along the lines of the file, lets say we want to give it a short cut, say F2, meaning when we type F2, it should run the command :set number, To map this command to shortcut key, the vi setting will be
#:map #2 :set number^M
(Note : remember ^M comment in above command)
same for :set nonumber (lets say to F3)
#:map #3 :set nonumber^M
3) set tabstop=2
this is for TAB's setting, I want TAB to be equal to 2 spaces, so I set it to 2.
vi quick reference
3 comments:
One of my favorite for any C-Programmers in .exrc
map @ ^[ :!cc % && ./a.out^M
Where ^[ is (Ctrl-V + ESC) and ^M is (Ctrl-V + Ctrl-M)
After this you can open small test C program and with one key-stroke (@) compile and execute from within editor.
Really its a nice to use shortcut key strock.
In shell or perl script with one key-stroke !% compile and execute from within editor.
Little modification in the shell or perl scripts to run while in the editor,
in ~/.exrc
:map v :w!%^M: !chmod u+x %^M: !./%
where ^M is (Ctrl-v + Cntr-M)
Post a Comment