Created
April 5, 2012 03:26
-
-
Save skalnik/2307726 to your computer and use it in GitHub Desktop.
<Leader>al to move down a line and insert delta of spaces
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
map <Leader>al :call MoveDownLine()<CR> | |
function! MoveDownLine() | |
let cols=col('.') | |
execute "normal! j" | |
let next_cols=col('.') | |
let delta_cols=cols-next_cols | |
if(delta_cols > 0) | |
if(next_cols==1) | |
let delta_cols += 1 | |
endif | |
execute "normal! " . delta_cols . "A " | |
endif | |
endfunction |
When it comes to Vimscript stuff, my thoughts usually end up at "if it works, it works!" since it's hard to test and things this small don't really have a way of doing it "right" that I know of. Looks good to me! 👍
Slightly more fancy?
map <Leader>o :call MoveLine('o', 'k')<CR>
map <Leader>O :call MoveLine('O', 'j')<CR>
function! MoveLine(open_motion, post_motion)
let cols=col('.')
execute "normal! D" . a:open_motion
let next_cols=col('.')
let delta_cols=cols-next_cols
if(delta_cols > 0)
execute "normal! " . delta_cols . "A "
endif
execute "normal! p" . a:post_motion
endfunction
Nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Close, but I actually wanted the line to move. I ended up with this, thanks only to you giving me a head start. Thoughts?