I am using DrawIt plugin in Vim 7 to draw some ASCII diagrams.
This might be too much, but still—
Is there any plugin which can display a grid in background, to make the drawing easier?
I can't add anything to @David and @romainl's thoughts (I think @romainl's suggestion of using a semi-transparent window with a grid behind it is inspired!).
However, you might find it easier to visualise the cursor position by using:
set cursorline
set cursorcolumn
Of course it's not a substitute for a true grid, but it will at least let you see at a glance the alignment of the cursor.
Let me propose an implementation emulating the guiding grid using Vim highlighting features. The following function creates the necessary highlighting taking two mandatory arguments and another two optional ones. The former two are distances between horizontal and vertical lines, correspondingly. The latter arguments are the height and the width of the area covered with grid (in lines and characters, correspondingly). When these arguments are not specified the number of lines in the buffer and the length of the longest line in it are used.
function! ToggleGrid(...)
if exists('b:grid_row_grp') || exists('b:grid_prev_cc')
call matchdelete(b:grid_row_grp)
let &colorcolumn = b:grid_prev_cc
unlet b:grid_row_grp b:grid_prev_cc
return
endif
let [dr, dc] = [a:1, a:2]
if a:0 < 4
let [i, nr, nc] = [1, line('$'), 0]
while i <= nr
let k = virtcol('$')
let nc = nc < k ? k : nc
let i += 1
endwhile
else
let [nr, nc] = [a:3, a:4]
endif
let rows = range(dr, nr, dr)
let cols = range(dc, nc, dc)
let pat = '\V' . join(map(rows, '"\\%" . v:val . "l"'), '\|')
let b:grid_row_grp = matchadd('ColorColumn', pat)
let b:grid_prev_cc = &colorcolumn
let &colorcolumn = join(cols, ',')
endfunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With