@@ -122,6 +122,22 @@ cat script.sh | vims -r 'foo' 'A # Comment'
122
122
123
123
## Example 4
124
124
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
+
125
141
Move all Python classes to the bottom of a file:
126
142
```
127
143
cat myscript.py | vims -e '^class' 'V/^\\S\<enter>kdGp'
@@ -132,7 +148,7 @@ cat myscript.py | vims -e '^class' 'V/^\\S\<enter>kdGp'
132
148
- ` exe ` - Execute the following, including escaped sequences (so you can call ` \<c-o> ` to mean Ctrl-o)
133
149
- ` 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
134
150
135
- ## Example 5
151
+ ## Example 6
136
152
137
153
Only print the last 6 lines (just like tail)
138
154
@@ -143,7 +159,7 @@ cat txt | vims -n '$-5,$p'
143
159
- ` $-5,$ ` - A range extending from 6th last line to the last line
144
160
- ` p ` - Print
145
161
146
- ## Example 6
162
+ ## Example 7
147
163
148
164
Replace all multi-whitespace sequences with a single space:
149
165
@@ -160,7 +176,7 @@ cat txt | vims -e '.' ':s/\\s\\+/ /g\<enter>'
160
176
Note the double back-slashes needed (only in the second string of a pair in an exe command!)
161
177
when you are typing a character like ` \s ` , but not like ` \<enter> ` .
162
178
163
- ## Example 7
179
+ ## Example 8
164
180
Resolve all git conflicts by deleting the changes on HEAD (keep the bottom code):
165
181
166
182
```
@@ -174,7 +190,7 @@ cat my_conflict.cpp | vims -e '^=======$' 'V?^<<<<<<< \<enter>d' -t '%g/^>>>>>>>
174
190
- ` %g/^>>>>>>> /d ` - Delete remaining conflict lines
175
191
176
192
177
- ## Example 8
193
+ ## Example 9
178
194
179
195
Uncomment all commented-out lines (comment char: ` # ` )
180
196
@@ -185,7 +201,7 @@ cat script.sh | vims -e '^\s*#' '^x'
185
201
- ` ^\s*# ` - Work on lines with whitespace followed by a comment char, followed by anything
186
202
- ` ^x ` - Go to the first non-whitespace character, and delete it
187
203
188
- ## Example 9
204
+ ## Example 10
189
205
190
206
191
207
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'
199
215
- ` A \<esc> ` - Start insert mode at front of line, type a space, hit escape key
200
216
- ` \"kp ` - Paste from the register ` k `
201
217
202
- ## Example 10
218
+ ## Example 11
203
219
204
220
Run a super-vanilla long chain of commands in simple mode, starting from line 1 of a file:
205
221
@@ -213,7 +229,7 @@ cat python.py | vims -s '/^class\<enter>O# This class broke\<esc>Go\<enter># Thi
213
229
- ` # This file broke' ` - Write at the end of the file: "# This file broke"
214
230
215
231
216
- ## Example 11
232
+ ## Example 12
217
233
218
234
Reverse a file:
219
235
@@ -225,7 +241,7 @@ cat text.txt | vims '%g/.*/m0'
225
241
- ` .* ` - Matches all lines
226
242
- ` m0 ` - Move line to start of file
227
243
228
- ## Example 12
244
+ ## Example 13
229
245
230
246
Sort the output of ` ls -l ` by file size, using the
231
247
unix command ` sort ` (which you can use inside vim):
@@ -241,9 +257,8 @@ ls -l | vims '1d' '%!sort -k5n'
241
257
242
258
# Credit
243
259
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:
245
261
[ 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 )
248
263
249
264
Thanks!
0 commit comments