Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-17 Thread sun

 You may even try (untested)

:inoremap   CRCR.BS

With the mapping above, you don't have to add a character then delete it: you
hit the Return key, and Vim (with 'nopaste') maps it to hit Return, hit dot,
hit backspace, i.e., the insertion-deletion game is played automatically
whenever you hit Return in Insert mode. What more do you want?

...or at least that's how I think it works.


o, now I get your point. This mapping indeed inserts the space.
However, I think the disavantage of this way is one has to append all
inserting commands, e.g, o O, with .BS.


Best regards,
Tony.


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-17 Thread Andy Wokula

Gary Johnson schrieb:

On 2007-04-16, fREW [EMAIL PROTECTED] wrote:

 On 4/16/07, Tom Whittock [EMAIL PROTECTED] wrote:

What I need is to always keep the auto-indented spaces.  So next time
I can start to insert from the spaced cursor.

Alternatively use cc to edit the ostensibly blank line. This will open
the line using the correct auto indent. Get into this habit and it
doesn't matter what state the line was in before - you always get the
right indentation.

Cheers.


 I tried cc and S and neither of them correctly reindented the line for
 me.  What gives?


It may depend on the indentation mechanism being used.  That is, on 
whether you're using 'autoindent', 'cindent', 'indentexpr' or 
something else.  For example, it works fine when I edit C code (with 
'cindent' set) but not in this e-mail (with only 'autoindent' set).  
If I indent this paragraph, then try to add a line below the last 
line by typing S or cc on that empty line, the new line starts in 
column 1.  I don't know why that is.


Regards,
Gary


   :h 'ai
| Copy indent from current line when starting a new line (typing CR in
| Insert mode or when using the o or O command).

cc uses the indent of the current line.  Thus if it is empty there is no
indent.  Try using
   :setl inde=indent(v:lnum-1)

--
Regards,
Andy

EOM


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-16 Thread sun

  Do I need always type a char then BS?
  Is there a better solution? I wander whether the vim option can do
  this automatically.

A better solution to what problem?  If vim automatically indents
properly when you add a new line, what difference does it make
whether it leaves leading spaces in that line you left or not?



If you want to leave a blank line and add properly indented text to
it later, you can resume editing that line by typing S which should
automatically move your cursor to the proper indentation.

Regards,
Gary


What I need is to always keep the auto-indented spaces.  So next time
I can start to insert from the spaced cursor.

The typing S is a reasonable way although I really want to know how to
change indent-deleting behavior for a empty line in vim.

Best Regards,
sun


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-16 Thread panshizhu
sun [EMAIL PROTECTED] wrote on 2007-04-16 15:57:21:
 What I need is to always keep the auto-indented spaces.  So next time
 I can start to insert from the spaced cursor.

 The typing S is a reasonable way although I really want to know how to
 change indent-deleting behavior for a empty line in vim.

 Best Regards,
 sun

Few people need that feature, so it is not there, I believe more than 99%
of vim users think it is better to just delete the trailing blanks.

If you still insist that the indent-deleting should be changed, then you
can do-it-yourself. The indent script and vim source are all open to you
and please feel free to change them (for your own custimized version, of
course).

--
Sincerely, Pan, Shi Zhu. ext: 2606



Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-16 Thread Tom Whittock

 What I need is to always keep the auto-indented spaces.  So next time
 I can start to insert from the spaced cursor.


Alternatively use cc to edit the ostensibly blank line. This will open
the line using the correct auto indent. Get into this habit and it
doesn't matter what state the line was in before - you always get the
right indentation.

Cheers.


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-16 Thread fREW

On 4/16/07, Tom Whittock [EMAIL PROTECTED] wrote:

  What I need is to always keep the auto-indented spaces.  So next time
  I can start to insert from the spaced cursor.

Alternatively use cc to edit the ostensibly blank line. This will open
the line using the correct auto indent. Get into this habit and it
doesn't matter what state the line was in before - you always get the
right indentation.

Cheers.



I tried cc and S and neither of them correctly reindented the line for
me.  What gives?


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-16 Thread A.J.Mechelynck

sun wrote:
The idea of the comment shown above was to leave something to remind 
you that
you had to come back later, since, as you said, you want to leave the 
indent
there for future use; also, the comment would be sure to stay in 
place even
if the bare indent didn't. But if just adding, let's say, a period, 
then
backspacing over it, makes the indent remain, then you don't have to 
type a

lengthy comment unless you need it.

You may even try (untested)

   :inoremap   CRCR.BS

Note: Next time, please use Reply to all rather than Reply to sender,
unless you're straying off-topic.

Best regards,
Tony.




 Do I need always type a char then BS?
 Is there a better solution? I wander whether the vim option can do
 this automatically.


With the mapping above, you don't have to add a character then delete it: you 
hit the Return key, and Vim (with 'nopaste') maps it to hit Return, hit dot, 
hit backspace, i.e., the insertion-deletion game is played automatically 
whenever you hit Return in Insert mode. What more do you want?


...or at least that's how I think it works.


Best regards,
Tony.
--
Speer's 1st Law of Proofreading:
The visibility of an error is inversely proportional to the
number of times you have looked at it.


how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread sun

Dear all,

The question is:

When I insert a line then Esc to edit other place, vim of C filetype
delete the auto-indented space. But i want to keep the indent there
for the future editing? Then how to make the auto-indent always insert
the indent-space regardless whether the line is empty or not?

I read the help file about the 'cpoption' option, it says 'set
cpoption+=I' can avoid the indent deleting when move the cursor
updown, but I can't let that work.

Best Regards,
sun


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread A.J.Mechelynck

sun wrote:

Dear all,

The question is:

When I insert a line then Esc to edit other place, vim of C filetype
delete the auto-indented space. But i want to keep the indent there
for the future editing? Then how to make the auto-indent always insert
the indent-space regardless whether the line is empty or not?

I read the help file about the 'cpoption' option, it says 'set
cpoption+=I' can avoid the indent deleting when move the cursor
updown, but I can't let that work.

Best Regards,
sun



If you type an arbitrary character, then delete it immediately, does the extra 
whitespace stay in place when you move the cursor away? If it does, you may 
resort to adding a placeholder comment, like:


function MyFunc()
{
/* TODO: code needed here */
};



Best regards,
Tony.
--
Nuke the gay, unborn, baby whales for Jesus.


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread sun

If you type an arbitrary character, then delete it immediately, does the extra
whitespace stay in place when you move the cursor away?



yes, the spaces remain.



If it does, you may
resort to adding a placeholder comment, like:

function MyFunc()
   {
   /* TODO: code needed here */
   };



you mean just add several character using a quick-key map? but then
everytime i type the code before /* TODO: code needed here */, i
have to delete it.
can i change the default behavior of vim not to delete the indent?


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread A.J.Mechelynck

sun wrote:
If you type an arbitrary character, then delete it immediately, does 
the extra

whitespace stay in place when you move the cursor away?


yes, the spaces remain.


If it does, you may


I meant if it doesn't


resort to adding a placeholder comment, like:

function MyFunc()
   {
   /* TODO: code needed here */
   };


you mean just add several character using a quick-key map? but then
everytime i type the code before /* TODO: code needed here */, i
have to delete it.
can i change the default behavior of vim not to delete the indent?



The idea of the comment shown above was to leave something to remind you that 
you had to come back later, since, as you said, you want to leave the indent 
there for future use; also, the comment would be sure to stay in place even 
if the bare indent didn't. But if just adding, let's say, a period, then 
backspacing over it, makes the indent remain, then you don't have to type a 
lengthy comment unless you need it.


You may even try (untested)

:inoremap   CR  CR.BS



Note: Next time, please use Reply to all rather than Reply to sender, 
unless you're straying off-topic.


Best regards,
Tony.
--
hundred-and-one symptoms of being an internet addict:
171. You invent another person and chat with yourself in empty chat rooms.


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread panshizhu
sun [EMAIL PROTECTED] 写于 2007-04-15 17:27:28:
 Dear all,

 The question is:

 When I insert a line then Esc to edit other place, vim of C filetype
 delete the auto-indented space. But i want to keep the indent there
 for the future editing? Then how to make the auto-indent always insert
 the indent-space regardless whether the line is empty or not?

 I read the help file about the 'cpoption' option, it says 'set
 cpoption+=I' can avoid the indent deleting when move the cursor
 updown, but I can't let that work.

 Best Regards,
 sun

If you insert a line, and then go somewhere else, and then come back, you
can just type dd to delte the newly inserted line and type o to insert a
new line again. This is only 3 keystrokes and it solves all problem, your
indent come back.

Anyway, this behavior is good for avoid trailing blanks.

--
Sincerely, Pan, Shi Zhu. ext: 2606

Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread sun

Do I need always type a char then BS?
Is there a better solution? I wander whether the vim option can do
this automatically.


The idea of the comment shown above was to leave something to remind you that
you had to come back later, since, as you said, you want to leave the indent
there for future use; also, the comment would be sure to stay in place even
if the bare indent didn't. But if just adding, let's say, a period, then
backspacing over it, makes the indent remain, then you don't have to type a
lengthy comment unless you need it.

You may even try (untested)

   :inoremap   CRCR.BS

Note: Next time, please use Reply to all rather than Reply to sender,
unless you're straying off-topic.

Best regards,
Tony.


Re: how to avoid deleting the auto-indent in a new empty line when i press Esc

2007-04-15 Thread Gary Johnson
On 2007-04-16, sun [EMAIL PROTECTED] wrote:

  The idea of the comment shown above was to leave something to 
  remind you that
  you had to come back later, since, as you said, you want to leave the 
  indent
  there for future use; also, the comment would be sure to stay in place 
  even
  if the bare indent didn't. But if just adding, let's say, a period, then
  backspacing over it, makes the indent remain, then you don't have to type a
  lengthy comment unless you need it.
 
  You may even try (untested)
 
 :inoremap   CRCR.BS
 
  Note: Next time, please use Reply to all rather than Reply to sender,
  unless you're straying off-topic.
 
  Best regards,
  Tony.

  Do I need always type a char then BS?
  Is there a better solution? I wander whether the vim option can do
  this automatically.

A better solution to what problem?  If vim automatically indents 
properly when you add a new line, what difference does it make 
whether it leaves leading spaces in that line you left or not?

If you want to leave a blank line and add properly indented text to 
it later, you can resume editing that line by typing S which should 
automatically move your cursor to the proper indentation.

Regards,
Gary

-- 
Gary Johnson | Agilent Technologies
[EMAIL PROTECTED] | Mobile Broadband Division
 | Spokane, Washington, USA