Main Page | Report this Page
Computers Forum Index  »  Computer - Editors  »  Vim: macro to replace space under cursor by " "...
Page 1 of 1    

Vim: macro to replace space under cursor by " "...

Author Message
Niki Kovacs...
Posted: Mon Oct 05, 2009 1:30 pm
Guest
Hi,

I'm using Vim to edit static XHTML pages.

I have to (manually) check for non-breakable spaces in my text, and
eventually replace simple spaces by the following character sequence:

 

Usually, when I perform the same operation over and over in a text, I do
it once, and then repeat it in command mode using [.]. But I can't
figure out how to do this here.

Here's what the according macro would look like. Pressing F2 would
replace the space under the cursor by " " :

:map <F2> cw&nbsp;<ESC>

.... except this also deletes the word after the cursor, which is annoying.

Any suggestions ?

Cheers from South France,

Niki Kovacs
 
Mikolaj Machowski...
Posted: Mon Oct 05, 2009 3:02 pm
Guest
Niki Kovacs scripsit:
Quote:
Here's what the according macro would look like. Pressing F2 would
replace the space under the cursor by "&nbsp;" :

:map <F2> cw&nbsp;<ESC

Any suggestions ?

:map <F2> s&nbsp;<ESC>

m.
--
LaTeX + Vim = http://vim-latex.sourceforge.net/
Vim Universal Templates: http://vim.sf.net/script.php?script_id=1078
CLEWN - http://clewn.sf.net
 
Phil...
Posted: Mon Oct 05, 2009 5:29 pm
Guest
Niki Kovacs wrote:
Quote:
Hi,

I'm using Vim to edit static XHTML pages.

I have to (manually) check for non-breakable spaces in my text, and
eventually replace simple spaces by the following character sequence:

&nbsp;

Usually, when I perform the same operation over and over in a text, I do
it once, and then repeat it in command mode using [.]. But I can't
figure out how to do this here.

Here's what the according macro would look like. Pressing F2 would
replace the space under the cursor by "&nbsp;" :

:map <F2> cw&nbsp;<ESC

... except this also deletes the word after the cursor, which is annoying.

Any suggestions ?

Cheers from South France,

Niki Kovacs

Try
:map <F2> s&nbsp;<ESC>

If you want to replace every space character then try
:%S/ /\&bbsp;/g
Regards
Phil
 
Patrick Texier...
Posted: Mon Oct 05, 2009 8:54 pm
Guest
Le Mon, 05 Oct 2009 11:30:05 +0200, Niki Kovacs a écrit :

Quote:
I have to (manually) check for non-breakable spaces in my text, and
eventually replace simple spaces by the following character sequence:

&nbsp;

You can use non-breakable spaces with <CTRL-K>NS
--
Patrick Texier

vim:syntax=mail:ai:ts=4:et:tw=72
 
 
Page 1 of 1    
All times are GMT
The time now is Mon Nov 23, 2009 5:36 pm