Skip to content

Instantly share code, notes, and snippets.

@ujihisa
Created March 2, 2010 02:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ujihisa/656edb373364c2268940 to your computer and use it in GitHub Desktop.
Save ujihisa/656edb373364c2268940 to your computer and use it in GitHub Desktop.
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