From 896c311feb10e947c727a888308dbc7eb71d1ec2 Mon Sep 17 00:00:00 2001 From: NPScript Date: Sat, 9 Apr 2022 21:22:20 +0200 Subject: init commit --- .local/share/nvim/site/autoload/brackify.vim | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .local/share/nvim/site/autoload/brackify.vim (limited to '.local/share/nvim/site/autoload/brackify.vim') diff --git a/.local/share/nvim/site/autoload/brackify.vim b/.local/share/nvim/site/autoload/brackify.vim new file mode 100644 index 0000000..ca2a834 --- /dev/null +++ b/.local/share/nvim/site/autoload/brackify.vim @@ -0,0 +1,39 @@ +function! CharAtIdx(str, idx) abort + return strcharpart(a:str, a:idx, 1) +endfunction + +function! CursorCharIdx() abort + let cursor_byte_idx = col('.') + if cursor_byte_idx == 1 + return 0 + endif + + let pre_cursor_text = getline('.')[:col('.')-2] + return strchars(pre_cursor_text) +endfunction + +function brackify#putbracket(bracket) + let cur_char_idx = CursorCharIdx() + let cur_char = CharAtIdx(getline('.'), cur_char_idx + 1) + + if cur_char != a:bracket + let line = getline('.')[:col('.') - 1] . a:bracket . getline('.')[col('.'):] + call setline(line("."), line) + endif +endfunction + +function brackify#putquotes(quote) + let cur_char_idx = CursorCharIdx() + let cur_char = CharAtIdx(getline('.'), cur_char_idx + 1) + + if cur_char != a:quote + let line = getline('.')[:col('.') - 1] . a:quote . a:quote . getline('.')[col('.'):] + call setline(line("."), line) + + if col('.') > 1 + call cursor(getpos('.')[1], col('.') + 1) + endif + else + call cursor(getpos('.')[1], col('.') + 1) + endif +endfunction -- cgit v1.2.3-70-g09d2