Vim Tips Wiki
Advertisement

Previous TipNext Tip

Tip: #1016 - Moving through camel case words

Created: October 10, 2005 4:13 Complexity: basic Author: Anthony Van Ham Version: 6.0 Karma: 14/11 Imported from: Tip#1016

If you want to move through a camel case word, like CamelCaseWordWeWantToMoveThrough, word by word (eg from the 'C' on Camel to the 'C' on Case to the 'W' in word), you can add the following maps to assign Ctrl-right and Ctrl-left to do the job


(inspired by http://groups.google.com/group/comp.editors/browse_thread/thread/863891edbd961691/280b68b9686e346e%23280b68b9686e346e?sa=X&oi=groupsr&start=0&num=2)


imap <C-Right> �:call search('\<\<Bar>\u', 'W')<CR>

imap <C-Left> �:call search('\<\<Bar>\u', 'Wb')<CR>

map <C-Right> :call search('\<\<Bar>\u', 'W')<CR>

map <C-Left> :call search('\<\<Bar>\u', 'Wb')<CR>

Comments

This tip is pretty handy, but I just wish it would work in select mode so you could get the behavior common in Windows code editors when you do ctrl+shift+<left>or<right>. Any tips out there for this?

Anonymous , March 16, 2006 12:07


Here is a more thorough version. It does not go through a CAPITALIZED word one character at a time.

nnoremap <silent><C-Left> :<C-u>cal search('\<\<Bar>\U\--AT--<=\u\<Bar>\u\ze\%(\U\&\>\--AT--!\)\<Bar>\%^','bW')<CR> nnoremap <silent><C-Right> :<C-u>cal search('\<\<Bar>\U\--AT--<=\u\<Bar>\u\ze\%(\U\&\>\--AT--!\)\<Bar>\%$','W')<CR> inoremap <silent><C-Left> <C-o>:cal search('\<\<Bar>\U\--AT--<=\u\<Bar>\u\ze\%(\U\&\>\--AT--!\)\<Bar>\%^','bW')<CR> inoremap <silent><C-Right> <C-o>:cal search('\<\<Bar>\U\--AT--<=\u\<Bar>\u\ze\%(\U\&\>\--AT--!\)\<Bar>\%$','W')<CR>


Gerald Lai , March 27, 2006 17:59


Advertisement