Re: Open all folds in the current fold?

2007-06-04 Thread Andy Wokula

Tim Chase schrieb:

I'm trying to find/create a command that acts somewhat like zO/zR
for within an existing fold.

If I use zR, it opens all the folds in the whole document.

If I use zO, it opens all the folds under the cursor.

The behavior I'm looking for is that if I'm within an existing
fold, it recursively opens all the folds within the current fold:

 --- line 1
 |   line 2 with cursor here
 |-- line 3
 ||  line 4
 ||+ line 5 (3 lines)
 ||  line 8
 ||+ line 9 (5 lines)
 |+  line 10 (20 lines)
 |+  line 30 (15 lines)
 |   more stuff
 after the fold
 +   some other fold I don't want to touch

With the cursor on line two, I'd like to recursively open all the
folds in the containing fold (lines 1 through more stuff).
Using zO does nothing because there's no currently closed fold
under the cursor even though there are other folds within the
currently containing fold.  Using zR opens lines such as the
some other fold I don't want to touch line which is more than I
want to unfold.

Any hints on this?  I've toyed a little with :folddoclosed but it
seems to be closer to zR than I want for my purposes.

Thanks,

-tim


zO on visual area recursively opens all folds in it.

   mc[zV]zzO`c

--
Regards,
Andy


Re: Defining new visual-mode motions?

2007-06-02 Thread Andy Wokula

Yegappan Lakshmanan schrieb:

Hi,

On 6/2/07, Andy Wokula [EMAIL PROTECTED] wrote:


Within a function (or script or Ex-mode), the visual area is not 
turned off

between ex commands, because there is no actual mode switching
... IMHO.

I don't know if this is mentioned in the help.



According to :help mode-switching, it is not possible to enter visual 
mode

from Ex or command-line mode. Either the table under :help i_esc needs
to be updated or this needs to be fixed.

According to that table, you can enter visual mode only from either 
normal or

select modes.

- Yegappan


The following is possible:
   Q
enter Ex mode
   normal v
   normal eee
extend visual area
   visual
quit Ex mode, enter Visual mode

Hmm, seems the table needs an update.
Unfortunately, :visual is ambigious.

--
Regards,
Andy


Re: copying text char-by-char from the line above line..

2007-05-31 Thread Andy Wokula

Ajay Gupta schrieb:

Hi All,

I saw one of my friends (once!) copying the text from the line right
above. He was using some keycombo and it would appear like he was
copying the characters one-by-one. So, if there are two lines like

quick brown fox
I see

and on the 2nd line, after 'see', i wanted to copy 'brown fox' from
the 1st line, I will just keep pressing that keycombo 9 times.

I know how to copy the full line, text till some character, etc. But,
I was just wondering how to do the above. Does anybody know how to do
this?

thanks...
Ajay


:h i_Ctrl-Y

--
Regards,
Andy


Crash with strftime()

2007-05-23 Thread Andy Wokula

Not nice:

  :echo strftime(%e)
   %e - some undefined code I used by accident

makes Vim crash.

(GVim 7.0.235, Win32)

--
Regards,
Andy


Re: Crash with strftime()

2007-05-23 Thread Andy Wokula

Anatoli Sakhnik schrieb:

Hi!

I observe different results. The compiled on MinGW gvim doesn't crash,
but displays nothing. Under linux it works quite well, and prints the
day of the month, i.e. 23.

So the crash may refer to a bug in the system libraries or
environments. It'd be interesting to have look at the crash from a
debugger.

-- Anatoli Sakhnik.

On 23/05/07, Andy Wokula [EMAIL PROTECTED] wrote:

Not nice:

   :echo strftime(%e)
%e - some undefined code I used by accident

makes Vim crash.

(GVim 7.0.235, Win32)

--
Regards,
Andy


Also no crash with the original GVim 7.0 Win32 distribution
(returns empty string).

--
Regards,
Andy


Re: A performance question

2007-05-22 Thread Andy Wokula

A.J.Mechelynck schrieb:

Robert M Robinson wrote:


First, thanks very much for creating VIM!  I have been using it on 
Linux systems for years, and now use it via cygwin at home as well.  I 
vastly prefer VIM to EMACS, especially at home.  I learned vi on a 
VAX/VMS system long ago (a friend of mine had ported it), when our 
computer science department was loading so many people on the VAXen 
that EDT was rendered unusably slow.  I still like VIM largely because 
I can do so much with so little effort in so little time.


That brings me to my question.  I have noticed that when editing large 
files (millions of lines), deleting a large number of lines (say, 
hundreds of thousands to millions) takes an unbelieveably long time in 
VIM--at least on my systems.  This struck me as so odd, I looked you 
up (for the first time in all my years of use) so I could ask why!


Seriously, going to line 1 million of a 2 million line file and typing 
the command :.,$d takes _minutes_ on my system (Red Hat Linux on a 
2GHz Athlon processor (i686), 512kb cache, 3 Gb memory), far longer 
than searching the entire 2 million line file for a single word 
(:g/MyQueryName/p).  Doing it this way fits way better into my usual 
workflow than using head -n 100, because of course I'm using a 
regular expression search to determine that I

want to truncate my file at line 100 in the first place.

I looked in the archive, and couldn't see that this issue had been 
raised before.  Is there any chance it can get added to the list of 
performance enhancement requests?


Thanks,

Max Robinson, PhD



I think this is just part of how Vim behaves.

When you edit a file, Vim holds the whole file in memory (IIUC). When 
you delete a million lines, Vim frees (i.e., releases to the OS) the 
memory those lines were using. That takes some time.



Best regards,
Tony.


What about the numbered registers?
  :h 1

After freeing the lines, they are copied to 1 .
And the content of 1 is shifted to 2 (before, of course)
And so on, until register 9.

To avoid the copies, the blackhole register can be used:
   :.,$d _

If there are copies, registeres can be cleared by hand:
   :let @1 = 
   :let @2 = 
   ...
   :let @9 = 
This also takes time, but frees the memory.

--
Regards,
Andy


Re: Wish: col(^)

2007-05-21 Thread Andy Wokula

Andy Wokula schrieb:

Gary Johnson schrieb:

On 2007-05-21, Andy Wokula [EMAIL PROTECTED] wrote:

 ... get position of first non-blank character in the line.

 If there is col($), there should also be col(^).
 In some situations (e.g. :imap expr)
   :normal ^
 is not allowed.


indent(.)?

HTH,
Gary


Nice, just forgot about indent().
Probably col(^) would be exactly the same as indent(.)+1 and
therefore redundant.


Oops this was slightly wrong.

Probably virtcol(^) would be exactly the same as indent(.)+1
(indent(.) counts virtual columns).

col(^) could still have its uses.

--
Regards,
Andy


Re: Wish: col(^)

2007-05-21 Thread Andy Wokula

Nikolai Weibull schrieb:

On 5/21/07, Andy Wokula [EMAIL PROTECTED] wrote:

... get position of first non-blank character in the line.

If there is col($), there should also be col(^).
In some situations (e.g. :imap expr)
   :normal ^
is not allowed.


Then shouldn't there also be a col(0) for symmetry?

 nikolai


Of course!  For symmetry, also col(|) should be added.

--
Regards,
Andy


Re: Go to start of visual selection

2007-05-16 Thread Andy Wokula

Andy Wokula schrieb:

Tim Chase schrieb:

How can I move the cursor the start of the visual selection?
With the o command, yes.  But how can I make sure the cursor
is at the start while visual mode is on?  The ` motion
followed by gv sets the cursor back to the end if it was
there.


I think it sounds like you want something like the following:

vnoremap gt esc`:exec 'norm '.visualmode().'`lt'cr
vnoremap gb esc`lt:exec 'norm '.visualmode().'`'cr

which gives you a Go to the Top and Go to the Bottom mapping 
within visual mode.


It can be a little funky in blockwise visual-mode, if your ' and ' 
points are top-right and bottom-left (rather than top-left and 
bottom-right), as the top will go to the top-right, not the 
top-left.  I haven't figured out a good way to do this without 
considerably more code in the mapping (save the column of ' and then 
gvO to go back to visual-mode but in the other corner and then 
compare the columns to see which you want, perhaps needing to switch 
back...it's ugly).


However, it should work fine in character-wise and line-wise visual 
modes.


HTH,

-tim


I don't understand why this works.

There must be a difference between
`v`
and
:normal `v`

v defines a new visual area and overwrites the `,` markers.  Why
does ` after :normal move the cursor to the start of the
_previously_ selected visual area?

Thx,
Andy


Ah, with a later Vim7 there is no difference any more.
Obviously this has been fixed with patch 125, dated August 2006.
Ok, this took three months till I got it ...

--
Regards,
Andy


Re: vim 7.1 and cr/lf interpretation

2007-05-14 Thread Andy Wokula

Thomas Michael Engelke schrieb:

:set fileformats?

gives

fileformats=dos,unix, so both formats are available, yet the
detection and switching does not seem to work.


Are you sure _every_ line ends in ^M?

--
Regards,
Andy

EOM


Re: comments after brackets with vim?

2007-05-14 Thread Andy Wokula

Simon Butler schrieb:


hi, when i write this skill (cadence extension language) fragment in 
emacs i get the following:



procedure( vscCheckpointHier( @key lib cell view message inclibs )
let(( ddCVs )
vscPrint0(sprintf( nil Hierarchy for %s,%s,%s ... lib cell 
view ))

when( ddCVs = vscGetHierarchyDDs( ?lib lib ?cell cell ?view view
  ?inclibs inclibs )
vscPrint0(sprintf( nil   %d cellviews. length(ddCVs) ))
vscCheckpoint( ddCVs ?message message)
); when ddCVs
); let
); procedure vscCheckpointHier


Notice all the comments placed on the closing brackets. Is there a way 
to make vim do this?


TIA


Yep.  I just felt the challenge, so I wrote the attached script.
I don't know skill, but I think this comes close to what you want.
Core elements:
  :imap expr ; ...
  searchpair()
Hopefully, filetype skill is what you currently use for those
kind of files.

--
Regards,
Andy

EOM
 Vim filetype plugin code snippet
 Language: skill (cadence extension language)
 File: skill_comment.vim
 Date: 2007 Mai 14
 Author:   Andy Wokula [EMAIL PROTECTED]
 Description: 
   After inserting );, insert the word located before the matching
   opening paren; for some keywords also add their argument.  To work
   properly, all must be found on the same line.

 Installation: (suggestion)
 1. make sure filetype skill is detected
 2. copy this script to ~/.vim/
(to the first entry of 'runtimepath')
 3. :edit
   ~/.vim/after/ftplugin/skill.vim
add the following line:
   runtime skill_comment.vim

 TODO:
 - ignore ); in comments
 - ignore (possibly unbalanced) parens in comments
 - extend s:keywords

if v:version  700
 sorry, Vim7 required
finish
endif

 Mapping for ; in Insert mode
ino bufferexpr ; sidCloseKeyword()

 search for arguments to these keywords:
let s:keywords = ['procedure', 'when']
 (to be extended)

function! sidCloseKeyword()
if getline(.)[col(.)-2] != ')'
 if char just before ; is not )
return ;
 (Note: first getline index is 0, first col is 1)
endif
 move cursor to closing paren (this is allowed)
call cursor(., col(.)-1)
 get position of matching paren:
let pomp = searchpairpos('(','',')','bW')
 [line, column]
if !pomp[0]
return ;
endif
 getline of matching paren
let glineomp = getline(pomp[0])
 get matching keyword:
let word = matchstr(glineomp[: pomp[1]-2], '\k\+\ze\s*$')
if word == 
return ;
endif
if match(s:keywords, '\'.word.'\') = 0
 search for argument
let kwarg = matchstr(glineomp, '\k\+', pomp[1])
 omit trailing space if no argument found
return ;  . word . (kwarg!= ?  .kwarg : )
else
return ;  . word
endif
endfunction


Re: Vim and email quoting

2007-05-11 Thread Andy Wokula

Timothy Knox schrieb:

I use vim to write my outgoing email, and for the most part, it rocks. Thanks to
all the folks who have written modules and provided tips that make it the best
thing for writing email since mailx grin.

That said, there is one small annoyance I find: When replying to an email, I
like to intersperse the original email with my commentary. When I am on the last
line of a paragraph I wish to respond to, I hit o to open a new line. All well
and good, save that something recognises the leading   of the previous
paragraph, and adds one to my new line. Can somebody tell me how to make it
stop? ;-)

Many thanks to you all. :-)


Add the following line to ~/.vim/after/ftplugin/mail.vim :

   setlocal fo-=o

Create the path or file if it doesn't exist.

--
Regards,
Andy

EOM


Re: autocomplete on the command line from words in buffers

2007-05-07 Thread Andy Wokula

Larson, David schrieb:

Hello Dan,

I suggest wrapping these functions into vim commands and then leverage
the command completion feature. See:

:help :command-completion

HTH,
David

-Original Message-
From: Dan Fabrizio [mailto:[EMAIL PROTECTED] 
Sent: Monday, May 07, 2007 5:27 AM

To: vim@vim.org
Subject: FW: autocomplete on the command line from words in buffers

Hello All,


I want to develop a plugin just using vim scripts for the verilog
language.
In the plugin I have functions that require arguments that are words
used in
the current open buffers.

On the command line, I want to autocomplete these words that are
arguments
to functions.

For example:

:call function1(last_Tab,first_Tab)

In open buffers,  the words called last_buffer_value and
first_buffer_value
are used. So when I hit Tab I want that word to be completed so the
result
would be

:call function1(last_buffer_value,first_buffer_value)

Is there a way to do this?

Thanks in advance,
Dan Fabrizio


IMHO this will become difficult.

In Insert mode, Ctrl-N/Ctrl-P scans through the buffers for words, but
I think there is no way to make Vim provide a similar list of completions in the
command-line.

You have to (kind of) scan the buffers yourself ...

Please correct me if I'm wrong

--
Regards,
Andy

EOM


Bug: windo and exceptions

2007-05-02 Thread Andy Wokula

GVim runs into an endless loop if I do the following:

clean startup
   :new  at least two windows
   :windo throw foo

   Error detected while processing :
   E605: Exception not caught: foo
   E605: Exception not caught: foo
   E605: Exception not caught: foo
   E605: Exception not caught: foo
   ...

Another example:

   clean startup
  :set modified
  :bot new
  :try
  :  windo enew

   - go and kill GVim in the task manager

(does not happen if  :bot new  is replaced by  :abo new )

--
Regards,
Andy

EOM


Re: Bug: windo and exceptions

2007-05-02 Thread Andy Wokula

Bram Moolenaar schrieb:

Andy Wokula wrote:


GVim runs into an endless loop if I do the following:

 clean startup
:new  at least two windows
:windo throw foo

Error detected while processing :
E605: Exception not caught: foo
E605: Exception not caught: foo
E605: Exception not caught: foo
E605: Exception not caught: foo
...


See patch below.


Another example:

clean startup
   :set modified
   :bot new
   :try
   :  windo enew

- go and kill GVim in the task manager

(does not happen if  :bot new  is replaced by  :abo new )


Solved with the same patch.  Please verify.


*** ../vim-7.0.240/src/ex_cmds2.c   Tue Feb 13 06:21:24 2007
--- src/ex_cmds2.c  Wed May  2 22:04:38 2007
***
*** 2287,2292 
--- 2287,2294 
if (!win_valid(wp))
break;
win_goto(wp);
+   if (curwin != wp)
+   break;  /* something must be wrong */
wp = curwin-w_next;
}
else if (eap-cmdidx == CMD_tabdo)


Great, the patch works (examples tested).

--
Thanks,
Andy

EOM


Re: Avoiding German Umlauts....

2007-04-27 Thread Andy Wokula

A.J.Mechelynck schrieb:

[EMAIL PROTECTED] wrote:

Hi,

 I want to write a macro, function or what else, which ensures, that
 no german umlauts (äöüÄÖÜ) or the sz (ß) will ever occure in any
 file written with vim. It does not matter, if these charactes will
 appear while typing but they should never and under no circumstances
 be saved to disk. Best solution however would be, if they were
 changed on the fly to their replacements:
 
 umlaut a ä - ae

 umlaut o ö - oe
 umlaut u ü - ue

 umlaut A Ä - Ae
 umlaut O Ö - Oe
 umlaut U Ü - Ue

 sz ß - sz

 I did some experiments, which had worked under some circumstances and
 did not under others.
 But I need something, which does the replacements under any
 condition.
 
 Keep editing!

 mcc


just another variant ...

Method I: will remove all umlauts in all files, even preexisting ones 
(if any) at write-time.


   scriptenc latin1
   function ConvertUmlauts()
range is whole file
let udict = {'ä':'ae', 'ö':'oe', 'ü':'ue',
\'Ä':'Ae', 'Ö':'Oe', 'Ü':'Ue',
\'ß':'sz'}
%s/[äöüÄÖÜß]/\=udict[submatch(0)]/ge
   endfunction

   autocmd BufWritePre * call ConvertUmlauts()

Method II: will remove umlauts only as you type them. Anything 
preexisting will remain untouched.


Method II a) use a keymap
   :h :lmap
(keymaps use :lmap to define mappings)

File ~/.vim/keymap/umlauts.vim

Vim Keymap
   scriptenc latin1
   let b:keymap_name=de_uml
   loadkeymap
   ä   ae
   ö   oe
   ü   ue
   Ä   Ae
   Ö   Oe
   Ü   Ue
   ß   sz

Argument of :scriptenc is at your taste/needs, I just suggest to
not skip the command because of the non-ascii chars.

Load the keymap:

   :set keymap=umlauts

Toggle keymap on/off:
   :h i_Ctrl-^


From the help:

:lmap defines a mapping that applies to:
Insert mode, Command-line mode, when entering a search pattern,
commands with a character argument (r, f) (won't probably work here),
and for the input() line.

These two solutions are not exclusive of each other: they can be applied 
together.



Note that the official transliteration of the eszett is not sz but ss: 
upcase(ß) is SS and, in de_CH locales, the eszett is not used (other 
than for archaic look, sometimes together with a Fraktur font); ss is 
used in its stead everywhere.


IMHO sz is ugly, but unique.  There is no upper ß.


Best regards,
Tony.


--
Regards,
Andy

EOM



Re: Avoiding German Umlauts....

2007-04-27 Thread Andy Wokula

A.J.Mechelynck schrieb:

Andy Wokula wrote:

A.J.Mechelynck schrieb:

[...]
Note that the official transliteration of the eszett is not sz but 
ss: upcase(ß) is SS and, in de_CH locales, the eszett is not used 
(other than for archaic look, sometimes together with a Fraktur 
font); ss is used in its stead everywhere.


IMHO sz is ugly, but unique.  There is no upper ß.


Best regards,
Tony.




Strictly speaking, there is no _titlecase_ ß because that letter must 
always follow a vowel. There is an uppercase equivalent of ß, which is 
SS, as shown by the fact that, for instance (in modern German spelling, 
I'm not talking of 19-th century spelling), the uppercase counterpart of 
schließen, for use in all-caps titles, is SCHLIESSEN, not 
SCHLIESZEN or SCHLIEßEN. (I've seen a German atlas printed between 
1871 and 1918, where the name of Russia was spelled RUSZLAND.) Also 
I'm not talking about the Vim ~ operation here (which is not normative) 
but about upcasing rules as decided by whoever decides that in 
German-language countries (it used to be Duden but IIUC it isn't 
anymore) and put down in the upcasing-downcasing rules which are (IIUC) 
included in the Unicode Standard.


Interesting.  I wasn't aware of that the rules of new german spelling
dumped the sz completely.

there is no upper ß should express that there is no non-ASCII uppercase
equivalent of ß that can occur in a text and needs translation into
SS.

sz is unique (i.e., reversible) but since the OP doesn't want an 
eszett in his text, how does reversibility concern him? ss is the 
official graphy in Switzerland as well as wherever an ß glyph is not 
available. It's true that there is no obvious mechanical rule (without 
a dictionary, I mean) to convert Fuss to Fuß but Fluss to Fluss.


Using ss, some words get a different meaning, e.g. Maße vs. Masse.
Although in most (if not all) cases context should make it clear which
meaning applies.


Best regards,
Tony.


--
Regards,
Andy

EOM


Re: wish: allow a: in the function def

2007-04-24 Thread Andy Wokula

Thomas schrieb:

Yakov Lerner schrieb:

wish: allow a: in the function definition line:
  function foo(a:line1, a:line2)


yeah, occasionally I do

  :setl isk+=:

to get completion of variable names in vim scripts.
I'd like to have this for function arguments, too.


Counterwish: implement better semantics for VimScript so that the
lookup order of variables alleviates the need for explicit
environments.  Yes, this will break backwards compatibility.


I personally like both wishes. I don't think that this has to 
necessarily break backwards compatibility as variables can already have 
implicit prefixes: eg foo could be l:foo when used in a function or 
g:foo when used in global scope.


So maybe one could make vimscript search a variable foo as l:foo, a:foo, 
(maybe also: w:foo, b:foo), s:foo, g:foo, and then throw an undefined 
variable name error if none exists. Or so.


Don't like the idea.
In Vim script there is no need or possibility to declare variables.
Now, if I forget to init a fun-local variable (happens often to me)
Vim gives me a helpful error (undefined variable).

This wouldn't be the case anymore if Vim could find obscure variables with
the same name I've never heard of (e.g. set by some weird plugin).

Also would it be _recommended_ to ever use a window-local variable without
the w: prefix? ... IMHO not.

--
Regards,
Andy

EOM


Re: wish: allow a: in the function def

2007-04-24 Thread Andy Wokula

Nikolai Weibull schrieb:

On 4/24/07, Andy Wokula [EMAIL PROTECTED] wrote:

Thomas schrieb:


 So maybe one could make vimscript search a variable foo as l:foo, 
a:foo,

 (maybe also: w:foo, b:foo), s:foo, g:foo, and then throw an undefined
 variable name error if none exists. Or so.



Don't like the idea.
In Vim script there is no need or possibility to declare variables.
Now, if I forget to init a fun-local variable (happens often to me)
Vim gives me a helpful error (undefined variable).


And I have the same problem with a: prefixes for my arguments.  Fine,
keep prefixes for g:, w:, and b:, but a: is just such an incredibly
nonstandard way of doing things.  In almost all languages parameters
are treated the same as local variables.

 nikolai


As long as function arguments are read-only, it is good to have
the a: modifier.

In fact, why are they read-only, although call is by value?

--
Regards,
Andy

EOM


Re: strange commenting behaviour (text gets deleted)

2007-04-18 Thread Andy Wokula

Daniel Nogradi schrieb:

 Hi vimmers,

 I have a very strange problem and couldn't figure out what's going on.
 I use the following function for commenting out a line or a block of
 lines:


 function! Komment2(commentLeader, commentTrailer)
if match( getline(.), ^\ *$ )  0
let save_cpo   = cpoptions
let save_paste = paste
set cpovim
set paste
let escCommentLeader = escape(a:commentLeader, '^[.*\~]$')
let escCommentTrailer = escape(a:commentTrailer, '^[.*\~]$')
if getline(.) =~ '^\s*' . escCommentLeader . '.*' .
 escCommentTrailer . '$'
execute normal ^ . strlen(a:commentLeader) . x$ .

_ ,--^
Workaround: insert zv between x and $ to make sure the fold is open.
:h zv


 strlen(a:commentTrailer)
 . hl . strlen(a:commentTrailer) . x
else
execute normal I . a:commentLeader . \ESC . A .
 a:commentTrailer . \
 ESC
endif
let cpo   = save_cpo
let paste = save_paste
endif
echo
 endfunction


 This function is a modified version of something I found in one of the
 tips or scripts of the vim website. For C I use of course

 Komment2('/* ', ' */')

 and this works perfectly well, I can select a block of lines, call the
 above function and every line will be commented out. It even works in
 a toggling way, so commented lines will be uncommented. So far so
 good, now comes the strange behaviour.

 If there is a line which only contains a { character and that line is
 commented out so it looks like /* { */ and then I call the above
 function to uncomment it, everything below this line will be deleted.

 It's probably unrelated

It is very related ...

 but just in case I mention that I have the
 following syntax method set:

 syn region myFold start='{' end='}' transparent fold
 set foldmethod=syntax

I just reproduced what happens:

With the (syntax) fold opened, go to the first / of the
comment
   /* { */
Then press x (or 3x as the function does), this will remove the /
and CLOSE THE FOLD (WHY??)

The next 3x will then remove the whole fold.

While trying this out, I had ft=vim set.  It obviously happens with
filetype C too.  It doesn't happen with some other filetypes.
Currently, I have no idea what's going on ...


Thanks for the explanation, that's indeed what seems to be happening,
but I still couldn't find a good way to circumvent it. How do other
people deal with syntax folding and commenting?


E.g. search on vim.org for comment.

I'd try to avoid Normal mode commands:

function! Komment3(Leader, Trailer)
let line = matchstr(getline(.), '\S.*')
if line == ''
  return
endif
let indent = matchstr(getline(.), '^\s*')
let pat = '^\V'.escape(a:Leader, '\') . '\(\.\*\)'
let pat .= escape(a:Trailer, '\').'\$'
if line =~ pat
  call setline(., indent . substitute(line, pat, '\1', ''))
else
  call setline(., indent . a:Leader . line . a:Trailer)
endif
endfunction

--
Regards,
Andy

EOM





Re: strange commenting behaviour (text gets deleted)

2007-04-18 Thread Andy Wokula

Andy Wokula schrieb:

Daniel Nogradi schrieb:

[...]
This function is a modified version of something I found in one of
the tips or scripts of the vim website. For C I use of course

Komment2('/* ', ' */')

and this works perfectly well, I can select a block of lines, call
the above function and every line will be commented out. It even
works in a toggling way, so commented lines will be uncommented. So
far so good, now comes the strange behaviour.

If there is a line which only contains a { character and that line is
commented out so it looks like /* { */ and then I call the above
function to uncomment it, everything below this line will be deleted.

It's probably unrelated


It is very related ...


but just in case I mention that I have the following syntax method
set:

syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax


I just reproduced what happens:

With the (syntax) fold opened, go to the first / of the
comment
  /* { */
Then press x (or 3x as the function does), this will remove the /
and CLOSE THE FOLD (WHY??)

The next 3x will then remove the whole fold.

While trying this out, I had ft=vim set.  It obviously happens with
filetype C too.  It doesn't happen with some other filetypes.
Currently, I have no idea what's going on ...


IMHO there is nothing wrong, at least with Vim.
In fact, it's all about how syntax folding works.

In order to fold code, your additional syntax rule


syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax


must get a chance to match text.  But as long as the '{' within
  /* { */
is hidden by the comment, your rule is not applied and therefore doesn't
fold anything.  Now if '/* ' is removed, resulting in
  { */
the Highlighter suddenly matches '{' with your rule and closes the fold
(depending on foldlevel etc.)

In a Vim script, the effect is the same, but for different reasons.
The line
  /* { */
is matched by the vimSearch group, hiding the '{' in it, but the text
  { */
again allows a match for '{' at top-level.

--
Regards,
Andy

EOM


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: strange commenting behaviour (text gets deleted)

2007-04-17 Thread Andy Wokula

Daniel Nogradi schrieb:

Hi vimmers,

I have a very strange problem and couldn't figure out what's going on.
I use the following function for commenting out a line or a block of
lines:


function! Komment2(commentLeader, commentTrailer)
   if match( getline(.), ^\ *$ )  0
   let save_cpo   = cpoptions
   let save_paste = paste
   set cpovim
   set paste
   let escCommentLeader = escape(a:commentLeader, '^[.*\~]$')
   let escCommentTrailer = escape(a:commentTrailer, '^[.*\~]$')
   if getline(.) =~ '^\s*' . escCommentLeader . '.*' .
escCommentTrailer . '$'
   execute normal ^ . strlen(a:commentLeader) . x$ .
strlen(a:commentTrailer)
. hl . strlen(a:commentTrailer) . x
   else
   execute normal I . a:commentLeader . \ESC . A .
a:commentTrailer . \
ESC
   endif
   let cpo   = save_cpo
   let paste = save_paste
   endif
   echo
endfunction


This function is a modified version of something I found in one of the
tips or scripts of the vim website. For C I use of course

Komment2('/* ', ' */')

and this works perfectly well, I can select a block of lines, call the
above function and every line will be commented out. It even works in
a toggling way, so commented lines will be uncommented. So far so
good, now comes the strange behaviour.

If there is a line which only contains a { character and that line is
commented out so it looks like /* { */ and then I call the above
function to uncomment it, everything below this line will be deleted.

It's probably unrelated


It is very related ...


but just in case I mention that I have the
following syntax method set:

syn region myFold start='{' end='}' transparent fold
set foldmethod=syntax


I just reproduced what happens:

With the (syntax) fold opened, go to the first / of the
comment
  /* { */
Then press x (or 3x as the function does), this will remove the /
and CLOSE THE FOLD (WHY??)

The next 3x will then remove the whole fold.

While trying this out, I had ft=vim set.  It obviously happens with
filetype C too.  It doesn't happen with some other filetypes.
Currently, I have no idea what's going on ...

--
Regards,
Andy

EOM


Re: Troubles configuring vim (multi-questions)

2007-04-14 Thread Andy Wokula

OnionKnight schrieb:

I think I understand the difference now and my function is pretty neat now.
function! HomeKey ()
let c = col(.)
if c == 1
normal ^
else
normal ^
if col(.) = c
normal 0
endif
endif
endfunction


quote= comes handy:

   :noremap silent home @=col(.)==1?^:0cr
   :imap home c-ohome

Noremap because it also works for Visual mode.

--
Regards,
Andy

EOM


Re: case of very slow regex search

2007-04-03 Thread Andy Wokula

Yakov Lerner schrieb:

I use sometimes the regex that finds paragraphs
containing given words w1,w2,... in any order ( I define paragraph
as separated by lines, \n\n).

I use the pattern like this: (two-word example, w1 and w2, but easily
expandable for N words):
   /\c\(.\|.\n\)*\w1\\\(.\|.\n\)*\w2\
  (and I set :set maxmempattern=2 )
This works. But search time is unbelievably slow on big files.

My question is; is there a rewrite of this  regex that works faster.

To see the testcase how of how slow this works:
  1. wget http://www.vmunix.com/~gabor/c/draft.html
 # this is ~1.3 MB file.
  2. vim draft.html
  3. /\c\(.\|.\n\)*\w1\\\(.\|.\n\)*\w2\
 This search never finishes for me.

How  can I rewrite the regex to search faster ?

Yakov


Prepeding  \n\n\zs  helps ...

--
Regards,
Andy

EOM


Re: Question about b:did_ftplugin

2007-04-02 Thread Andy Wokula

Thomas schrieb:

Hi,

When I set a filetype for a buffer the variable b:did_ftplugin is set.

The help says:

If you are writing a filetype plugin to be used by many people, they 
need a

chance to disable loading it.  Put this at the top of the plugin: 

 Only do this when not done yet for this buffer
if exists(b:did_ftplugin)
  finish
endif
let b:did_ftplugin = 1


Now, when I do set ft=X from the command line, it happens that the 
ftplugin X doesn't get loaded because it finishes when b:did_ftplugin is 
set.


When is b:did_ftplugin ever unset? What's the rationale of setting 
b:did_ftplugin and not b:did_ftplugin_X?


Regards,
Thomas.


ftplugins should define b:undo_ftplugin .
   :h undo_ftplugin
If this var exists and its commands get executed then (only then) also
b:did_ftplugin will be unset.

Executing b:undo_ftplugin is one of the first things  :setf X  tries
to do.

--
Regards,
Andy

EOM


Re: Vim Help for deleting alternate lines in text

2007-03-31 Thread Andy Wokula

Gary Johnson schrieb:

Auro Ashish Saha wrote:

Hello,

Please help me to remove alternate lines from a text file.

00 0
123456 9
99 9
123445 9

I want to delete the line 1, 3, 5 and so on. What are the commands to be
used. Thanks for help in advance.


Method I:

qddjjq
count@

where count is equal to the number of lines still to be deleted


This version will work:

qqddjq
count@q

Note that it uses the q register instead of the  register.  Also, 
if you don't want to try to figure out what count should be, and 
if you don't want to remove a huge number of lines, you can execute 
the recorded commands the first time after you record them with this 
command:


@q

and every subsequent time with this command:

@@

That way, once you've recorded the command and executed it once from 
the q register, you can just hold your finger on the @ key and watch 
the lines disappear.  As you get close to the bottom of your file, 
you can start slowing down and typing just two @'s at a time.


Macros stop if an error (- beep) occurs

   [EMAIL PROTECTED]

will stop if end-of-file reached because j cannot go further.


Method II (all on one line if typed on the Vim command-line):

 :let i=1 | while i = line('$') | if (i % 2) | exe i . delete |
endif |
endwhile


It looks as though Tony left out part of Method II:  i is never 
incremented.  I modified it as shown below (added let i += 1 |)and 
verified that it works.


:let i=1 | while i = line('$') | if (i % 2) | exe i . delete | endif | 
let i += 1 | endwhile

HTH,
Gary


Method III:

  :2,$-1g/^/+1d
  :1d 


--
Regards,
Andy

EOM


Re: Selecting tag opens file in a new tab - how?

2007-03-23 Thread Andy Wokula

A.J.Mechelynck schrieb:

Zarko Coklin wrote:

I posted following question some time back:
~
Is it possible to have a setup in .vimrc so that every
time I select tag either through CTRL-] or by
holding CTRL and pressing left mouse click to open a
new buffer in a new tab?

and got following answer that works:
:map C-] :exe tab stag expand(cword)CR
:map C-LeftMouse :exe tab stag
expand(cword)CR
~
The trouble I am having at the moment is that this
approach leads to a quick proliferation of open file
tabs. Ideally, Vim should not open a new tab for the
the file that already has a tab. Rather, it should
simply reuse an existing tab and position itself
within an open tab. Is there a way to get that done?

Thanks in advance,
Zarko


I think it is possible, but not easy, and would require writing a custom 
function, especially if you want to still be able to have split windows. 
I'm not going to try. You may want to try for yourself, or change your 
behaviour.


See, among others:
:help tabpagenr()
:help tabpagewinnr()
:help tabpagebuflist()
:help bufname()
etc.

Best regards,
Tony.


Another idea: Usage of 'switchbuf'
   :set switchbuf=useopen,usetab

Problem: Works with buffer names only
- Get filename of tag and search it in the buffer list

i.e. (first move cursor to tag)
   :exe tab sbuf taglist(expand(cword))[0].filename

HTH,
Andy

--
EOM





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Count characters

2007-03-22 Thread Andy Wokula

Tim Chase schrieb:
Is there some function or script to count characters (letters without 
whitespaces) in vim?


For example Kile the Latex Editor has such a feature to control how 
long texts are.



You can use

:%s/\w//g

which will report back X substitutions on Y lines.  X represents the 
number of characters of interest.  Adjust the \w regexp for whatever 
constitutes your definiton of characters that you want to count.  
Thus, this might be


:%s/\a//g (only letters)
:%s/\S//g(non-whitespace)

Or any other such combo.

It does have the side effect of modifying your document (setting the 
modified flag).  If this is a problem, you can undo it and it should 
revert.  It also requires that the document not be readonly (or at least 
it will gripe if it is, warning you that you're changing a RO document).


If you have fewer than 'report' characters, Vim won't report back:

:help 'report'

but you can set this to

:set report=0

to always report any changes.

There are ways to do it on non-modifiable buffers, but they require a 
bit more programatic logic, such as


:let x=0
:g/^/let x+=strlen(substitute(getline('.'), '\W', '', 'g'))
:echo x

where the '\W' is the inverse-set of characters of interest.  In this 
case, if you're interested in \w characters, the \W is the inverse.  
If you're interested in non-whitespace characters (\s), you would use 
\S; and if you're interested in counting vowels, you could use 
[^aeiouAEIOU].


You might even notice that the second version uses a :g command that 
matches every line.  With this, you have a lot of flexibility:


  :','g/^/let ...  counts characters in the linewise selection
  :g/foo/let ... counts characters on lines containing foo

and the like.

All sorts of fun things at your disposal :)  Hope this helps,

-tim


Therefore in Vim7 the 'n' flag was added to the
substitute command:

   :%s/\S//gn

just reports the number of matches.  Works also
for read-only files, because no text is changed.

   :h :s_flags

Andy

--
EOM





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Vim Help for deleting text

2007-03-20 Thread Andy Wokula

Arnaud Bourree schrieb:


Arnaud Bourree wrote on 20/03/2007 10:22:

Tim Chase wrote on 19/03/2007 23:01:

Or, if all your columns align, you can use visual-block mode with
control+V to create a block across the characters in question, and then
just hit d to delete.

-tim


Sorry, I'm begginer with VIM (Windows XP).
When I want to select a block with my mouse, I can't select column block.
How can I switch to line mode to column mode?


I reply myself with help file content:
Since CTRL-V is used to paste, you can't use it to start a blockwise Visual
selection.  You can use CTRL-Q instead.  You can also use CTRL-Q in Insert
mode and Command-line mode to get the old meaning of CTRL-V.  But CTRL-Q
doesn't work for terminals when it's used for control flow.


If you're happy with the current setting of Ctrl-V, try the following:

First select text characterwise with your mouse, then open
context menu - Select Blockwise

or
Press the Alt key while making your selection
(e.g. place cursor, press and hold down Alt, click end of selection)

or
use a map like the following in your vimrc to make v toggle visual mode
between characterwise and blockwise:
:vno silent v :c-uexenorm!visualmode()==#v?gv\ltc-v:gvvcr

Andy

--
EOM





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Get date and filename as plain text

2007-03-15 Thread Andy Wokula

Wolfgang Schmidt schrieb:

   Hi,

I don't know about the filename part, but you could insert a date with 
the following mapping:


inoremap @date C-R=strftime(%d.%m.%Y)CR

Cheers,

   Wolfgang

Eric Leenman wrote:

Hi,

Is it possible to make an inoremap that inserts the date as text and 
the filename as text?


For example:

inoremap @date   {insert_date_as_text()}
inoremap @filename   {insert_filename_as_text()}


Rgds,
Eric


 including path
:inoremap @filename C-R=expand(%:p)CR
 without path:
:inoremap @filename C-R=expand(%:t)CR

:h i_CTRL-R
:h filename-modifiers
:h expand()

If there is still no filename, nothing is inserted.

Andy

--
EOM





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: clone a vim session into a new tab

2007-03-13 Thread Andy Wokula

Kamaraju S Kusumanchi schrieb:

Let's say I opened a 6 files in a 3X2 grid inside vim. Now I want to clone
this and have all the files at the same position, same window sizes etc.,
and put it into a new tab under the same vim session. Is there a command to
do this?

commands like tabe etc., open only a single file. But I want to open about 6
files and have the correct window sizes etc.,

Any ideas?

raju


Simple way (recommended or not, at least quick) with sessions:

:mks
 use ! to overwrite existing Session.vim
:tabnew
:so Session.vim

Just guessed it might work and it works.
Now I think sessions don't include tabpages.

Andy

--
EOM



___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: clone a vim session into a new tab

2007-03-13 Thread Andy Wokula

Kamaraju S Kusumanchi schrieb:

Andy Wokula wrote:

Simple way (recommended or not, at least quick) with sessions:

:mks
 use ! to overwrite existing Session.vim
:tabnew
:so Session.vim

Just guessed it might work and it works.
Now I think sessions don't include tabpages.



This works although I use tabe instead of tabn. But there is a small
problem. If I have three already existing tabs, and if I want to clone only
the second tab into a new tab then it does not work. Any other suggestions?

thanks
raju


Ok tabpages are included in the session per default.  Try
:set sessionoptions-=tabpages
first.

:help 'sessionoptions'

Then use again
:mks
 use ! to overwrite existing Session.vim
:tabnew
:so Session.vim 


Andy

--
EOM





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: clone a vim session into a new tab

2007-03-13 Thread Andy Wokula

Kamaraju S Kusumanchi schrieb:

Andy Wokula wrote:


Ok tabpages are included in the session per default.  Try
:set sessionoptions-=tabpages
first.



Awesome! Thanks a lot!


:help 'sessionoptions'



The help is a bit confusing. It says

There is no option to include tab pages yet, only the current tab page
is stored in the session. |tab-page|

But in reality, it stores all the tab pages. Is this a bug in the
documentation? or am I misreading something?

raju


Confuses me too.  Looks like some forgotten beta version note.

Andy

--
EOM


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: visual problem

2007-03-12 Thread Andy Wokula

Simon Jackson schrieb:

I have a problem when i am in visual mode and i have text highlighted.
Instead of being able to run a command, it just overwrites my selected
text instead. im sure its because of something in my vimrc but i just
cant pinpoint it, can anyone help?

P.S.: If anyone sees some errors in my vimrc or maybe how something
can be done more efficiently please let me know.



filetype ondetect the type of file
filetype plugin indent on enable filetype plugin

second line is enough


set gdefault   Use 'g' flag by default with :s/foo/bar/

Can result in obscure errors with some badly written plugin,
that does not reset 'gdefault' to the default.

! Looks like you're not happy with

set selectmode=mouse,key,cmd



au FileType helpfile set nonumber  no line numbers when viewing help
au FileType helpfile nnoremap buffercr c-] Enter selects subject
au FileType helpfile nnoremap bufferbs c-T Backspace to go back

Does this work for you?  On helpfiles,
:set ft?
returns help, not helpfile.


highlight Pmenu guibg=black gui=bold

Works as long as you don't change colorschemes.


Andy

--
EOM


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: How to paste without replace the content in buffer

2007-03-11 Thread Andy Wokula

Peng Yu schrieb:

Hi,

Suppose I want to replace string1 with string2 in a file from vim.

1. Highlight string1 (in visual mode) and then type y.
2. Highlight string2 (in visual mode) and then type p.

However, the problem with the above procedure is that string2,
instead of string1, is in buffer. That is if I highlight string3
and then type p, string3 will be replaced with string2 instead
of string1.

I'm wondering if there is any way to avoid change the content in the 
buffer?


Thanks,
Peng


The Vim teacher already taught you ^^, so here is a hint _why_ this
happens:
:help put-Visual-mode

| (Implementation detail: it actually works by first putting the
| register after the selection and then deleting the selection.)

Obviously, the selection is deleted into the unnamed register, changing
it.

Andy

--
EOM


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Marking an undo-block before ^U in insert-mode

2007-02-23 Thread Andy Wokula

Yakov Lerner schrieb:

On 2/20/07, Tim Chase [EMAIL PROTECTED] wrote:

I'm trying to find a good way to remap control+U in insert-mode
so that it begins an undo-block.  There are times when type
control+U in insert-mode and it doesn't do what I intend, or I
want to undo it, only to find that an undo doesn't solve the
problem.  I know that transitioning out of insert-mode (via esc
or c-o) will mark a point in the undo-stack.  However, I don't
really want to be in insert mode.  I've tried the following:

inoremap c-u c-oescc-u

This does a funky beep/flash (depending on VB settings) and
doesn't behave quite like I would have expected it to.

inoremap c-u c-onopc-u

This gives me a crazy

E486: Pattern not found: insert

which, I haven't searched for the word insert so this one makes
me scratch my head.  Bug perhaps?  Vim-internals showing through?

Have I overlooked some setting that I couldn't find in undo.txt?
 Or does anyone else have a good suggestion on how to tag a
control+U in insert-mode so that it alone can be undone?


Hello Tim,
I am not sure I understand you right, but do you mean somthing like
c-gu in insert mode ? (:help i_CTRL-G_u):

  :imap c-u c-gu
?

:help i_CTRL-G_u
CTRL-G u...break undo sequence, start new change.. *i_CTRL-G_u*

Yakov



There is another strange detail about c-gu

In my vimrc I have (for gVim 6.4, gVim 7.0)
   :imap cr crc-gu

Each u goes back one line of text in the undo history.
Note the imap instead of inoremap.  This way
abbreviations still work.
For the strange part: This mapping does not result
in an endless loop!  I don't know why ... just found
out by trial and error, could someone explain this?

Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Marking an undo-block before ^U in insert-mode

2007-02-23 Thread Andy Wokula

A.J.Mechelynck schrieb:

Andy Wokula wrote:

There is another strange detail about c-gu

In my vimrc I have (for gVim 6.4, gVim 7.0)
   :imap cr crc-gu

Each u goes back one line of text in the undo history.
Note the imap instead of inoremap.  This way
abbreviations still work.
For the strange part: This mapping does not result
in an endless loop!  I don't know why ... just found
out by trial and error, could someone explain this?

Andy



see :help recursive-mapping

Shortly put: A mapping never re-expands its {lhs} at the start of the {rhs}

Best regards,
Tony.


Thanks for the hint :-)

Regards,
Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Insert new blank line in normal mode

2007-02-23 Thread Andy Wokula

A.J.Mechelynck schrieb:

Alexey Vakhov wrote:

Hi Dear community,

Command o and O create new line and switch to insert mode. I want only
insert blank line and stay in normal mode. I know this problem can be
solved using simple mappting, but maybe in vim there are original
commands for this tip?
Thanks a lot



IIUC there are no intrinsic commands for this; but you could use

oEsc
OEsc

at the keyboard, or

:put =''
:.-1put =''


For some reason
   :put_
   :put!_
also work.  Another odd detail, in fact nothing should be inserted (?)
because the black hole register is always empty.


in a script.


Best regards,
Tony.


Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: break option lines

2007-02-06 Thread Andy Wokula

[EMAIL PROTECTED] schrieb:

Hello,

is it possible in a vimrc for comma separated
option strings like this one below to break:

set
dictionary=$VIM\SQLDict\BPMS_Stamm.txt,$VIM\SQLDict\BPMS_Mandant.txt,$VIM\SQL
Dict\CBS_2005.txt,$VIM\SQLDict\ICCS_Net_Strommixer.txt,$VIM\SQLDict\DBS.txt,$
VIM\SQLDict\cbsbestenergy.txt,$VIM\SQLDict\iccs_2005.txt... many other
files..


In the help:

:help line-continuation
:help cpo-C

Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Tips which are spam

2007-02-05 Thread Andy Wokula

Currently there is much spam in recent comments:
http://vim.sourceforge.net/tips/recent_notes.php

Andy

--
EOF


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Tips which are spam

2007-02-05 Thread Andy Wokula

John Beckett schrieb:

Andy Wokula wrote:

Currently there is much spam in recent comments:
http://vim.sourceforge.net/tips/recent_notes.php


Last time this was discussed I got the impression that there is a
feeling that if no one reads the spam, then it is not a problem.

But I think the situation is worse than that. The spammers don't
care if anyone reads the tips. They want the optimisation to their
search ranking in Google et al from having links to their site.
Helping these leaches is no longer acceptable IMHO.

Lots of places on the Internet have had to implement a simple
logon or at least a captcha - anonymous posting can't be allowed.

John


E.g. posters must either login or solve simple math
(or answer simple Vim questions, even better ;)
next to the Add Note button.

Should be fairly easy to add?

Andy

--
EOF


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Go to start of visual selection

2007-02-04 Thread Andy Wokula

Tim Chase schrieb:

How can I move the cursor the start of the visual selection?
With the o command, yes.  But how can I make sure the cursor
is at the start while visual mode is on?  The ` motion
followed by gv sets the cursor back to the end if it was
there.


I think it sounds like you want something like the following:

vnoremap gt esc`:exec 'norm '.visualmode().'`lt'cr
vnoremap gb esc`lt:exec 'norm '.visualmode().'`'cr

which gives you a Go to the Top and Go to the Bottom mapping within 
visual mode.


It can be a little funky in blockwise visual-mode, if your ' and ' 
points are top-right and bottom-left (rather than top-left and 
bottom-right), as the top will go to the top-right, not the top-left.  
I haven't figured out a good way to do this without considerably more 
code in the mapping (save the column of ' and then gvO to go back to 
visual-mode but in the other corner and then compare the columns to see 
which you want, perhaps needing to switch back...it's ugly).


However, it should work fine in character-wise and line-wise visual modes.

HTH,

-tim


I don't understand why this works.

There must be a difference between
`v`
and
:normal `v`

v defines a new visual area and overwrites the `,` markers.  Why
does ` after :normal move the cursor to the start of the
_previously_ selected visual area?

Thx,
Andy

--
kühl, @vim.org ist wieder zurück

EOF






___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: Go to start of visual selection

2007-02-04 Thread Andy Wokula

Tim Chase schrieb:

How can I move the cursor the start of the visual selection?
With the o command, yes.  But how can I make sure the cursor
is at the start while visual mode is on?  The ` motion
followed by gv sets the cursor back to the end if it was
there.


I think it sounds like you want something like the following:

vnoremap gt esc`:exec 'norm '.visualmode().'`lt'cr
vnoremap gb esc`lt:exec 'norm '.visualmode().'`'cr

which gives you a Go to the Top and Go to the Bottom mapping within 
visual mode.


It can be a little funky in blockwise visual-mode, if your ' and ' 
points are top-right and bottom-left (rather than top-left and 
bottom-right), as the top will go to the top-right, not the top-left.  
I haven't figured out a good way to do this without considerably more 
code in the mapping (save the column of ' and then gvO to go back to 
visual-mode but in the other corner and then compare the columns to see 
which you want, perhaps needing to switch back...it's ugly).


However, it should work fine in character-wise and line-wise visual modes.

HTH,

-tim


Works fine at least for character-wise visual mode, thanks! :-)
IMHO, this little basic feature should be included in Vim.

Regards,
Andy

--
EOF




___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Go to start of visual selection

2007-02-01 Thread Andy Wokula

How can I move the cursor the start of the visual selection?  With the
o command, yes.  But how can I make sure the cursor is at the start
while visual mode is on?  The ` motion followed by gv sets the 
cursor back to the end if it was there.


Thx, Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: change filenames before vim reads buffer

2007-01-25 Thread Andy Wokula

Tom Whittock schrieb:

Hi.

I'm running the vim under cygwin, and have set up my build process to
execute via :make. This is great, but the build process reports
filenames in DOS format, not the cygwin /cygdrive/* way. This means
that when a quickfix command runs, vim will be asked to open
C:\dev\test.cpp, when I already have /cygdrive/c/dev/test.cpp
open, and this causes issues for me.

Is there any way I can insert my own handler in between the quickfix
jump and buffer reading so that I can fix up the filename? Moreso,
could I do this in general so that if I gf to C:\dev\test.cpp, vim
will interpret that in the cygwin manner?

Thanks,
Tom.


:h quickfix-valid

[...]

| Filtering messages
|
| If you have a compiler that produces error messages that do not fit in
| the format string, you could write a program that translates the error
| messages into this format.  You can use this program with the :make
| command by changing the 'makeprg' option.  For example:
| :set mp=make\ \\\|\ error_filter
| The backslashes before the pipe character are required to avoid it to
| be recognized as a command separator.  The backslash before each space
| is required for the set command.


Just a try,

Andy

--
EOF


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: A doubt with syntax region

2007-01-25 Thread Andy Wokula

DervishD schrieb:

Hi all :))

I'm trying to fully understand the syntax commands, and when doing
tests a question popped up in my mind: let's say I have a region which
starts with something like \I\i*{ and ends with }. For example, the
example below will match:


strange{contents}


BUT, the below is valid for the filetype, too:


morestrange{content with words and {}, surprise!}


Of course, with something like this:

syntax region SomeRegion start=\I\i*{ skip={[^}]*} end=}

I'm able to highlight the example above, without having {} end the
region. The problem here comes when I want to highlight the part between
the braces in a different color. I've tried this, to (by the moment)
only highlight *braces* within those braces:

syntax region SomeRegion start=\I\i*{ skip={[^}]*} end=}
\ contains=Inner
syntax match Inner {[^}]*} contained

But this performs the following highlighting:

example{with some contents}
^^^

example{with another pair of braces {}}
^^^+++^

That is, the contained item is swallowing part of the start
match!. I thought that when the match for start was performed, the
matched test wasn't tried for any other match, including contained
items. Obviously, I was wrong (or I misunderstood the entire issue), and
I don't know if, just using regions, I can have a match like this:

example{{weird} and some mor{}e text}
^

that is, that the first opening brace is not swallowed by the
contained syntax item. As you can see, the contained item must be
allowed to start with {.

Thanks a lot in advance and sorry for the weird question O:)))

Raúl Núñez de Arenas Coronado



:h :syn-matchgroup

| In a start or end pattern that is highlighted with matchgroup the
| contained items of the region are not used.  This can be used to avoid

e.g.
syntax region SomeRegion matchgroup=SomeRegion start=\I\i*{ ...

HTH,
Andy

--
EOF


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: how to NOT save history

2007-01-16 Thread Andy Wokula

Luis A. Florit schrieb:

Pals,

How I avoid certain commands and/or substitutions NOT to be saved
into the history list? For example, I have a sequence of VIM commands
that executes on every email quote to properly format it, and I don't
want these to appear in the registries and history.

Thanks!

L.


One idea is:
- backup (i.e. write) the viminfo file (:help :wv)
- do some secret commands
- read the viminfo file back in (:help :rv), overwriting the history

In theory I thought this would work:
:echo public command
:wviminfo!
:echo secret command one
:echo secret command two
:rviminfo!

But it doesn't (because of my unpatched Vim7?), so I tried:
:set history?
  history=1000
:echo public command
:wviminfo!
:set history=0
:echo secret command one
:echo secret command two
:set history=1000
:rviminfo!

My 'viminfo' settings (just info :o):
:set viminfo?
  viminfo=!,'30,50,h,rA:,rB:
I think the only chars you should be aware of are ':' and '/' (not
present here).

HTH Andy


--
EOF


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: how to NOT save history

2007-01-16 Thread Andy Wokula

Luis A. Florit schrieb:

Pals,

How I avoid certain commands and/or substitutions NOT to be saved
into the history list? For example, I have a sequence of VIM commands
that executes on every email quote to properly format it, and I don't
want these to appear in the registries and history.

Thanks!

L.


Think I completely misunderstood you (because of the subject), in case
please forget my previous post.

Commands:
A  :SomeCommand  will not be added to the history, if you map it to a
normal mode key (including the cr), for example:
:map f2 :Command1cr:Command2barCommand3cr

Registers:
You could write data into variables to not touch registers.
You will need some knowledge about vim script.
:h eval

Search history:
The search history is always overwritten, although you can backup and
restore the last search pattern:
:let sav_search = @/
/some search/
:let @/ = sav_search
:unlet sav_searchno need within :function
...

Do you use filetype plugins?
...

Wonder if this has more to do with what you had in mind.

Andy

--
EOF




___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: C++ Syntax highlighting for Identifier, Statement

2007-01-14 Thread Andy Wokula

Matt England schrieb:
I'm trying to get function names, class names, objects, variables and 
similar things to appear as non-white text with 'syntax on'.


Had the same question after editing with Visual Studio.
This is difficult, I haven't seen that before in any syntax file.
I think there are no means to do that in an easy way.
The file (and included files) needs to be parsed to collect all the user 
defined names.  I think with some energy it should be possible, because 
syntax definitions can be added and removed at any time.


Hopefully some of the gurus will answer?

Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: enclosing a visual block with quotes

2007-01-14 Thread Andy Wokula

Bram Kuijper schrieb:

Hi,

I tried to use the following tip on enclosing a visual block with quotes 
in vim:
http://schlitt.info/applications/blog/index.php?/archives/331-Comfortable-PHP-editing-with-VIM-3.html 



Sometimes you want to include text you already typed text into braces 
or (more likely) into quotes. Using this feature you can simply mark the 
text (go into visual mode using v/CTRL-v/SHIFT-v/... in command 
mode) and type the char you want to wrap around the text (like ( for (), 
' for '',...) and it will be enclosed.


For me that doesn't seem to work. I do start visual mode, e.g. Ctrl-v 
on the beginning of a word, use e to block the whole word and then press 
any quoting character, like '


Then I press enter

Obviously, I get the following error message:
E78: Unknown mark

anybody a solution to easily enclose parts of text using visual mode?

cheers,
Bram



I guess it is a feature of that .vimrc provided on that web site (link 
is dead).  In Vim the feature you described is not included.


The unknown mark you mentioned is Enter, because 'Enter would be a 
motion command (also in visual mode) and there is no Enter mark 
defined in Vim.


I guess 2ndly the author has defined mappings like
:vmap ' c'c-r'esc
:vmap  cc-resc
:vmap ( c(c-r)esc

These ones may help you on the first run.  Hint: There is no need to 
press Enter afterwards.


Andy

--
EOF





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Undo bug

2007-01-06 Thread Andy Wokula

Think I found a bug in the undo-branches behaviour, which cuts
undo-states.  Try this out:

In a new buffer, insert `one' (or some other text), then in normal mode
type `g-g-u', now insert `two' and type `g-g-u' again (ignore quotes
`').  From now on it is not possible to get back the text states `one'
or `two' using `g-' and `g+'.

I know, in both cases `g-g-u' would not be very useful to type, but
sometimes it happens by accident.

Some more examples:
insert `one'
undo
insert `two'
type `g-g-g-u'
insert `three'
result: `g-' can reach `two', but not `one'

Or is this a feature?  But then what about:
insert `one'
undo
insert `two'
type `g-g-g-u'
(just like above, but without inserting `three')
result: even `two' cannot be reached (only redo gets it back)

In the following case everything seems ok:
insert `one'
insert `two'
undo
insert `three'
type `g-g-g-g-u'

In short:
- create a branch-off at the root level of the undo tree
- type `g-' until the message `Already at oldest change' occurs
- type `u'
result: damaged undo tree

`:undolist' may still show the branches, but `:u {N}', `g-', `g+' cannot
restore the text.

I'm still using an unpatched Vim7 binary for Win32 (`:ver' says
`compiled May 7 2006'), but searching the patches-README for `undo'
didn't give me a hint about fixes.

Andy


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: locked window

2006-10-19 Thread Andy Wokula

Brecht Machiels schrieb:

Hi,


You can clear the 'modifiable' option to disable unintended
modifications to a buffer.

   setlocal nomodifiable


Is is possible to prevent, for example, the project plugin from opening
another file (other than the current) in a window? The nomodifiable
option only applies to the buffer. The window should be locked to the
buffer instead.

Regards,
Brecht




:help :sandbox

may help (vim7 only I think).

Andy





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de


Re: combining two mapping into one

2006-10-08 Thread Andy Wokula
A.J.Mechelynck schrieb:
 Kamaraju Kusumanchi wrote:
 On Friday 06 October 2006 08:24, Andy Wokula wrote:
 Kamaraju Kusumanchi schrieb:
 I use two mappings for my Fortran (.f90) files

 map F5 Homev%zf
 map F6 HomezDv%zf

 The idea is to create folds for code blocks which are of the form

 subroutine some_name_here
statements_here
 end subroutine some_name_here

 Here F5 folds the subroutine block irrespective of whether there are
 any
 folds within it. F6 folds the subroutine block after deleting the
 existing folds.

 However, if there are no folds and if I press F6, I get an error saying
 that

 E490: No fold found

 Is it possible to combine these two maps into a single map such that
 1) If there are no existing folds, create a fold  (i.e. perform F5)
 2) If there are already some folds defined, then delete them and
 define a
 new fold (i.e. perform F6)

 Any ideas?

 thanks
 raju
 Some time ago I saw this:
 http://vim.sourceforge.net/tips/tip.php?tip_id=1330

 Andy

 Thanks for the pointer. I tried
 nnoremap F5 @=((foldclosed(line('.'))  0) ? 'Homev%zfjj' :
 'HomezDv%zfjj')CR

 but it did not work due to Home. Dont know how to escape it
 properly. Any ideas? For now I am using

 nnoremap F5 @=((foldclosed(line('.'))  0) ? '1\|v%zfjj' : '1\|
 zDv%zfjj')CR

 but would like to use Home instead of 1\| since that would make the
 map more readable.

 thanks
 raju

 
 To use the Home key in an expression (as here), use a double-quoted
 string and a backslash-escape: \Home
 
 See the last item under :help expr-quote.
 
 
 Best regards,
 Tony.

Seems to be theory in this case, a mapping like
:nn f7 @=\homecr

results in an error:
=\
E15: Invalid expression: \

Nevertheless
:let home = \home
:nn f7 @=homecr

works.  Same for both GVim 6.4 and GVim 7.0 (no latest patches) on Win32.

Looks like a bug?!

Andy



___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: combining two mapping into one

2006-10-06 Thread Andy Wokula
Kamaraju Kusumanchi schrieb:
 I use two mappings for my Fortran (.f90) files
 
 map F5 Homev%zf
 map F6 HomezDv%zf
 
 The idea is to create folds for code blocks which are of the form
 
 subroutine some_name_here
statements_here
 end subroutine some_name_here
 
 Here F5 folds the subroutine block irrespective of whether there are any 
 folds 
 within it. F6 folds the subroutine block after deleting the existing folds.
 
 However, if there are no folds and if I press F6, I get an error saying that
 
 E490: No fold found
 
 Is it possible to combine these two maps into a single map such that
 1) If there are no existing folds, create a fold  (i.e. perform F5)
 2) If there are already some folds defined, then delete them and define a new 
 fold (i.e. perform F6)
 
 Any ideas?
 
 thanks
 raju

Some time ago I saw this:
http://vim.sourceforge.net/tips/tip.php?tip_id=1330

Andy


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Mapping of keysequences...

2006-10-02 Thread Andy Wokula
Meino Christian Cramer schrieb:
  Thanks for all, Tony!!! :O)
 
 I think Bram should add
 
   :he Tony
 
 -support in vim which prints your email address...
 or may be it is not what you really want, isn't ir ;O)
 
 (just kidding)
 
 Keep hacking!
 mcc

Add it yourself

:e ~/.vim/doc/tony.txt
:i
*tony.txt*  Tony's mail address

*Tony* A.J.Mechelynck antoine(dot)mechelynck(at)skynet(dot)be

 vim:tw=78:ts=8:ft=help:norl:
.
:w
:helptags ~/.vim/doc
:he Tony

:-)

Andy





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: 
http://mail.yahoo.de


Re: glued Cursor trick anyone ?

2006-09-21 Thread Andy Wokula
Tim Chase schrieb:
 Generally, folks would get fired for writing stunts like the following,
 so read with caution...
 
 Archived here:
 http://permalink.gmane.org/gmane.editors.vim/38930
 
 you'll find these two lines from my post:
 
 nnoremap / :exec('cnoremap '.'cr '.'cr:exec(cunmap
 .cr)'.'cr:call HighlightCurrentSearch()'.'cr')cr/
 
 nnoremap ? :exec('cnoremap '.'cr '.'cr:exec(cunmap
 .cr)'.'cr:call HighlightCurrentSearch()'.'cr')cr?
 
 They are hideous monstrosities, that don't quite do all that I
 described in my previous post. The basic gist is that you want to
 remap the / and ? keys so that when you press them, you
 create a cnoremap mapping that maps the cr (and, unimplemented
 in this example, also esc and c-c) to perform the action
 cunmap the cr mapping, and then do my custom action.
 
 In this case, the custom action was to call the
 HighlightCurrentSearch() function defined in the post, as desired
 by the OP.  In your case, you'd want to tweak it to do a zz
 instead.
 
 Caveat Vimtor...if it breaks, you get to keep both pieces.  If it
 kicks your dog, drinks your beer, steals your girlfriend, wrecks your
 pickup-truck, or any other tragedy found in country-music, I take no
 responsibility...it's an ugly hack.  YMMV.
 
 -tim

A version using lt:

:nnoremap / :cno ltcr ltcrzz:cun ltltcrltcrcr/

Hints:
The mapping defined within the above RHS is
:cno cr crzz:cun ltcrcr

And there is one more level of nesting
:cun cr


Andy


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Two problems

2006-09-14 Thread Andy Wokula
Pete Johns schrieb:
  For all lines longer than 72 characters, reformat the
  paragraph from that line..
 1,$g/.\{73,}/normal v}gq

or just

:set tw=72   if set otherwise
:g/./normal gqq

Andy





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: 
http://mail.yahoo.de


Re: Deleting question

2006-09-13 Thread Andy Wokula
Nikolaos A. Patsopoulos schrieb:
 Hi,
 
 I'm trying to delete several lines from the beginning of file till the
 appearance of a specific pattern, without deleting the pattern. I have
 used the following command:
 
 :1,/Citations: /d/e-10
 
 but the offset doesn't work.
 
 Thanks in advance,
 
 Nikos

why not

:1;/Citations: /-1d

of course, this is linewise, what's before Citations:  in the same
line is not deleted.

Andy




___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Deleting question

2006-09-13 Thread Andy Wokula
 why not
 
 :1;/Citations: /-1d
 
 of course, this is linewise, what's before Citations:  in the same
 line is not deleted.
 
 Andy

oops, just overlooked Yakov's answer, sorry.

Andy


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Re: Smarter Indent (an odd problem)

2006-09-06 Thread Andy Wokula
  Let me take this opportunity to try once again to drum up support
 for an idea that I have proposed before.  IMO it is too restrictive to
 make options (such as syntax highlighting, 'textwidth', and
 indent-related options) apply to a whole file.  There should be a
 convenient, consistent way to tell vim to treat different sections of a
 file as having different file types.  Examples:
 
 * code snippets in an e-mail
 * PHP in an HTML file (or vice-versa)
 * perl/python/ruby inside a vim script
 * comments, text, and math inside LaTeX/plain TeX/conTeXt
 
   --Benji Fisher

Something like Textmate's scope selectors?
http://macromates.com/textmate/manual/scope_selectors

I'm not a Mac user, just read about it.

Andy





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: 
http://mail.yahoo.de


Re: Remapping - how to get the count

2006-07-12 Thread Andy Wokula
Yakov Lerner schrieb:
 On 7/8/06, Andy Wokula [EMAIL PROTECTED] wrote:
 I want to remap Ctrl-A (normal mode) to do something similar with other
 data, e.g.

 :nmap c-a ciwc-r=IncRoman(@-)cresc

 Now if a count is provided this will mess up the text, e.g.
 10c-a does 10ciw...

 What is a good way to catch the count and make it available to the
 function call?
 
 :help v:count
 
 Yakov

Vim überrascht einen doch immer wieder, ich hab nicht mal versucht, nach
count zu suchen ...

Thanks for the tip, now I'm quite happy with

:nmap silent c-a :c-ulet c=v:count1crciwc-r=IncRoman(@-,c)cresc
:nmap silent c-x :c-ulet c=v:count1crciwc-r=DecRoman(@-,c)cresc

The only thing I don't like is the use of a variable.

Thanks for the other replies as well
(still have to look at the solution with count).

Andy





___ 
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: 
http://mail.yahoo.de


Re: language menu

2006-07-12 Thread Andy Wokula
Cesar Romani schrieb:
 Normally the language of my vim's menu is Italian.
 How can I change it to English?
 Many thanks in advance,
 
 Cesar

:set langmenu=none

works for me.  Put it early in your .vimrc,

:help 'langmenu'

says: This option must be set before loading menus, switching on
filetype detection or syntax highlighting.

Andy


___ 
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de


Remapping - how to get the count

2006-07-08 Thread Andy Wokula
I want to remap Ctrl-A (normal mode) to do something similar with other
data, e.g.

:nmap c-a ciwc-r=IncRoman(@-)cresc

Now if a count is provided this will mess up the text, e.g.
10c-a does 10ciw...

What is a good way to catch the count and make it available to the
function call?

TIA Andy





___ 
Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: 
http://mail.yahoo.de