-
-
Save ujihisa/656edb373364c2268940 to your computer and use it in GitHub Desktop.
This file contains 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
inoremap <buffer> <expr> ] CloseOrCompl() | |
function! CloseOrCompl() | |
if pumvisible() | |
return "\<C-n>" | |
endif | |
let a = GetCharsUntilHere() | |
let tmp = 0 | |
let in_string = 'no' | |
for i in reverse(range(0, len(a) - 1)) | |
if in_string != 'no' | |
if a[i] == in_string | |
let in_string = 'no' | |
else | |
" Ignore the contents of String literal | |
endif | |
elseif a[i] == '"' | |
let in_string = '"' | |
elseif a[i] == "'" | |
let in_string = "'" | |
elseif a[i] == ']' | |
let tmp += 1 | |
elseif a[i] == '[' | |
if tmp <= 0 | |
return ']' | |
else | |
let tmp -= 1 | |
endif | |
endif | |
endfor | |
return "\<C-n>" | |
endfunction | |
function! GetCharsUntilHere() | |
let [_, lnum, col, _] = getpos('.') | |
let a = getline(1, lnum - 1) | |
call add(a, getline(lnum)[:col-1]) | |
return join(a, "\n") | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment