From 94de573c7f05582cb2ab6e2a7cb81cca31ba6453 Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Wed, 9 Apr 2025 03:08:14 +0000 Subject: Add a vertical version of 'iw/iW' with iv/iV --- autoload/fall.vim | 44 ++++++++++++++++++++++++++++++++++++++++++++ plugin/fall.vim | 8 ++++++++ 2 files changed, 52 insertions(+) diff --git a/autoload/fall.vim b/autoload/fall.vim index feccc1a..ac54ba0 100644 --- a/autoload/fall.vim +++ b/autoload/fall.vim @@ -114,3 +114,47 @@ function! fall#visual_same_character(dir) return expr endfunction + +function! fall#visual_vertical_word(dir, def_class) + let start_line = line(".") + let line = start_line + let column = col(".") + + let start_char = matchstr(getline(line), '\%' . column . 'c.') + if (start_char =~# '\s') + let class = '\s' + elseif (start_char =~# a:def_class) + let class = a:def_class + else + return "" + endif + + let expr = "" + + if a:dir =~ 'k' + while line > 1 + let line -= 1 + if ! (matchstr(getline(line), '\%' . column . 'c.') =~# class) + break + endif + let expr .= 'k' + endwhile + endif + + if a:dir == 'jk' + let expr .= 'o' + let line = start_line + endif + + if a:dir =~ 'j' + while line <= line("$") + let line += 1 + if ! (matchstr(getline(line), '\%' . column . 'c.') =~# class) + break + endif + let expr .= 'j' + endwhile + endif + + return expr +endfunction diff --git a/plugin/fall.vim b/plugin/fall.vim index 8de1780..a3eb2c5 100644 --- a/plugin/fall.vim +++ b/plugin/fall.vim @@ -35,6 +35,14 @@ vnoremap ii exec "normal! " \ . "kO" \ . fall#fall('k', '^\s*$') . 'j' +" Selects "vertical words" +vnoremap iv fall#visual_vertical_word("jk", '\k') +onoremap iv exec "normal! V" . fall#visual_vertical_word("jk", '\k') + +" Selects "vertical WORDS" +vnoremap iV fall#visual_vertical_word("jk", '\S') +onoremap iV exec "normal! V" . fall#visual_vertical_word("jk", '\S') + vnoremap ic fall#visual_same_character("jk") onoremap ic exec "normal! V" . fall#visual_same_character("jk") -- cgit