LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   errors with VI editor after mapped key setup in .exrc file (https://www.linuxquestions.org/questions/linux-newbie-8/errors-with-vi-editor-after-mapped-key-setup-in-exrc-file-947456/)

bilyboy65 05-29-2012 03:26 PM

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,

bilyboy65 05-31-2012 10:36 AM

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.


All times are GMT -5. The time now is 12:56 PM.