Wednesday, September 8, 2010

Re: formating

On Sep 9, 1:22 am, sandeep kapse <sandeep.kaps...@gmail.com> wrote:
> I have to shift the following text to left or right with just one place

This is such a common use case for me that I wrote the following years
ago. Just do a visual block, type space to increase indent, backspace
to decrease:

function! Vbs()
if visualmode() != "\<c-v>"
normal gvh
return
endif
let s = getpos("'<")
let e = getpos("'>")
let fl = min([s[1],e[1]])
let fc = min([s[2],e[2]])
let ll = max([s[1],e[1]])
let lc = max([s[2]+s[3],e[2]+e[3]])
let sve = &virtualedit
let &virtualedit = "all"
call setpos(".", [0, fl, lc - (lc == 1 ? 0 : 1), 0])
execute "normal \<c-v>"
call setpos(".", [0, ll, lc - (lc == 1 ? 0 : 1), 0])
normal x
call setpos(".", [0, fl, fc - (fc == lc && fc != 1 ? 1 : 0), 0])
execute "normal \<c-v>"
call setpos(".", [0, ll, lc - (fc == lc && lc == 1 ? 0 : 1), 0])
let &virtualedit = sve
endfunction

function! Vsp()
if visualmode() != "\<c-v>"
normal gvl
return
endif
execute "normal gvI\<space>\<esc>"
normal gvl
endfunction

vnoremap <silent> <space> :<C-U>call Vsp()<cr>
vnoremap <silent> <bs> :<C-U>call Vbs()<cr>


Also, I have
" I use block mode so much that I want the unmodified v to start block
mode
noremap v <c-v>
" occasionally characterwise visual mode is useful, get it with vv
vunmap v

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: