5
5
![ Demo] ( https://i.imgur.com/dntK3MP.gif )
6
6
7
7
8
- You can use "exe" mode (flag ` -e ` ):
9
- for example, to comment out in C++
10
- every line containing ` my_bad_var ` ,
11
- then delete the line above it:
8
+ Ever wish you could simply apply a vim command to every line
9
+ in a command output automatically?
10
+ If you use vim as your primary editor, this is likely much much easier
11
+ than having to look up sed commands every time you filter a command output.
12
12
13
- ```
14
- cat my_script.cpp | vims -e 'my_bad_var' 'I//\<esc>kdd'
15
- ```
13
+ E.g., ` cat file.txt | vims -l 'f|d$' ` will go through every line, and run "f|d$",
14
+ which is the vim command for deleting every character after "|".
15
+ See below for many other useful features.
16
16
17
- Which translates to ` vims '%g/my_bad_var/exe "norm I//\<esc>kdd"' ` - the ` I ` being the command
18
- to start insert at the start of the line, and ` // ` being the comment sequence.
19
- ` \<esc>kdd ` pushes the escape key, moves up a line, then deletes the line.
17
+ # Install
20
18
21
- ```
22
- > echo 'Hello World!' | vims -s 'ea Beautiful'
23
- Hello Beautiful World!
24
- ```
19
+ To install, put ` vims ` somewhere on your path, e.g., ` /usr/bin ` .
25
20
26
- - ` -s ` - Turn on simple mode (normal vim commands, start at char 0, line 0)
27
- - ` ea ` - Start inserting after end of first word
28
21
29
- # Usage/Examples
22
+ # Usage
30
23
31
- To install,
32
- put ` vims ` somewhere on your path, e.g., ` /usr/bin ` .
24
+ ` ... | vims ... `
25
+ - (default) ` -t [EX_CMD] ` Ex mode. Works as if you typed ":" in vim.
26
+ - ` -s [CMD] ` Simple command mode. Starts on the first line in command mode (e.g., ` x ` deletes a char).
27
+ - ` -l [CMD] ` Line command mode. Runs the command on every line.
28
+ - ` -e [REGEX] [CMD] ` Exe mode. Runs the command on every line matching ` REGEX ` (uses vim regex).
29
+ - ` -r [REGEX] [CMD] ` Inverse exe mode. Runs the command on every line not matching ` REGEX ` (uses vim regex).
30
+ - ` -n ` quiet. Don't print lines to stdout. You will then have to use ` :p ` command to print manually.
31
+
32
+ Note that for commands, you can write ` \<esc> ` to hit the escape key, or ` \<c-o> ` to hit ctrl-O.
33
33
34
34
```
35
- {command} | vims [-n|--quiet] [-d|--disable-vimrc]
35
+ {command} | vims [-n|--quiet]
36
36
[-e|--exe-mode] [-r|--inverse-exe-mode]
37
37
[-s|--simple-mode] [-l|--line-exe-mode]
38
38
[-t|--turn-off-mode]
@@ -43,6 +43,8 @@ Call `vims` on piped input, providing a list of arguments that you
43
43
would use in vim command-line mode. All lines not deleted are printed
44
44
by default, but you can turn this off with a ` -n|--quiet ` flag.
45
45
46
+ ## Discussion:
47
+
46
48
Trigger "exe" mode using the ` -e|--exe-mode ` flag, which creates macros
47
49
for ` '%g/$1/exe "norm $2"' ` (see [ the power of ` :g ` ] ( http://vim.wikia.com/wiki/Power_of_g ) ),
48
50
where ` $1 ` is the first arg of a pair,
@@ -64,9 +66,6 @@ Modes are activated for all the proceeding args. You can switch
64
66
modes partway, by calling the flag for the other mode you want, or you
65
67
can turn off any activated mode with ` -t|--turn-off-mode ` .
66
68
67
- Your default vimrc should be enabled by default, turn it off with
68
- ` -d|--disable-vimrc ` .
69
-
70
69
## Example 1
71
70
Delete lines 10-15, and print the remainder:
72
71
0 commit comments