4 ms·
Vim equivalents if you're feeling jealous (matching the order in the article): J Join line. ddp Swap line with the one below. ddkP Swap line with th
by damncabbage 14y ago
Vim equivalents if you're feeling jealous (matching the order in the article):
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?
- patrickaljord 14y ago> I'm a bit stumped on toggling comments, though. Any ideas? http://www.vim.org/scripts/script.php?script_id=1218 http://www.vim.org/scripts/script.php?script_id=1218
- slurgfest 14y agoSimpler alternative: tComment http://www.vim.org/scripts/script.php?script_id=1173 http://www.vim.org/scripts/script.php?script_id=1173
- shreyas-satish 14y ago>> 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. These shortcuts work in Sublime too, with Vintage mode enabled.
- amix 14y agoFor swapping lines I recommend following shortcuts: " 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> endif
- atechie 14y ago>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
- tyrmored 14y agogqap uses a paragraph as a text object so you don't have to be at the start of the paragraph for it to work, just somewhere inside it.
- eieio 14y agoUnless I'm misunderstanding the purpose of your 'TwiddleCase' function, you can simply highlight the text that you want to flip and hit ~ to invert the case.
- jurre 14y agoI think macvim has this because I've been doing it for as long as i remember, or maybe it's in Janus though.
- damncabbage 14y agoThis is all plain vim, so this'll work in MacVim, GVim and Janus (just MacVim and a bundle of plugins).
- jurre 14y agosorry i meant command / to toggle comments
- deleted 14y ago[deleted]
- kamaal 14y agoMakes me curious how you manage to remember all these commands. Is there some sort of trick you use?
- f0r 14y agoVim commands are like a language - you don't route learn combinations, only the individual "words", and you string them together dynamically, like you would do with English words in a sentence.
- kamaal 14y agoWhat are the list of those individual "words". And what is the syntax for combining them?
- damncabbage 14y agoThis is the best explanation I've found so far: http://stackoverflow.com/a/1220118/3528 http://stackoverflow.com/a/1220118/3528
- kamaal 14y agoIt was a very good read. But not what I was expecting. If vim is indeed speaking a language this is what I would expect a vim tutorial to have. 1. Basic commands. 2. Syntax to chain basic commands. 3. Ability to form other commands from basic commands. 4. Way to write macros. Instead most vim tutorials I have read present with a list of several commands to memorize and then a cheat sheet to navigate you through a jungle. Often they are letters, and not meaningful words. So they are difficult to put into ones brain. Couple that with vim's modes. And you are set with a perfect recipe for disaster in case of a new bie. If vim is indeed speaking a language than manuals and tutorials teaching it, must explain how to speak that language. This is 2012 and the need to memorize commands, and read cheat sheets to edit text doesn't belong to our times. What I seem to get is vim aims to provide sed, grep, tr, cut etc kind of tools inside a text editor in form of some interplay of letters and words. How I haven't figured out till today's date. Every time I've tried to learn vim, I've quit trying to memorize 'yy P...' kind of commands. That happens as I first can't memorize random arrangement of characters. Secondly if its not random, I've not understood how to arrange and use those letters to make meaningful commands.