Created
December 10, 2014 10:08
-
-
Save Olical/7da533889a4f3224a40b to your computer and use it in GitHub Desktop.
Expand lines like bash in Vim https://asciinema.org/a/14558
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Run expand on your current line or range of lines. | |
| " Allows you to repeat {lines,blocks} like this {1..3} times. | |
| " Allows you to repeat lines like this 1 times. | |
| " Allows you to repeat lines like this 2 times. | |
| " Allows you to repeat lines like this 3 times. | |
| " Allows you to repeat blocks like this 1 times. | |
| " Allows you to repeat blocks like this 2 times. | |
| " Allows you to repeat blocks like this 3 times. | |
| function! s:expand() range | |
| let new_line = "_THIS_IS_A_NEW_LINE_" | |
| let selection = join(getline(a:firstline, a:lastline), new_line) | |
| let expanded = substitute(expand(selection), "\n", new_line, 'g') | |
| let lines = split(expanded, new_line) | |
| execute 'silent! ' . a:firstline . ',' . a:lastline . 'd' | |
| call append(a:firstline - 1, lines) | |
| execute 'silent! normal =' . len(lines) . 'k' | |
| endfunction | |
| command! -range Expand :<line1>,<line2>call <SID>expand() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment