Created
January 31, 2017 21:55
-
-
Save deathlyfrantic/fc513b59364a0dabb19448a34308cfd9 to your computer and use it in GitHub Desktop.
check/uncheck [x] boxes with the mouse in vim.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" this whole thing is super brittle, but was a fun experiment | |
function! s:string_replace(string, new_char, position) | |
let l:string_list = [strpart(a:string, 0, a:position)] | |
let l:string_list = add(l:string_list, a:new_char) | |
let l:string_list = add(l:string_list, strpart(a:string, (a:position + 1))) | |
return join(l:string_list, '') | |
endfunction | |
function! CheckThatBox() | |
let l:colnum = col('.') - 1 | |
let l:lnum = line('.') | |
let l:line = getline(l:lnum) | |
let l:char = l:line[l:colnum] | |
let l:x = -1 | |
if l:char == '[' && l:line[l:colnum + 2] == ']' | |
let l:x = l:colnum + 1 | |
elseif l:char == ']' && l:line[l:colnum - 2] == '[' | |
let l:x = l:colnum - 1 | |
elseif l:line[l:colnum - 1] == '[' && l:line[l:colnum + 1] == ']' | |
let l:x = l:colnum | |
endif | |
if l:x > -1 | |
let l:repl = (l:line[l:x] =~? 'x') ? ' ' : 'X' | |
let l:line = s:string_replace(l:line, l:repl, l:x) | |
call setline(l:lnum, l:line) | |
endif | |
endfunction | |
nnoremap <silent> <LeftMouse> <LeftMouse>:call CheckThatBox()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment