Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Integralist/87742ba01bb58be8b0e293b5ba3fbfd3 to your computer and use it in GitHub Desktop.
Save Integralist/87742ba01bb58be8b0e293b5ba3fbfd3 to your computer and use it in GitHub Desktop.
[Vim word motion to be camelcase sensitive] #vim #viml
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