Mapping PF Keys in Vi


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Mapping PF Keys in Vi
# 1  
Old 04-21-2010
Mapping PF Keys in Vi

This is my first post and right off the bat, I want to let you know that my experience in UNIX is 2 days only backed up with over 20 years of IT working. So, if this is a dumb question or too stupid, please bear with me.

I read somewhere on the web and also on these forums that you can map your PF keys to whatever you want to do. So, I decided to try it out and created an .exrc file with the following commands in there:

set showmode
:map #2 :wq!^M
:map #3 :q!^M

I want PF2 key to save changes to the current file and return to unix command prompt and PF3 key to exit without saving.

For some reason, this does not seem to be working. I don't get any error, but PF keys don't work as expected. When I press PF2 in command mode within Vi, it inserts a line above the line I was last at and types a letter Q. Likewise, it does the same thing to PF3 key but in stead types a letter R.

The command showmode works fine but not the PF keys. I would appreciate if someone can help me out here and tell me what I am doing wrong.

Thanks in advance for the help.....
sssccc
# 2  
Old 04-21-2010
1) When in a .exrc file there is no colon prefix to the map command.

2) The map must exactly match what is generated when you press the key.
I don't know what is generated when you press PF2 or PF3 but no doubt you can find out. (I suspect that it is an Escape Sequence from the way vi behaves in your example).

In one of my .exrc files these lines map the arrow keys on vt320 emulation. When you press an arrow key it actually generates a 3-character Escape Sequence.
Because the .exrc file contains real Escape characters I have to view them with something which makes each Escape character visible.

Code:
cat -v .exrc

map ^[[A k
map ^[[B j
map ^[[D h
map ^[[C l


sed -n l .exrc

map \033[A k$
map \033[B j$
map \033[D h$
map \033[C l$


Getting a real Escape character or a real Carriage-Return character into a text file can be fiddly but others on this board may know an easy way.
# 3  
Old 04-21-2010
Thanks Methyl for the reply. I tried without the colon, but still no go. This is what I get when I issue :map command in Vi Editor:

Code:
:map
up      ^[[A    k
down    ^[[B    j
left    ^[[D    h
right   ^[[C    l
home    ^[[H    H
f2      #2      :wq!^M
f3      #3      :q!^M

Does that help narrowing down the issue ?

Last edited by Scott; 04-27-2010 at 11:25 AM.. Reason: Please use code tags
# 4  
Old 04-27-2010
Anyone else can help me out here. I would really like to customize Vi so I don't have to ftp files back and forth to windows for editing.

Thanks.
# 5  
Old 04-27-2010
With some difficulty, got the idea to work.

In this case I've mapped my Insert key to :wq!<carriage-return>


In .exrc (viewed with sed to make control codes visible.
I had entered the control codes in vi using ctrl/v (take next character literally). The \033 is <escape> the \r is carriage-return.

Code:
sed -n l .exrc
map \033[2~ :wq!\r$


Viewed from "vi".
Code:
:map
^[[2~   ^[[2~   :wq!^M


Now in your case we need to know what characters your PF2 and PF2 keys actually generate.
If it is just a normal escape sequence or a single character control code we can get the sequence into a .extrc file using "vi".
For example for PF2.

Code:
vi .exrc
i          (Put vi into insert mode)
^V         (Tell vi to store the next character even if it is an escape).
PF2        (Press the PF2 key)
space      (Press the space bar)
:wq!^V^M   (The vi sequence we want with a trailing carriage-return)
ESC        (Press the Escape key to exit insert mode)
:wq!       (Save the .exrc file)

The whole approach is only sensible if the sequence generated by pressing PF2 or PF3 is something unique which is NOT a "vi" control character.

Last edited by Scott; 04-27-2010 at 08:02 PM.. Reason: Added code tags to methyl's post... there's a first!
# 6  
Old 04-27-2010
Methyl.

Thanks a lot for very detailed reply. That worked.

However, would you know by any chance why the syntax in my first post did not work.
# 7  
Old 04-27-2010
We go through the whole of this without knowing about your terminal. I managed to work out that it was probably not a DEC vtxxx .

What sort of terminal is it? A real CRT or a PC emulating a terminal? If it is a terminal emulator, which one?
What was the setting of unix environment variable $TERM ?
What Operating System are you running?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Many to many -- mapping

INPUT 13333--TEXT1 14444--TEXT2 13333--TEXT3 12233--TEXT5 14444--TEXT5 12233--TEXT1 12222--TEXT5 13333--TEXT09 what I'm looking for is something using awk arrays with below given output. 14444--TEXT2,TEXT5 13333--TEXT1,TEXT3,TEXT09 12233--TEXT5,TEXT1 12222--TEXT5 (6 Replies)
Discussion started by: busyboy
6 Replies

2. UNIX for Dummies Questions & Answers

Mapping drive

please forgive me. i know this is unix forum. CIFS can map to shared windows folder. i just wonder if windows can map to unix shared folder. if yes, please enlight me... (5 Replies)
Discussion started by: lawsongeek
5 Replies

3. Shell Programming and Scripting

Mapping Servers

Hi All, I need an urgent assistance please . My case below: I have a list of 500 IP addresses. All These ip addresses are mapped/connected to different machine kinds : NT, Linux, Switch, Router ,FW, and so on. My Requirement is to filter from all this ip address only the Linux machines.... (2 Replies)
Discussion started by: James Stone
2 Replies

4. Shell Programming and Scripting

Creating unique mapping from multiple mapping

Hello, I do not know if this is the right title to use. I have a large dictionary database which has the following structure: where a b c d e are in English and p q r s t are in a target language., the two separated by the delimiter =. What I am looking for is a perl script which will take... (5 Replies)
Discussion started by: gimley
5 Replies

5. Shell Programming and Scripting

Need Help Mapping Arrays

I have the following arrays with different lengths that I want to map them with the same key. # Week numbers, 8 columns @headers = ("2011-34", "2011-35", "2011-36", "2011-37", "2011-38", "2011-39", "2011-40", "2011-41"); %data = ("2011-34", BCE, "2011-35", YZA, "2011-36",... (5 Replies)
Discussion started by: tqlam
5 Replies

6. Shell Programming and Scripting

Bit Mapping

Hi All, I am working on the Scenario where i need compare the integer value with other using bit mapping. input file, 1,4,5,4 1,2,4,6 2,3,4,4 like i have many fields. Script : i need to filter hte field one value "1" and field 3 value "4" and Filed 4 i need to do the Bitwise... (5 Replies)
Discussion started by: readycpbala
5 Replies

7. Shell Programming and Scripting

Pattern mapping

Dear Friends, Please help me on this I have file A.txt containing text lines as below grectec; 30 ,50, 60, base_123 ; top09 grectec; 30 ,55, 60, base_123 ; top09 grectec; 10 ,53, 60, base_123 ; top09 grectec; 50 ,57, 60, base_123 ; top09 ... ... another file B.txt containing test... (4 Replies)
Discussion started by: Danish Shakil
4 Replies

8. Shell Programming and Scripting

What are public keys in ssh and how do we create the public keys??

Hi All, I am having knowledge on some basics of ssh and wanted to know what are the public keys and how can we create and implement it in connecting server. Please provide the information for the above, it would be helpful for me. Thanks, Ravindra (1 Reply)
Discussion started by: ravi3cha
1 Replies

9. IP Networking

port mapping

Hello to all! I am new to this interesting forum. My questions is not totally related to unix/linux systems, but I am not finding proper place where to make my question and this forum seems to be visited by experts and unix/linux experts are epxerts in everything My ISP has two kinds of... (1 Reply)
Discussion started by: kallquk
1 Replies

10. UNIX for Dummies Questions & Answers

arrow keys / special keys

how to use the arrow keys in shell scripting. is there any special synatax / command for this. i just want to use the arrow keys for navigation. replies appreciated raguram R (3 Replies)
Discussion started by: raguramtgr
3 Replies
Login or Register to Ask a Question