Created
July 10, 2014 19:25
-
-
Save melrief/300f1dd7ab7db0cfa237 to your computer and use it in GitHub Desktop.
Set the current selection indent to the indent of the line above it with <C-Tab> in vim
This file contains 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
function! IndentAsPrevLine() | |
python << EOF | |
import itertools as I | |
from vim import * | |
if current.range.start > 0: | |
def takewhile(pred,l): return ''.join(I.takewhile(pred,l)) | |
prev_line = current.buffer[current.range.start - 1] | |
spaces = takewhile(lambda c:c.isspace(),prev_line) | |
for idx in xrange(current.range.start,current.range.end+1): | |
line = current.buffer[idx] | |
curr_spaces = takewhile(lambda c:c.isspace(),line) | |
# avoid multiple indent | |
if len(spaces) != len(curr_spaces): | |
current.buffer[idx] = spaces + line.lstrip() | |
EOF | |
endfunction | |
map <C-Tab> :call IndentAsPrevLine()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment