Loading ...
Sorry, an error occurred while loading the content.
 

Re: using !sort in windows commandline: passing special characters

Expand Messages
  • Tim Chase
    ... This sounds like cmd.exe is being used for your shell processing of your command, rather than some other (bash?) shell. Within vim, what is the result of
    Message 1 of 4 , Jul 21, 2013
      On 2013-07-21 11:13, rameo wrote:
      > I use cygwin on my windows system to use unix commands from vim
      > commandline.
      >
      > This is written in my text file:
      > Adam|12345
      > Bob|34567
      > Joe|56789
      > Sam|45678
      > Wendy|23456
      >
      > When I use:
      >
      > :%!sort -k2n -t'|'
      >
      > it gives an error:
      > ''' is not recognized as an internal or external command, operable
      > program or batch file.

      This sounds like cmd.exe is being used for your shell processing of
      your command, rather than some other (bash?) shell. Within vim, what
      is the result of

      :set shell?

      I'm presuming it's something like "C:\...\cmd.exe" rather than
      "C:\...\bash.exe" (or some such cygwin shell).

      As directed at ":help 'shell'", you might also want to investigate
      your settings for 'shelltype', 'shellpipe', 'shellslash'
      'shellredir', 'shellquote', 'shellxquote' and 'shellcmdflag' to
      figure out what they're set to. Including those values in a reply
      may help track down further issues if pointing 'shell' at a *nixy
      shell rather than a Win32 shell.

      If it's cmd.exe, you might try setting the value of 'shell' to the
      path where you'll find your preferred *nixy shell as installed by
      cygwin, and re-test (and providing the results here if it doesn't
      work for you).

      > Same problem when I use '>' and '<' as separator.
      > Escaping doesn't resolve my problem.
      > I don't have problems with other separators as ';', ')', '\\', '='
      > and many others.

      I suspect this is a similar issue, and that you might have trouble
      with "&" as a separator depending on where you put it in your
      command-line.

      > Is it possible to use regex in the sort command. No info is written
      > in the manual and it doesn't work in my vim.

      To the external GNU/cygwin sort that you're calling? I don't believe
      so. That said, vim has had a built-in ":sort" command since at least
      v7.0 (possibly late 6.x series builds too) which *does* support
      sorting on a regexp, which you can read about at

      :help :sort

      (you can skim down to the section on /pattern/ if that's your primary
      concern)

      -tim












      --
      --
      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

      ---
      You received this message because you are subscribed to the Google Groups "vim_use" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • Tim Chase
      [copying the list, as your reply came directly to me. You may want to check your reply before sending] ... Someone with a Win32+cygwin environment might be
      Message 2 of 4 , Jul 21, 2013
        [copying the list, as your reply came directly to me. You may want
        to check your reply before sending]

        On 2013-07-21 22:29, Raimond Willemsen wrote:
        > Thank you very much for your reply Tim.
        >
        > > This sounds like cmd.exe is being used for your shell processing
        > > of your command, rather than some other (bash?) shell. Within
        > > vim, what is the result of
        > >
        > > :set shell?
        > >
        > > I'm presuming it's something like "C:\...\cmd.exe" rather than
        > > "C:\...\bash.exe" (or some such cygwin shell).
        >
        > Yes you're right
        > shell=cmd.exe
        > >
        > > As directed at ":help 'shell'", you might also want to investigate
        > > your settings for 'shelltype', 'shellpipe', 'shellslash'
        > > 'shellredir', 'shellquote', 'shellxquote' and 'shellcmdflag' to
        > > figure out what they're set to. Including those values in a reply
        > > may help track down further issues if pointing 'shell' at a *nixy
        > > shell rather than a Win32 shell.
        >
        > shelltype: option not supported
        > shellpipe=>%s 2>&1
        > noshellslash
        > shellredir=>%s 2>&1
        > shellquote=
        > shellxquote=
        > shellcmdflag=/c

        Someone with a Win32+cygwin environment might be able to step in here
        and compare their settings with yours.

        It might also help to know whether you're running vim-for-Windows
        (the "Windows" version of vim) or a vim built to be cygwin aware. I
        seem to recall that there were some differences in them.


        > > If it's cmd.exe, you might try setting the value of 'shell' to the
        > > path where you'll find your preferred *nixy shell as installed by
        > > cygwin, and re-test (and providing the results here if it doesn't
        > > work for you).
        >
        > The windows shell is working very well as intermetter to the bash
        > shell, just these pipes and quotes problems.
        > I noted much more problems when I define the bash shell as shell in
        > vim.

        I've found that cmd.exe's parameter-quoting and piping are somewhat
        less predictable when compared to *nixy shells


        > I use unix sort command because I've found it much more flexible as
        > the vim sort command.
        > p.e. to sort by column(nr) 5 and if there are equals sort by
        > column(nr) 12, isn't possible (i.m.o) with vim sort command.
        > I use it also to sort by real columns (and define a separator to
        > number columns), like the one in my example.

        since you have the full expressive power of Vim regexps at your
        disposal with the internal sort, your example could be done with
        either of

        :%sort /|/
        :%sort n /|/

        (depending on whether you wanted numeric sorting or
        ASCII/lexicographical sort order)

        For subsequent columns it gets a little messier, but you can do it.
        For 2 preceding columns (i.e., sorting on the 3rd column), you can do

        :%sort /^\([^|;:]*[|;:]\)\{2}/

        to allow for any of a pipe, colon, or semi-colon as delimiters.

        All the basics that you can do with GNU sort should be pretty doable
        with Vim's internal sort, except perhaps some of the more edge-case
        sort-orders (such as --month-sort, --human-numeric-sort and
        --version-sort). I don't use those very often and far more
        frequently have need to sort by some regexp like vim provides.

        -tim











        --
        --
        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

        ---
        You received this message because you are subscribed to the Google Groups "vim_use" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
      • rameo
        ... Thank you very much Tim. Sorry that my reply came to you and not to the list. Thanks also for your regex. ... Hope that someone will answer also to the
        Message 3 of 4 , Jul 22, 2013
          On Monday, July 22, 2013 4:08:28 AM UTC+2, Tim Chase wrote:
          > [copying the list, as your reply came directly to me. You may want
          >
          > to check your reply before sending]
          >
          >
          >
          > On 2013-07-21 22:29, wrote:
          >
          > > Thank you very much for your reply Tim.
          >
          > >
          >
          > > > This sounds like cmd.exe is being used for your shell processing
          >
          > > > of your command, rather than some other (bash?) shell. Within
          >
          > > > vim, what is the result of
          >
          > > >
          >
          > > > :set shell?
          >
          > > >
          >
          > > > I'm presuming it's something like "C:\...\cmd.exe" rather than
          >
          > > > "C:\...\bash.exe" (or some such cygwin shell).
          >
          > >
          >
          > > Yes you're right
          >
          > > shell=cmd.exe
          >
          > > >
          >
          > > > As directed at ":help 'shell'", you might also want to investigate
          >
          > > > your settings for 'shelltype', 'shellpipe', 'shellslash'
          >
          > > > 'shellredir', 'shellquote', 'shellxquote' and 'shellcmdflag' to
          >
          > > > figure out what they're set to. Including those values in a reply
          >
          > > > may help track down further issues if pointing 'shell' at a *nixy
          >
          > > > shell rather than a Win32 shell.
          >
          > >
          >
          > > shelltype: option not supported
          >
          > > shellpipe=>%s 2>&1
          >
          > > noshellslash
          >
          > > shellredir=>%s 2>&1
          >
          > > shellquote=
          >
          > > shellxquote=
          >
          > > shellcmdflag=/c
          >
          >
          >
          > Someone with a Win32+cygwin environment might be able to step in here
          >
          > and compare their settings with yours.
          >
          >
          >
          > It might also help to know whether you're running vim-for-Windows
          >
          > (the "Windows" version of vim) or a vim built to be cygwin aware. I
          >
          > seem to recall that there were some differences in them.
          >
          >
          >
          >
          >
          > > > If it's cmd.exe, you might try setting the value of 'shell' to the
          >
          > > > path where you'll find your preferred *nixy shell as installed by
          >
          > > > cygwin, and re-test (and providing the results here if it doesn't
          >
          > > > work for you).
          >
          > >
          >
          > > The windows shell is working very well as intermetter to the bash
          >
          > > shell, just these pipes and quotes problems.
          >
          > > I noted much more problems when I define the bash shell as shell in
          >
          > > vim.
          >
          >
          >
          > I've found that cmd.exe's parameter-quoting and piping are somewhat
          >
          > less predictable when compared to *nixy shells
          >
          >
          >
          >
          >
          > > I use unix sort command because I've found it much more flexible as
          >
          > > the vim sort command.
          >
          > > p.e. to sort by column(nr) 5 and if there are equals sort by
          >
          > > column(nr) 12, isn't possible (i.m.o) with vim sort command.
          >
          > > I use it also to sort by real columns (and define a separator to
          >
          > > number columns), like the one in my example.
          >
          >
          >
          > since you have the full expressive power of Vim regexps at your
          >
          > disposal with the internal sort, your example could be done with
          >
          > either of
          >
          >
          >
          > :%sort /|/
          >
          > :%sort n /|/
          >
          >
          >
          > (depending on whether you wanted numeric sorting or
          >
          > ASCII/lexicographical sort order)
          >
          >
          >
          > For subsequent columns it gets a little messier, but you can do it.
          >
          > For 2 preceding columns (i.e., sorting on the 3rd column), you can do
          >
          >
          >
          > :%sort /^\([^|;:]*[|;:]\)\{2}/
          >
          >
          >
          > to allow for any of a pipe, colon, or semi-colon as delimiters.
          >
          >
          >
          > All the basics that you can do with GNU sort should be pretty doable
          >
          > with Vim's internal sort, except perhaps some of the more edge-case
          >
          > sort-orders (such as --month-sort, --human-numeric-sort and
          >
          > --version-sort). I don't use those very often and far more
          >
          > frequently have need to sort by some regexp like vim provides.
          >
          >
          >
          > -tim

          Thank you very much Tim.
          Sorry that my reply came to you and not to the list.

          Thanks also for your regex.
          This one is maybe even easier:

          :%sort! n /^\(.\{-}\zs[|;:]\)\{'.columnnr.'}/

          Hope that someone will answer also to the shell settings.
          (btw I use the vim windows version (not the cygwin vi version).

          Sure I will use the vim sort command a bit more (and have to study it a bit more)

          I still use the unix sort command to sort single columns (p.e.\\%2v)
          P.e. to sort by column 4 and if there are equals sort by column 8.
          This is very easy to do with the unix sort command, it seems to me much more difficult with the vim sort command.

          However, thanks so far.
          Rameo

          --
          --
          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

          ---
          You received this message because you are subscribed to the Google Groups "vim_use" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        Your message has been successfully submitted and would be delivered to recipients shortly.