LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-29-2012, 04:26 PM   #1
bilyboy65
LQ Newbie
 
Registered: Apr 2012
Posts: 14

Rep: Reputation: 0
errors with VI editor after mapped key setup in .exrc file


I have the following mapped commands to the K key in my .exrc file

map K :1,$s/^\s*[0-9]+\s//|1,$s/^\s*[0-9]+\n/\r/

The purpose of it is to remove any whitespace before the line number and after the number when a user has line numbers turned on and does a copy and paste.

Sample after paste:

1 1 text
2 2 text
3 3 text
4 4
5 5 text

will look like after commands run

1 text
2 text
3 text
4
5 text

If I copy the above command into the command line of VI it works as designed.

I'm having 2 problems that I would like help with. The first is when VI loads it only seems to load the first command into K. The second problem is that before the file opens I receive an error message that the pattern can't be found.

My question is how do I prevent VI from running this command at start, but still map it to the K key? Also how do I get the 2 commands to be mapped to the K key?

Thank you for any help,

Last edited by bilyboy65; 05-30-2012 at 12:51 PM. Reason: I figured out one of my problems and discovered another.
 
Old 05-31-2012, 11:36 AM   #2
bilyboy65
LQ Newbie
 
Registered: Apr 2012
Posts: 14

Original Poster
Rep: Reputation: 0
I figured it all out. In case anyone else runs into this situation here is the solution. It's essentially the same solution as well. In the posted command, the + and | characters needed to be escaped.

map K :1,$s/^\s*[0-9]+\s//|1,$s/^\s*[0-9]+\n/\r/

Because the | wasn't being escaped the editor thought it was part of the command and was returning the error and preventing the entire command from being mapped. Without escaping the + signs the pattern wasn't being correctly mapped. I'll mark this post as completed.

So the final command that works correctly without any errors is

map K :1,$s/^\s*[0-9]\+\s//\|1,$s/^\s*[0-9]\+\n/\r/<CR>

****I added the <CR> at the end so the command was automatically executed.

Last edited by bilyboy65; 05-31-2012 at 11:38 AM. Reason: original attempt at bolding things didn't work
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
A system wide .exrc file. swamprat Linux - Software 1 04-26-2012 08:53 PM
Network device Memory mapped or Port mapped ?? Bignon Linux - Hardware 0 10-20-2009 09:36 AM
fread and fwrite errors with mapped memory justaguy_75ae Programming 2 09-08-2009 02:44 PM
Smart Key Signature ERRORS! How do I delete this bad key from my computer? Balarabay1 Linux - Software 4 09-27-2006 12:01 PM
tripwire: paranoid setup - key file vulnerability? rumex Linux - Security 1 04-19-2005 08:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration