On 5/7/06, Meino Christian Cramer <[EMAIL PROTECTED]> wrote:
Hi,
WARNING ! VAST DANGER ! NEWBIE QUESTION AHEAD ! :)
Everybody take cover! :-)
I got stuck! I read several times user_40.txt and user_41.txt but
can't figure out, why my very very basic script simply does nothing.
It is a very very verbose implemention of the NOOP-command, I fear.
It even does not display an error...
It consists of foru lines:
:normal gg
:normal %s/^[ ]*//g
:normal gg
:normal %s/[ ]*$//g
You need to understand what normal does. It delivers Normal mode
key commands. gg is a normal mode command, %s/.. is an :ex
command. If you don't fully understand the difference between Normal,
Insert, Command, Visual, etc. modes, you can't get far.
In the case shown, since you are already at the :ex prompt, you
don't need the normal command for the s/// substitute commands.
However, if you are writing a script, then of course you don't need
the : before everything, so this is one alternative:
%s/^[ ]*//g
%s/[ ]*$//g
If your just typing it in, you still need to enter the :ex prompt,
of course. The gg is redundant with the % range shortcut.
If you want to run an :ex mode command from a script using normal
(which is useful if you want to put the command together a piece at a
time):
exe 'normal :%s/^/"/' . "\<CR>"
A bare <CR> (meaning 4 chars: < + C + R + > ) only works in some
circumstances (i.e. mappings). Here, the format "\<keyname>" is
translated to the actual key value in a script.
Other versions I tried were:
:normal gg
:normal %s/^[ ]*//g<CR>
:normal gg
:normal %s/[ ]*$//g<CR>
and
:normal gg
:normal :%s/^[ ]*//g<CR>
:normal gg
:normal :%s/[ ]*$//g<CR>
(Intention is to strip off all leading and trailing white space from
a file. It is an experiment, so I choose this basic task. May be
there is one command to achieve this, but as said...I used this as an
exercise.
I put that into a file, change to a buffer with an text, which has
superflous space in it and did a :so <file.vim>. The screen flickers
-- no result other than this. I did a :so! <file.vim> with the same
Oh, come on. A screen flicker is an entertaining result. Just put it
in a loop, and sit back and watch.
result. I yanked the script and did a :@" -- same result.
What did I so badly wrong here ?
The cataclysm of newbieness! You should take a week, and read the doc
files from start to finish, several times, while doing all the
exercises. HahahaHAhAhoo! That was fun to write. The pinnacle of
hypocrisy :-O ;-)
THANK YOU very much for any helpful reply in advance!
mcc