Tim Chase | 1 Apr 2011 02:11

Re: Finding the correct map

On 03/31/2011 05:01 PM, carlosvillu wrote:
> I came from Textmate and i try to created a map that i was so
> useful for me. When i edit a file in insert mode, i want can
> press <shift>Left /<shift>Rigth for select caracter by
> caracter and <shift><cmd>Left<shift><cmd>Right to select word
> by word. Really I tried, but I don´t make work fine.

Assuming your vim can see that key-sequence (see note below), you 
can use

  :nnoremap <s-left> v<left>
  :nnoremap <s-right> v<right>
  :vnoremap <s-left> <left>
  :vnoremap <s-right> <right>

which should implement the behavior you expect.

-tim

NOTE:  to see if your Vim distinguishes between them, in either 
insert-mode or command-line (":"-prompt) mode, you can type 
control-V followed by shift-left.  Then try the same with 
control-V followed by plain-left and see if Vim sees the same 
key-sequence.  Alternatively in insert-mode, you can prefix the 
key-to-check with control-K to see the vim-key-code representation.

   :help i_CTRL-V
   :help i_CTRL-K

--

-- 
(Continue reading)

Alessandro Antonello | 1 Apr 2011 07:35
Picon

Regular Expression Help

Hi, all.

I have a problem building a regular expression for fields in a SQL UPDATE
statement. The SET clause has the format as follows:

field1 = 'value of field1', field2 = 'field\' 2 value'

I have built a regular expression that can split the name of fields from its
values. But when a value has an escaped single-quote the regular expression
fails. I know that it fails because I am using the expression [^'] in between
the parenthesis. But how to fix this?

This is the regular expression I am using:

/(\w+)\s*=\s*(('[^']*'\s*,)|(\d+\s*,))\s*/i

Could someone help me with that?

Alessandro Antonello

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Tony Mechelynck | 1 Apr 2011 08:17
Picon
Gravatar

Re: Regular Expression Help

On 01/04/11 07:35, Alessandro Antonello wrote:
> Hi, all.
>
> I have a problem building a regular expression for fields in a SQL UPDATE
> statement. The SET clause has the format as follows:
>
> field1 = 'value of field1', field2 = 'field\' 2 value'
>
> I have built a regular expression that can split the name of fields from its
> values. But when a value has an escaped single-quote the regular expression
> fails. I know that it fails because I am using the expression [^'] in between
> the parenthesis. But how to fix this?
>
> This is the regular expression I am using:
>
> /(\w+)\s*=\s*(('[^']*'\s*,)|(\d+\s*,))\s*/i
>
> Could someone help me with that?
>
> Alessandro Antonello
>

I think you could use non-greedy matching i.e. .\{-} and end at (or 
maybe just before) a single quote not preceded by a backslash (maybe end 
the pattern with [^\\]' if there must be at least one character between 
the quotes).

See
	:help non-greedy
	:help /[]
(Continue reading)

wei gao | 1 Apr 2011 08:35
Picon

why remap <C-;> is not working

Hi, All
 
I want to add ";" to the end of line when coding. So, I add the following map in vimrc. however, it's not working for me (if I change to <C-e>, it's OK). Anybody know why? <C-;> is mapped to a special command already?
 
:inoremap <C-;> <C-o>A;

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
howard Schwartz | 1 Apr 2011 08:45
Picon

What is supposed to happen if there is an error in a vim script?


> However none of you answered,
  > anywhere in the available documentation?
  > Not just mentioned in passing by an example!

  > Where are the rules for this detailed?

Actually the documentation does describe, in detail, the rules for handling 
errors, exceptions, and interrupts -- if the author of a script encloses it in 
a ``try'' block. You can find these explanations in the document eval.txt in 
Section 8 ``Exception Handling''. You can also use help commands to locate 
descriptionfor the ``catch'' ``throw'' and ``finally'' commands within 
``try'' and ``endtry'' blocks.

I had to deal with this recently myself when I wrote a few scripts,.
Frankly, I found these rules unnecessarily complex and, well, arcane compared 
to error handling in other script languages (e.g., unix shells).

Vim provides a set of rules for the Author of a script to deal with errors, 
should he or she choose to do so. However, if the author does not use the 
``try'' mechanism - I fear errors are handled -well - however the developers 
happened to handle each particular error. Generally, error messages are 
displayed and some action may or may not be taken.

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Jürgen Krämer | 1 Apr 2011 10:08

Re: Regular Expression Help


Hi,

Alessandro Antonello wrote:
> 
> I have a problem building a regular expression for fields in a SQL UPDATE
> statement. The SET clause has the format as follows:
> 
> field1 = 'value of field1', field2 = 'field\' 2 value'
> 
> I have built a regular expression that can split the name of fields from its
> values. But when a value has an escaped single-quote the regular expression
> fails. I know that it fails because I am using the expression [^'] in between
> the parenthesis. But how to fix this?
> 
> This is the regular expression I am using:
> 
> /(\w+)\s*=\s*(('[^']*'\s*,)|(\d+\s*,))\s*/i
> 
> Could someone help me with that?

there are some problems with your regular expression: first, Vim needs a
lot of backslashes where Perl or other regexp variants do not. You can
fix this by putting \v inside your regexp (see ":help /\v"). As a
consequence you now have to prefix the equal sign with a backslash:

  /\v(\w+)\s*\=\s*(('[^']*'\s*,)|(\d+\s*,))\s*/i

Now you want to match single quoted strings which might include a
backlash-escaped single quote. That means "'[^']'*" is not enough;
inside your string everything but single quotes should be allowed, or
alternative a backslash-escaped single quote. This leads us to
"'([^']|\\')*'" for a string:

  /\v(\w+)\s*\=\s*(('([^']|\\')*'\s*,)|(\d+\s*,))\s*/i

This still won't match you example, because "\s*," is expected after
every string or number. First lets move them out of the parentheses:

  /\v(\w+)\s*\=\s*(('([^']|\\')*')|(\d+))\s*,\s*/i

Now you have to decide: do you want this regular expression to match a
single field or a list of fields. A single field is (almost) easy: just
strip "\s*,\s*" from the end:

  /\v(\w+)\s*\=\s*(('([^']|\\')*')|(\d+))/i

Both fields in your example get matched now, but the second match is too
short. This is due to the way alternatives are tested. You can fix this
by swapping "[^']" and "\\'":

  /\v(\w+)\s*\=\s*(('(\\'|[^'])*')|(\d+))/i

This correctly matches both fields. Before we continue lets get rid of
some superfluous parentheses. You don't need them around the
alternatives as long as the whole alternation is wrapped with
parentheses:

  /\v(\w+)\s*\=\s*('(\\'|[^'])*'|\d+)/i

If you want to match a list of fields you must consider that there might
be no trailing comma after the last field of the list or -- expressed in
a slightly different way -- that every field has a leading comma except
the first one. For a list only one field is needed; more fields are
optional and separated from their predecessors with (optional) whitespace,
a comma, and (again optional) whitespace:

  /\v(\w+)\s*\=\s*('(\\'|[^'])*'|\d+)(\s*,\s*\v(\w+)\s*\=\s*('(\\'|[^'])*'|\d+))*

That's it.

Regards,
Jürgen

-- 
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us.     (Calvin)

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

EdwardXu | 1 Apr 2011 10:47
Picon

bracket indent question

Hi, guys,


I'm using xptemplate to writing C code, i must deal with following code snippet:
int foo(int a)
{
     //bla bla
}

When i finished the first line of that and press enter, VIM will shift cursor according to the value of shiftwidth like
int foo(int a)
   [cursor here]
Then i entered {, VIM will complete bracket for me like:
int foo(int a)
   { [cursor here ] }  

I don't want to use this kind of indent, i just want it be :
int foo(int a)
{[cursor here]} 


but i don't know how to configure it or if there is any other solution for this.


--
Thanks & Best Regards
Edward

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Paul | 1 Apr 2011 12:09
Favicon

Re: How to use color to search

Alternatively, the SyntaxMotion script: http://www.vim.org/scripts/script.php?script_id=2965

-- 

.

--

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Terence Monteiro | 1 Apr 2011 08:29
Picon

Re: Regular Expression Help

On Fri, Apr 1, 2011 at 11:53 AM, Terence Monteiro wrote:
/\(\w\+\)\s*=\s*\(\(\\'\|[^']\)*\)'

You'll need a ' after the \s*. Depending on whether you want to capture the single quotes:

\(\w\+\)\s*=\s*'\(\\'\|[^']\)*'

Regards, Terence.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Terence Monteiro | 1 Apr 2011 08:23
Picon

Re: Regular Expression Help

Alessandro,

On Fri, Apr 1, 2011 at 11:05 AM, Alessandro Antonello <antonello.ale <at> gmail.com> wrote:
Hi, all.

I have a problem building a regular expression for fields in a SQL UPDATE
statement. The SET clause has the format as follows:

field1 = 'value of field1', field2 = 'field\' 2 value'

I have built a regular expression that can split the name of fields from its
values. But when a value has an escaped single-quote the regular expression
fails...

This should work:

/\(\w\+\)\s*=\s*\(\(\\'\|[^']\)*\)'

1. You need to escape the +, (, ), | metacharacters
2. The value part is 0 or more \' or [^'] sequences
 
Regards, Terence.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Gmane