Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

21 Commits

Repository files navigation

A helper plugin for defining consistent charwise and linewise motions and visual selection endpoints.

You can read about (neo)vim's inconsistencies this plugin aims to address here.

This plugin is also designed to correctly handle multibyte and composing characters, as well as forced motions (except blockwise).

Usage

localmotion=require('motion')
vim.keymap.set('o', 'my-motion', function()
localcursor=vim.api.nvim_win_get_cursor(0)
localend_pos= { cursor[1] -1, vim.v.maxcol }
motion.textobj_set_endpoints(end_pos, cursor)
end, { desc='selects until the end of the previous line' })
vim.keymap.set('n', 'my-visual', function()
localp1=vim.api.nvim_win_get_cursor(0)
localp2= { p1[1] +1, vim.v.maxcol }
ifmotion.range_inclusive_to_visual(p1, p2) thenmotion.util.visual_start(p1, p2)
endend, {
desc='starts visual selection from the current position'..' to the end of the next line, including both ends',
})

Testing

localplugin_path=''-- if not installed as a plugin-- vim.opt.rtp:prepend(plugin_path)vim.opt.rtp:prepend(plugin_path..'/test')
localfunctionrun_test()
package.loaded['motion'] =nilpackage.loaded['motion.util'] =nilpackage.loaded['motion-test.helpers'] =nilprint('-----util-----')
package.loaded['motion-test.util_spec'] =nilrequire('motion-test.util_spec')
print('-----visual-----')
package.loaded['motion-test.init_visual_spec'] =nilrequire('motion-test.init_visual_spec')
print('-----inclusive-visual-----')
package.loaded['motion-test.init_visual_inclusive_spec'] =nilrequire('motion-test.init_visual_inclusive_spec')
print('-----textobj-calc-endpoints-----')
package.loaded['motion-test.init_textobj_calc_endpoints_spec'] =nilrequire('motion-test.init_textobj_calc_endpoints_spec')
end--- Warning: changes options!localfunctionrun_options_test()
package.loaded['motion'] =nilpackage.loaded['motion.util'] =nilpackage.loaded['motion-test.helpers'] =nilprint('-----textobj-calc-endpoints-----')
package.loaded['motion-test.init_textobj_spec'] =nilrequire('motion-test.init_textobj_spec')
endvim.cmd('mes clear')
run_test()
-- run_options_test()

About

Neovim plugin for defining consistent motions and visual selection endpoints

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages