我的用户定义了一个命令 .vimrc
command! RemoveOutput :'<,'> ! grep -v 'OUT'
Run Code Online (Sandbox Code Playgroud)
但是,只有在之前选择并再次取消选择时,这显然适用于视觉选择.相反,如果没有这样的选择,我想将它应用于当前的视觉选择或整个文件.我怎么做到这一点?请注意,我知道我不需要在这里使用grep.请将其视为更复杂的shell命令的占位符.
您需要将范围传递给您的命令,以便它可以在一系列行上运行.
command! -range=% RemoveOutput :<line1>,<line2> ! grep -v 'OUT'
Run Code Online (Sandbox Code Playgroud)
LINE RANGE
Some commands take a range as their argument. To tell Vim that you are
defining such a command, you need to specify a -range option. The values for
this option are as follows:
-range Range is allowed; default is the current line.
-range=% Range is allowed; default is the whole file.
-range={count} Range is allowed; the last number in it is used as a
single number whose default is {count}.
When a range is specified, the keywords <line1> and <line2> get the values of
the first and last line in the range. For example, the following command
defines the SaveIt command, which writes out the specified range to the file
"save_file":
:command -range=% SaveIt :<line1>,<line2>write! save_file
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
288 次 |
| 最近记录: |