Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6173089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:30:25+00:00 2026-05-23T23:30:25+00:00

A frequently used feature of Vim for me is filtering a file (or a

  • 0

A frequently used feature of Vim for me is filtering a file (or a selection of text) through an external command and replace the selection with the result, e.g.:

:'<,>'!sort

so

c
b
a

will be sorted and will result in

a
b
c

It’s also possible to replace the current line with the return value of an external command, e.g.:

:,!ls | wc -l

will insert the number of files in the current directory (in my case e.g.:)

41

But is there a way to pass the string to a command for the shell?

As an example, this might be the content of my visual selection:

line_x
line_y
line_z

I need to execute some shell command and take each of the selected lines as one shell script parameter, e.g.:

my_bash_command line_x -c -e -f
my_bash_command line_y -c -e -f
my_bash_command line_z -c -e -f

What is the best way to do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:30:26+00:00Added an answer on May 23, 2026 at 11:30 pm

    I suggest you use xargs -L1

    Example:

    :%!xargs -L1 wc -l
    

    Basically xargs [cmd] will run the following [cmd] with multiple parameters from multiple lines. But with the -L1 argument the [cmd] will be executed command for each line.

    If you need to supply a certain order to the arguments for your command you can use xargs‘s -I option to supply a pattern to be replaced by the argument list.

    Example:

    :%!xargs -L1 -I {} rake {} --trace
    

    If you feel very adventurous you can just execute the code directly like so:

    :%!bash
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like a file of the 200-1000 or so most frequently used words in
I frequently use the Remove and sort usings feature of VS/PowerCommands - in fact,
I have stock market application which will be frequently used by millions of members
I have a table with 16 columns. It will be most frequently used table
Morning all I have frequently used the old <asp:Label ID=lblWas runat=server Text='<%# XPath(FACEVALUE) %>'></asp:Label>
I wrote a simple batch file to run Frequently Used websites based on a
Could you share your frequently used tricks to search the web for programming related
I've got a list of frequently used hex colors that I'd like to list
I'm thinking of wrapping frequently used Cocoa object selectors with my own code to
I use thejit treemap to display first 50 most frequently used words from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.