Skip to content

Instantly share code, notes, and snippets.

@skalnik
Created April 5, 2012 03:26
Show Gist options
  • Save skalnik/2307726 to your computer and use it in GitHub Desktop.
Save skalnik/2307726 to your computer and use it in GitHub Desktop.
<Leader>al to move down a line and insert delta of spaces
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
@alindeman
Copy link

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

@skalnik
Copy link
Author

skalnik commented Apr 5, 2012

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment