No edit summary |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=758 |
|id=758 |
||
+ | |previous=757 |
||
− | |title=search and sort by selection |
||
+ | |next=759 |
||
− | |created= |
+ | |created=2004 |
|complexity=basic |
|complexity=basic |
||
− | |author=mosh |
+ | |author=mosh |
|version=6.0 |
|version=6.0 |
||
|rating=12/5 |
|rating=12/5 |
||
+ | |category1= |
||
− | |text= |
||
+ | |category2= |
||
− | Recently I discovered the potential uses of vmap ... |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | <pre> |
||
⚫ | |||
+ | :vmap 0 :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m0<CR> |
||
+ | :vmap $ :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m$<CR> |
||
+ | :vmap p :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>p<CR> |
||
+ | </pre> |
||
⚫ | |||
⚫ | |||
− | |||
− | be precomputed, because it depends on data). |
||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | to move matching lines out of the way, it gets tedious, |
||
− | |||
− | so here's the automation using vmap: |
||
− | |||
− | |||
− | |||
− | With tip, |
||
− | |||
⚫ | |||
− | |||
− | v<move> |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | 5. You figure out more uses. |
||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | :vmap 0 :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m0<CR> |
||
− | |||
− | :vmap $ :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m$<CR> |
||
− | |||
− | :vmap p :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>p<CR> |
||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | to avoid errors on subtrings like 'c:/xyz/*.*' |
||
− | |||
− | |||
− | |||
− | Mosh |
||
− | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | <pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
− | Breadman |
||
− | , August 30, 2004 10:42 |
||
---- |
---- |
||
− | <!-- parsed by vimtips.py in 0.477628 seconds--> |
Latest revision as of 05:46, 13 July 2012
Tip 758 Printable Monobook Previous Next
created 2004 · complexity basic · author mosh · version 6.0
I need to sort log file by some substring (that cannot be precomputed, because it depends on data).
I would select substring with mouse, then press :g/<S-Insert>/m0 to move matching lines out of the way, it gets tedious, so here's the automation using vmap:
- Select any part of the string with
v<move>
- Press 0, to move all matching lines to top of the file.
- Or press p, to see other matches.
- Or press $, to move junk to end of file.
" Sort by selection. :vmap 0 :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m0<CR> :vmap $ :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>m$<CR> :vmap p :<BS><BS><BS><BS><BS>g<M-x>\M<S-Insert><M-x>p<CR>
I used M-x as a delimiter and very non magic \M modifier to avoid errors on subtrings like 'c:/xyz/*.*'
Comments[]
The tip as given assumes that the selection is automatically copied to the clipboard. The following maps are more compatible, but modify the unnamed register. I also switched the maps to start with m, to preserve the original motions.
vmap m0 y:g<M-x>\M<C-R>"<M-x>m0<CR> vmap m$ y:g<M-x>\M<C-R>"<M-x>m$<CR> vmap mp y:g<M-x>\M<C-R>"<M-x>p<CR>