If you press !! in normal mode, you will notice the vim command-line turn into :.! and wait for additional input:
The . means "current line"
The ! means "execute external program"
Putting both of these things together means the current line in the buffer is piped to an external program and the output is piped back/written into the current line in the buffer.
You can also press !<motion> in normal mode, like !ip, which will be translated to :.,.+n! (where n is the number of lines in your paragraph; if you have 3 lines in your paragraph, it will be :.,.+3!).
This is a more robust version of :'<,'>!.
This is also useful for when you want to execute the current line in an external program.
To put it all together, given a shell script like this:
#!/bin/bash# 1. get the current user# 3. print date# 2. list fileswhoami
ls
date
Place the cursor on line 3, press !ip, type sort, hit enter. This will sort the comments to be in correct order
Place cursor on line 7, press !!, type sh, hit enter. This will execute whoami and write the output back into the buffer.
Place cursor on line 9, press !ip, type sh, hit enter. This will execute both ls and date in external shell and write the output back into the buffer.
So far I've only used the visual mode instead of motions for filters, but depending on the situation this might be the easier thing to do. Thanks for mentioning it!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
There is also
:h filter.If you press
!!in normal mode, you will notice the vim command-line turn into:.!and wait for additional input:.means "current line"!means "execute external program"Putting both of these things together means the current line in the buffer is piped to an external program and the output is piped back/written into the current line in the buffer.
You can also press
!<motion>in normal mode, like!ip, which will be translated to:.,.+n!(wherenis the number of lines in your paragraph; if you have 3 lines in your paragraph, it will be:.,.+3!).This is a more robust version of
:'<,'>!.This is also useful for when you want to execute the current line in an external program.
To put it all together, given a shell script like this:
!ip, typesort, hit enter. This will sort the comments to be in correct order!!, typesh, hit enter. This will executewhoamiand write the output back into the buffer.!ip, typesh, hit enter. This will execute bothlsanddatein external shell and write the output back into the buffer.So far I've only used the visual mode instead of motions for filters, but depending on the situation this might be the easier thing to do. Thanks for mentioning it!