简体   繁体   中英

Reference selection in Vim command mode to pass on to terminal

Is there something like % (that represents the whole buffer in Vim command line ) for the current selection, so that I can do something like: :# sort (Imagine # represents the selection).

EDIT:

Sorry, I missed to mention that I am requesting for a way to operate on block selections not on ordinary selections that can be operated using ranges '<,'> .

Yes. Example:

:'<,'>!sort
  • The range :'<,'> represents the visually selected lines.
  • :* is shorthand for :'<,'>
  • If you hit : while in visual mode it will start the command with '<,'>

For more help see:

:h '<
:h v_:
:h range

You are probably looking for the marks '< and '> :

:'<,'>sort

If you just select a few lines and hit : to enter the command line these marks should appear automatically.

As others have already remarked, the visual selection is represented by the '<,'> range (there's also the :* short form). However, as all ranges, this always covers entire lines , even if the selection is only characters or a block.

Most Ex commands (like :sort ) only operate on full lines, for :substitute , you can limit the effects to the visual selection by including the special \\%V atom in the search pattern, cp. :help /\\%V .

The idea to make Ex commands handle blockwise selections is old, but unlikely to be tackled any time soon.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM