Skip to content

Commit 1d7ca66

Browse files
committed
New plugin.
0 parents  commit 1d7ca66

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed

doc/textobj-word-column.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
*textobj-word-column.txt* Adds text-objects for word-based columns.
2+
3+
===============================================================================
4+
CONTENTS *textobj-word-column-contents*
5+
6+
1. Intro...............................|textobj-word-column-intro|
7+
2. Commands............................|textobj-word-column-mappings|
8+
3. Mappings............................|textobj-word-column-examples|
9+
4. Contributing........................|textobj-word-column-contributing|
10+
5. Credits.............................|textobj-word-column-credits|
11+
6. Changelog...........................|textobj-word-column-changelog|
12+
13+
===============================================================================
14+
INTRO *textobj-word-column-intro*
15+
16+
The word-based column |text-object| makes operating on columns of code
17+
conceptually simpler and reduces keystrokes.
18+
19+
The common task of deleting, changing, or adding to a vertical column of code
20+
can be achieved using |visual-blocks|, however the first step is to establish
21+
the visual block itself. This typically involves moving the cursor to the
22+
start of the block, and then using vim motions to move the cursor to the end of
23+
the block, and finally doing the appropriate operation.
24+
25+
With a text object for columns, establishing the visual block is much easer,
26+
and even unecessary for certain operations.
27+
28+
===============================================================================
29+
WORD-BASED COLUMN *textobj-word-column-mappings*
30+
31+
*ac* *cac* *dac* *vac* *yac*
32+
ac "a column", a column based on "a word" |aw|.
33+
34+
*ic* *cic* *dic* *vic* *yic*
35+
ic "inner column", a column based on the "inner word" |iw|.
36+
37+
*aC* *caC* *daC* *vaC* *yaC*
38+
aC "a COLUMN", a column based on "a WORD" |aW|.
39+
40+
*iC* *ciC* *diC* *viC* *yiC*
41+
iC "inner COLUMN", a column based on "inner WORD" |iW|.
42+
43+
===============================================================================
44+
USAGE EXAMPLES *textobj-word-column-examples*
45+
46+
vic Visually select a column.
47+
48+
cic Change a column.
49+
50+
dac Delete a column.
51+
52+
vicI Prepend new text to a column.
53+
54+
vicA Append new text to a column.
55+
56+
viC Visually select a WORD based colunn.
57+
58+
===============================================================================
59+
CONTRIBUTING *textobj-word-column-contributing*
60+
61+
The goal of this plugin is to be able to operate on conceptual columns of code
62+
without the hassle of manually demarcating their boundaries. If you find a
63+
case where the selected column wasn't what you expected AND there's a logical
64+
way to fix or add a boundary condition for that case, then submit an issue via
65+
github. If you'd like to add the fix yourself, please fork the plugin, make
66+
your changes in a branch, and then submit a pull request for that branch.
67+
68+
===============================================================================
69+
CREDITS *textobj-word-column-credits*
70+
71+
Developed by Jim Garvin <http://github.com/coderifous>.
72+
73+
Git repository: https://github.com/coderifous/textobj-word-column.vim
74+
75+
===============================================================================
76+
CHANGELOG *textobj-word-column-changelog*
77+
78+
First Public Release: 2012/06/18

plugin/textobj/word-column.vim

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
if (exists("g:loaded_textobj_word_column"))
2+
finish
3+
endif
4+
5+
function! TextObjWordBasedColumn()
6+
let startcol = col("'<")
7+
let stopcol = col("'>")
8+
let linenum = line(".")
9+
let indentlevel = s:indent_level(".")
10+
let startline = s:find_boundary_row(linenum, indentlevel, -1)
11+
let stopline = s:find_boundary_row(linenum, indentlevel, 1)
12+
exec "silent normal!" startline . "gg" . startcol . "|" stopline . "gg" . stopcol . "|"
13+
endfunction
14+
15+
function! s:find_boundary_row(linenum, indentlevel, step)
16+
let sameindent = s:indent_level(a:linenum + a:step) == a:indentlevel
17+
let nonblank = getline(a:linenum + a:step) =~ "[^ \t]"
18+
if sameindent && nonblank
19+
return s:find_boundary_row(a:linenum + a:step, a:indentlevel, a:step)
20+
else
21+
return a:linenum
22+
endif
23+
endfunction
24+
25+
function! s:indent_level(linenum)
26+
let line = getline(a:linenum)
27+
return match(line, "[^ \t]")
28+
endfunction
29+
30+
if (!exists("g:skip_default_textobj_word_column_mappings"))
31+
vnoremap <silent> ac <Esc>vaw:call TextObjWordBasedColumn()<cr>
32+
vnoremap <silent> aC <Esc>vaW:call TextObjWordBasedColumn()<cr>
33+
vnoremap <silent> ic <Esc>viw:call TextObjWordBasedColumn()<cr>
34+
vnoremap <silent> iC <Esc>viW:call TextObjWordBasedColumn()<cr>
35+
onoremap <silent> ac :normal vac<cr>
36+
onoremap <silent> aC :normal vaC<cr>
37+
onoremap <silent> ic :normal vic<cr>
38+
onoremap <silent> iC :normal viC<cr>
39+
endif
40+
41+
let g:loaded_textobj_word_column = 1

0 commit comments

Comments
 (0)