Skip to content

Commit 5b82ebc

Browse files
committed
Add another example and change wording of credit
1 parent 1750efe commit 5b82ebc

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

README.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ cat script.sh | vims -r 'foo' 'A # Comment'
122122

123123
## Example 4
124124

125+
Delete all modifications to files in a git repo:
126+
127+
```
128+
git status | vims '1,/modified/-1d' '$?modified?,$d' -l 'df:dw' | xargs git checkout --
129+
```
130+
131+
- `git status` - View which files are modified
132+
- `vims` - Start vims in normal mode
133+
- `1,/modified/-1d` - Delete all lines up to the first line with "modified"
134+
- `$?modified?+1,$d` - Delete all lines from below the last line with "modified"
135+
- `-l` - Turn on line exe mode (execute a command on each line)
136+
- `df:dw` - Delete until the ":", then delete the white space
137+
- `xargs git checkout --` - Pass all the filenames to `git checkout --`
138+
139+
## Example 5
140+
125141
Move all Python classes to the bottom of a file:
126142
```
127143
cat myscript.py | vims -e '^class' 'V/^\\S\<enter>kdGp'
@@ -132,7 +148,7 @@ cat myscript.py | vims -e '^class' 'V/^\\S\<enter>kdGp'
132148
- `exe` - Execute the following, including escaped sequences (so you can call `\<c-o>` to mean Ctrl-o)
133149
- `norm V/^\S\<enter>kdGp` Enter normal mode, visual select to the next zero-indentation line, move up a line, delete, paste it at the bottom
134150

135-
## Example 5
151+
## Example 6
136152

137153
Only print the last 6 lines (just like tail)
138154

@@ -143,7 +159,7 @@ cat txt | vims -n '$-5,$p'
143159
- `$-5,$` - A range extending from 6th last line to the last line
144160
- `p` - Print
145161

146-
## Example 6
162+
## Example 7
147163

148164
Replace all multi-whitespace sequences with a single space:
149165

@@ -160,7 +176,7 @@ cat txt | vims -e '.' ':s/\\s\\+/ /g\<enter>'
160176
Note the double back-slashes needed (only in the second string of a pair in an exe command!)
161177
when you are typing a character like `\s`, but not like `\<enter>`.
162178

163-
## Example 7
179+
## Example 8
164180
Resolve all git conflicts by deleting the changes on HEAD (keep the bottom code):
165181

166182
```
@@ -174,7 +190,7 @@ cat my_conflict.cpp | vims -e '^=======$' 'V?^<<<<<<< \<enter>d' -t '%g/^>>>>>>>
174190
- `%g/^>>>>>>> /d` - Delete remaining conflict lines
175191

176192

177-
## Example 8
193+
## Example 9
178194

179195
Uncomment all commented-out lines (comment char: `#`)
180196

@@ -185,7 +201,7 @@ cat script.sh | vims -e '^\s*#' '^x'
185201
- `^\s*#` - Work on lines with whitespace followed by a comment char, followed by anything
186202
- `^x` - Go to the first non-whitespace character, and delete it
187203

188-
## Example 9
204+
## Example 10
189205

190206

191207
Delete the first word of each line and put it at the end:
@@ -199,7 +215,7 @@ cat script.sh | vims -e '^[A-Za-z]' '\"kdwA \<esc>\"kp'
199215
- `A \<esc>` - Start insert mode at front of line, type a space, hit escape key
200216
- `\"kp` - Paste from the register `k`
201217

202-
## Example 10
218+
## Example 11
203219

204220
Run a super-vanilla long chain of commands in simple mode, starting from line 1 of a file:
205221

@@ -213,7 +229,7 @@ cat python.py | vims -s '/^class\<enter>O# This class broke\<esc>Go\<enter># Thi
213229
- `# This file broke'` - Write at the end of the file: "# This file broke"
214230

215231

216-
## Example 11
232+
## Example 12
217233

218234
Reverse a file:
219235

@@ -225,7 +241,7 @@ cat text.txt | vims '%g/.*/m0'
225241
- `.*` - Matches all lines
226242
- `m0` - Move line to start of file
227243

228-
## Example 12
244+
## Example 13
229245

230246
Sort the output of `ls -l` by file size, using the
231247
unix command `sort` (which you can use inside vim):
@@ -241,9 +257,8 @@ ls -l | vims '1d' '%!sort -k5n'
241257

242258
# Credit
243259

244-
I innovated very little (none) on this script, I basically took a Google Groups
260+
The heart of this script comes from a Google groups posting:
245261
[posting](https://groups.google.com/forum/#!msg/vim_use/NfqbCdUkDb5/Ir0faiNaFZwJ),
246-
then had the nice folks on [SO](https://stackoverflow.com/questions/44745046/bash-pass-all-arguments-exactly-as-they-are-to-a-function-and-prepend-a-flag-on)
247-
help me put it together.
262+
and then from an answer on [SO](https://stackoverflow.com/questions/44745046/bash-pass-all-arguments-exactly-as-they-are-to-a-function-and-prepend-a-flag-on)
248263

249264
Thanks!

0 commit comments

Comments
 (0)