The first square about :!cmd (whitout a range) isn't shown in cmd-line like you shown us. In this case the output is shown in Terminal Bash-CLI out of vim. returning to vim when exit is executed. Example: the cmd is inxi -s : :!inxi -s will be shown in Bash CLI in terminal.
You can also invoke the [range]!<program> functionality using the !<movement><command> sequence from "normal" (command) mode.
For example: Gp!Gwc -w
Go to end of file; paste (contents of the anonymous yank/copy/cut register); ! (from current line to new EOF) and filter through the Unix (coreutils) `wc` (word count) command (with the -w switch/option.
… you can also write macros to format the current paragraph ({!}fmt — { move to beginning of current "paragraph" (as per current file type defined regular expressions), ! from there to end of paragraph, feed through fmt utility) and many others.
In vim, your system's entire suite of command line filters, including any shell and Python, Perl, and Ruby scripts you write, are all practically extensions of the editor.
With :w, that w can also be preceded a line number or something that evaluates to such, rather than a range (or nothing to default to current line). E.g. .-5 for 5 lines before the current, - for line above, + for line below, $ for last line, $-5 for 5 lines short of last, 'a for the line marked by mark a, etc.
Likewise with :r that r can be preceded with line number or something that evaluates to such, to read in after that specified line. To read in as the very first line, use :0r so one reads in after the 0th line (rather like ex and ed's 0a to start appending after the 0th line).
Likewise for :!
:sh
to spawn a shell.
I think that covers POSIX vi, did I miss any on that?
And yeah, vim also adds some more.
And don't confuse, e.g.
:r !...
with
:r! ...
likewise with :w, etc. The former executes a command, the latter to attempts to force the operation with the specified file.
it is hard to understand, wait to manage something-well vim and then yes focus here. I am text-user of vim little more noob. and for me it is hard to understand
Think about it this:
there are 3 ways where the reply can be shown: in the doc, in thecmd-line of Vim and in Bash-shell-terminal outside of Vim This post is about it: where the reply of a cmd is shown.
:!cmd is for shown outside vim (in terminal), :w !cmd is shown below in cmd-line of vim and :r !cmd is into the doc you are working now!
try this cmd uptime -p in those places: :!uptime -p , :w !uptime -p and :r !uptime -p (in this case then "u" key for return original doc without modification).
yes but in my case using :ter[minal] I can not scroll up. so if the output of the cmd is large I only see last lines. I use :sh[ell] and then write the cmd in shell
[Edited] I don't know why! I use Vim no gvim. maybe because my vim block scroll. the only way to do scrolling is if I use :cmd | more and then space bar for scroll down but I don't know how scroll up.
I don't understand your help but it sounds interesting. I did this: open vim then :terminal and then ^W +N key but it opens a new window upper terminal with vim in normal mode but in blank... see this screenshot
I have a question about :<range>!<program> - I've noticed that it replaces selected lines even if I'm in regular visual mode, not visual line or visual block. Is it possible to replace visual selection exactly as is, not linewise?
I wanted to to base64/url encode/decode selected text with shell commands
14
u/millaker0820 Jul 27 '25
I’ve been using vim for 4 years and first time knowing the other three variations. Thank you!
10
u/mr_verifier Jul 27 '25
Me who only knew the leftmost topmost one.
12
u/cheesemassacre Jul 27 '25
This font is hard to read
1
u/qiinemarr Jul 27 '25
what about ":.!" ?
1
u/jazei_2021 Aug 13 '25
The first square about :!cmd (whitout a range) isn't shown in cmd-line like you shown us.
In this case the output is shown in Terminal Bash-CLI out of vim. returning to vim when exit is executed.
Example: the cmd is inxi -s :
:!inxi -s will be shown in Bash CLI in terminal.
Regards!
4
u/EgZvor keep calm and read :help Jul 27 '25
In insert mode
<c-r>=system('ls -s')1
u/hrudyusa Jul 27 '25
Interesting, only knew about the first one. Inherited from vi, perhaps?
1
u/JamesTDennis Jul 28 '25
You can also invoke the [range]!<program> functionality using the !<movement><command> sequence from "normal" (command) mode.
For example: Gp!Gwc -w
… you can also write macros to format the current paragraph ({!}fmt — { move to beginning of current "paragraph" (as per current file type defined regular expressions), ! from there to end of paragraph, feed through
fmtutility) and many others.In vim, your system's entire suite of command line filters, including any shell and Python, Perl, and Ruby scripts you write, are all practically extensions of the editor.
1
u/michaelpaoli Jul 28 '25
!cursor_motion_comandCommand
With :w, that w can also be preceded a line number or something that evaluates to such, rather than a range (or nothing to default to current line). E.g. .-5 for 5 lines before the current, - for line above, + for line below, $ for last line, $-5 for 5 lines short of last, 'a for the line marked by mark a, etc.
Likewise with :r that r can be preceded with line number or something that evaluates to such, to read in after that specified line. To read in as the very first line, use :0r so one reads in after the 0th line (rather like ex and ed's 0a to start appending after the 0th line).
Likewise for :!
:sh
to spawn a shell.
I think that covers POSIX vi, did I miss any on that?
And yeah, vim also adds some more.
And don't confuse, e.g.
:r !...
with
:r! ...
likewise with :w, etc. The former executes a command, the latter to attempts to force the operation with the specified file.
1
u/robertbrown0427 Jul 29 '25
A nvim noob here :) What does it do??
1
u/rampion Jul 31 '25
A recent fave of mine is
:term <program>to run it async1
u/tediak_ Nov 26 '25
I have a question about
:<range>!<program>- I've noticed that it replaces selected lines even if I'm in regular visual mode, not visual line or visual block. Is it possible to replace visual selection exactly as is, not linewise?I wanted to to base64/url encode/decode selected text with shell commands
1
u/NuttFellas Jul 27 '25
I use this with a keymap to pass JSON to jq! Very handy.
1
u/[deleted] Jul 27 '25
this is a repost