Created
July 27, 2021 13:48
-
-
Save Integralist/87742ba01bb58be8b0e293b5ba3fbfd3 to your computer and use it in GitHub Desktop.
[Vim word motion to be camelcase sensitive] #vim #viml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Word() | |
" Get cursor current position | |
let curpos = getpos(".") | |
" Apply movement | |
normal! w | |
" Get cursor potential next position | |
let wcurpos = getpos(".") | |
" Return cursor to original place | |
call setpos(".", curpos) | |
" Get the string between the two cursor positions | |
let line = getline(line(".")) | |
if curpos[1] == wcurpos[1] " word within the same line | |
let str = line[curpos[2]-1:wcurpos[2]-1] | |
else | |
" word motion goes to next line | |
let str = line[curpos[2]-1:] | |
endif | |
" Look for upper case in the string | |
let m = match(str, '[A-Z]', 1) | |
" If upper case letter found | |
if m >= 1 | |
exec "normal ". m ."l" | |
else | |
" else just move as normal | |
normal! w | |
endif | |
endfunction | |
nnoremap w :call Word()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment