by damncabbage · 14y ago · 0 comments
J Join line.
ddp Swap line with the one below.
ddkP Swap line with the one above.
dd Delete current line
yyp Duplicate line
gq} Rewrap a paragraph.
Vu Lowercase a line
VU Uppercase a line
Sort the selection by the Unix `sort` command (eg. sort -rn for reverse numeric order): V <select your lines>
:!sort
It goes a bit pear-shaped for these ones, though: Title-Case:
:s/\<\(\w\)\(\w*\)\>/\u\1\L\2/g
Twiddle/Flip Case:
function! TwiddleCase(str)
if a:str ==# toupper(a:str)
let result = tolower(a:str)
elseif a:str ==# tolower(a:str)
let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
else
let result = toupper(a:str)
endif
return result
endfunction
vnoremap ~ ygv"=TwiddleCase(@")<CR>Pgv
I'm a bit stumped on toggling comments, though. Any ideas? " comentify/uncommentify a line or a visual block"
function! Komment()
if getline(".") =~ '^[ \t]*#'
let hls=@/
s/^\([ \t]*\)#\(.*\)$/\1\2
let @/=hls
else
let hls=@/
s/^\([ \t]*\)\(.*\)$/\1#\2
let @/=hls
endif
endfunction
:vnoremap // :call Komment()<CR>
:nnoremap // :call Komment()<CR>
If you want to use c style comment :
function! Komment()
if getline(".") =~ '^[ \t]*\/\*'
let hls=@/
s/^\(\s*\)\/\*\(.*\)\*\/\(\s*\)$/\1\2\3/
let @/=hls
else
let hls=@/
s/[ \t]*$//
s/^\(\s*\)\(.*\)\(\s*\)$/\1\/\* \2 \*\//
let @/=hls
endif
endfunction
:vnoremap <silent> // :call Komment()<CR>
:nnoremap <silent> // :call Komment()<CR>
edited formatting>> ddp Swap line with the one below. >> ddkP Swap line with the one above.
>> dd Delete current line >> yyp Duplicate line
>> gq} Rewrap a paragraph.
These shortcuts work in Sublime too, with Vintage mode enabled.
" Move a line of text using ALT+[jk] or Comamnd+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endifIs there some sort of trick you use?