19 Jan 2014 21:42:35

Vim autocomplete, template paster extension

Данное расширение позволяет вставлять заготовки кода по хоткеям, также автодополняет кавычки, скобки и преносы фигурных скобок согласно заданному codestyle
 
" All autocompelte logic defined here.

if exists("g:InterfaceAutocompleteInit")
  if (g:InterfaceAutocompleteInit == 1)
    finish
  endif
endif

let g:InterfaceAutocompleteInit = 1

" Enter \r & spaces by need.
function! CleverBackSpace()
  imap  <BS> <BS>
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:prevChar = strpart(a:lineContent, (a:pos[2] - 2), 1)
  echo a:currentChar
  echo a:prevChar
  if (a:prevChar == '(' && a:currentChar == ')')
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<DEL>\<BS>"
  elseif (a:prevChar == "'" && a:currentChar == "'")
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<DEL>\<BS>"
  elseif (a:prevChar == '"' && a:currentChar == '"')
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<DEL>\<BS>"
  elseif (a:prevChar == '{' && a:currentChar == '}')
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<DEL>\<BS>"
  elseif (a:prevChar == '[' && a:currentChar == ']')
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<DEL>\<BS>"
  else
    imap  <BS> <C-R>=CleverBackSpace()<CR>
    return "\<BS>"
  endif
endfunction

" Enter \r & spaces by need.
function! CleverEnter()
  if exists('g:completionaActivated') && g:completionaActivated == 1
    let g:completionaActivated = 0
    return "\<CR>"
  endif
  imap <silent> <CR> <CR>
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  if (a:currentChar == ')' || a:currentChar == ']'
  \ || a:currentChar == '}')
    imap <silent> <CR> <C-R>=CleverEnter()<CR>
    return "\<cr>.\<cr>\<UP>\<DEL>\<SPACE>\<SPACE>"
  else
    if (a:currentChar == '')
      imap <silent> <CR> <C-R>=CleverEnter()<CR>
      return "\<right>\<cr>\<right>"
    else
      imap <silent> <CR> <C-R>=CleverEnter()<CR>
      return "\<cr>\<right>"
    endif
  endif
endfunction

" Provides array insert function
function! ArrayInput()
  imap <silent> [ [

  " Get next, current & newline chars.
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  let a:isSpace =  a:currentChar == " "
  let a:nextCharNL =  a:nextChar == ""

  " Insert characters.
  if (and(strlen(a:currentChar) > 0, !a:isSpace))
    if (and(a:currentChar != '[', a:currentChar != ']'))
      imap <silent> [ <C-R>=ArrayInput()<CR>
      return "["
    else
      imap <silent> [ <C-R>=ArrayInput()<CR>
      return "["
    endif
  elseif (or(a:currentChar == ' ', a:nextCharNL))
    imap <silent> [ <C-R>=ArrayInput()<CR>
    return "[]\<LEFT>"
  endif

endfunction

function! ColumnInput()
  imap <silent> ( (

  " Get next, current & newline chars.
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  let a:isSpace =  a:currentChar == " "
  let a:nextCharNL =  a:nextChar == ""

  " Insert characters.
  if (and(strlen(a:currentChar) > 0, !a:isSpace))
    if (and(a:currentChar != '(', a:currentChar != ')'))
      imap <silent> ( <C-R>=ColumnInput()<CR>
      return "("
    else
      imap <silent> ( <C-R>=ColumnInput()<CR>
      return "("
    endif
  elseif (or(a:currentChar == ' ', a:nextCharNL))
    imap <silent> ( <C-R>=ColumnInput()<CR>
    return "()\<LEFT>"
  endif

endfunction

function! ObjectInput()
  imap <silent> { {

  " Get next, current & newline chars.
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  let a:isSpace =  a:currentChar == " "
  let a:nextCharNL =  a:nextChar == ""

  " Insert characters.
  if (and(strlen(a:currentChar) > 0, !a:isSpace))
    if (and(a:currentChar != '{', a:currentChar != '}'))
      imap <silent> { <C-R>=ObjectInput()<CR>
      return "{"
    else
      imap <silent> { <C-R>=ObjectInput()<CR>
      return "{"
    endif
  elseif (or(a:currentChar == ' ', a:nextCharNL))
    imap <silent> { <C-R>=ObjectInput()<CR>
    return "{}\<LEFT>"
  endif

endfunction

function! QouteInput()
  imap <silent> ' '

  " Get next, current & newline chars.
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  let a:isSpace =  a:currentChar == " "
  let a:nextCharNL =  a:nextChar == ""

  " Insert characters.
  if (and(strlen(a:currentChar) > 0, !a:isSpace))
    if (a:currentChar == "]" || a:currentChar == ")" || a:currentChar == "}")
      imap <silent> ' <C-R>=QouteInput()<CR>
      return "''\<LEFT>"
    elseif (a:currentChar != "'")
      imap <silent> ' <C-R>=QouteInput()<CR>
      return "'"
    else
      imap <silent> ' <C-R>=QouteInput()<CR>
      return "'"
    endif
  elseif (or(a:currentChar == ' ', a:nextCharNL))
    imap <silent> ' <C-R>=QouteInput()<CR>
    return "''\<LEFT>"
  endif

endfunction

function! DQouteInput()
  imap <silent> " "

  " Get next, current & newline chars.
  let a:pos = getpos(".")
  let a:lineContent = getline(a:pos[1])
  let a:currentChar = strpart(a:lineContent, (a:pos[2] - 1), 1)
  let a:nextChar = strpart(a:lineContent, (a:pos[2]), 1)
  "let curCharNL =  currentChar == ""
  let a:isSpace =  a:currentChar == " "
  let a:nextCharNL =  a:nextChar == ""

  " Insert characters.
  if (and(strlen(a:currentChar) > 0, !a:isSpace))
    if (a:currentChar == "]" || a:currentChar == ")" || a:currentChar == "}")
      imap <silent> ' <C-R>=QouteInput()<CR>
      return "\"\"\<LEFT>"
    elseif (a:currentChar != "\"")
      imap <silent> " <C-R>=DQouteInput()<CR>
      return "\""
    else
      imap <silent> " <C-R>=DQouteInput()<CR>
      return "\""
    endif
  elseif (or(a:currentChar == " ", a:nextCharNL))
    imap <silent> " <C-R>=DQouteInput()<CR>
    return "\"\"\<LEFT>"
  endif

endfunction
" All window related logic defined here.

if exists("g:InterfaceTempatesInit")
  if (g:InterfaceTempatesInit == 1)
    finish
  endif
endif

let g:InterfaceTempatesInit = 1

function! Php_if()
  return "yiWoif \<c-r>=ColumnInput()\<cr>!empty\<c-r>=ColumnInput()\<cr>pA)
\ \<c-r>=ObjectInput()\<cr>\<c-r>=CleverEnter()\<cr>"
endfunction

function! Php_comment()
  return "i/**
 * Preprocess variables/€kb.
*/€ku€kr"
endfunction

function! Php_html_if()
  return "i<php€kb€kb€kb?o€kbphp if \<c-r>=ColumnInput()\<cr>€kr: ?>
<?php enfi€kb€kbdif; ?>€kl€kl€kl€kl€kl€kl€ku€kr"
endfunction

function! Php_tag()
  return "i<?php ?>€kl€kl"
endfunction

function! Php_foreach()
  return "oforeach \<c-r>=ColumnInput()\<cr>$ as $€kr \<c-r>=ObjectInput()
\ \<cr>\<c-r>=CleverEnter()\<cr>€ku€kr€kr€kr€kr€kr€kr€kr€kr"
endfunction

 

if exists("g:InterfaceBindsInit")
  if (g:InterfaceBindsInit == 1)
    finish
  endif
endif

let g:InterfaceBindsInit = 1

"Mappings.
imap <silent> [ <C-R>=ArrayInput()<CR>
imap <silent> ( <C-R>=ColumnInput()<CR>
imap <silent> { <C-R>=ObjectInput()<CR>
imap <silent> ' <C-R>=QouteInput()<CR>
imap <silent> " <C-R>=DQouteInput()<CR>
imap <silent> <CR> <C-R>=CleverEnter()<CR>
imap  <BS> <C-R>=CleverBackSpace()<CR>
nmap 8t @=Php_foreach()<CR>
nmap 8p @=Php_tag()<CR>
nmap 8i @=Php_html_if()<CR>
nmap 8I @=Php_if()<CR>
nmap 8c @=Php_comment()<CR>
nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>
nmap cp :let @" = expand("%")<CR>
nnoremap <S-F4> :%s/\s\+$//<CR>
nnoremap <S-F3> :!tail -n 30 /var/log/httpd/error.log <CR>

Comments:

Pavel Ruban
эй ты, шпион вылазь!
15 апр 2013 в 01:15
Pavel Ruban
ага! попался негодник!
15 апр 2013 в 01:16
PavlikRuban
Вот он, вот он! Знаменитый 40-сорокасантиметровый скрипт! Ты все еще надеешься привлечь им самок?
20 мая 2013 в 20:36
аноним
If your flight is late, the window of time for airport staff to transfer your bag from a single plane for the subsequent narrows. Cheap Ray Ban Sunglasses http://diaryofdaedalus.com/author/panoftheforest/
22 июл 2013 в 16:12
аноним
dzewwqbwfmsvcbo, http://www.txtgfvwgva.com/ lfmkyyqjqi
25 янв 2014 в 10:28
аноним
bhshyqbwfmsvcbo, <a href="http://www.bzlybyvhwt.com/">qkwpwsngjd</a> , [url=http://www.yfjcndxabe.com/]pvymceuowv[/url], http://www.citxnksvsk.com/ qkwpwsngjd
30 янв 2014 в 11:46

add comment

Image CAPTCHA