Skip to content

Vim motions for camelCase, snake_case, names.with.dots, and more

Notifications You must be signed in to change notification settings

bendk/polyword.vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polyword.vim -- Vim motions for camelCase, snake_case, names.with.dots, and more

If you use vim, you know and love its word commands (w, b, daw, ...). However, sometimes the vim word does not match the words you're working with. This plugin fills in the gaps.

Compatible with:

  • nvim (0.5-dev)
  • vim (8.2 and maybe before)

Miniwords

Use miniwords when a vim word is too big, like when you want to navigate by camelCase, PascalCase, snake_case, and kebab-case words.

Map keys to <plug>(polyword-miniword-[command]) to work with miniwords. w, b, e, ge, iw, and aw are all supported

Consider adding "-" to your iskeyword value. This means that w will always go to the next full word and whatever you map to <plug>(polyword-miniword-w) will go to the next mini-word.

Miniword transforms

Transform names between the different case styles. Map keys to any of these mappings:

  • <plug>(polyword-transform-camel) -- transform names to camelCase
  • <plug>(polyword-transform-pascal) -- transform names to PascalCase
  • <plug>(polyword-transform-snake) -- transform names to snake_case
  • <plug>(polyword-transform-kebab) -- transform names to kebab-case
  • <plug>(polyword-transform-snake-upper) -- transform names to SNAKE_CASE
  • <plug>(polyword-transform-kebab-upper) -- transform names to KEBAB-CASE

Megawords

Use megawords when a vim word is too small, like when you want to delete an entire object.value or Class::attribute name. Megawords work exactly like a vim word, but they temporarily add : and . to the iskeyword option.

Map keys to <plug>(polyword-megaword-[command]) to work with megawords. w, b, e, ge, iw, and aw are all supported

Consider mapping the uppercase letters to megawords (W, B, iW etc). I find this more useful than the default vim WORD motions that are mapped to those keys.

Example mappings

map <leader>w <plug>(polyword-miniword-w)
map <leader>b <plug>(polyword-miniword-b)
map <leader>e <plug>(polyword-miniword-e)
map <leader>ge <plug>(polyword-miniword-ge)
omap im <plug>(polyword-miniword-iw)
omap am <plug>(polyword-miniword-aw)

map <leader>W <plug>(polyword-megaword-w)
map <leader>B <plug>(polyword-megaword-b)
map <leader>E <plug>(polyword-megaword-e)
map <leader>gE <plug>(polyword-megaword-ge)
omap iW <plug>(polyword-megaword-iw)
omap aW <plug>(polyword-megaword-aw)

map <leader>nc <plug>(polyword-transform-camel)
map <leader>nC <plug>(polyword-transform-pascal)
map <leader>ns <plug>(polyword-transform-snake)
map <leader>nS <plug>(polyword-transform-snake-upper)
map <leader>nk <plug>(polyword-transform-kebab)
map <leader>nK <plug>(polyword-transform-kebab-upper)

About

Vim motions for camelCase, snake_case, names.with.dots, and more

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published