mattn / emmet-vim

emmet for vim: http://emmet.io/
http://mattn.github.io/emmet-vim
MIT License
6.38k stars 410 forks source link

In gvim, some problem with "expand tag" #202

Open wslx520 opened 10 years ago

wslx520 commented 10 years ago

In 'insert mode', and with filetype is html,but some css code in it.

1, I typed some code and keep 'insert mode',press the expand keys, it will be worked but sometimes, some extra letter will be added. For example:

div

when expanded it will become:

<divs></divs>

just sometimes.but where is the 's' from?! why?

2,and then I move cursor into <style> tags, typed some emmet css code like : tl:l , and expand,it will become <tl:l></tl:l> but not actual css codes.

But,all problems above would not appeared in 'normal mode',it says, if I typed code and press 'ESC' to normal mode,then press expand keys( same keys like above), all are worked perfect! no problems!

can you tell me why ? or how could I jump over these problems?

mattn commented 10 years ago

What other plugins are you using?

wslx520 commented 10 years ago

minibufexpl.vim, multiple_cursors.vim,nerd_commenter.vim. etc

mattn commented 10 years ago

Please note here all. Especially, plugins for input completion if you are using.

wslx520 commented 10 years ago

I re-install a new VIM, and download the zip file from vim.org,then unzip it to my vim directory to cover the same names folder,but no one more other plugin,just this, but the same problem appeared too...I don't know how continue..

mattn commented 10 years ago

What version of vim do you use?

wslx520 commented 10 years ago

Now I use 7.4,yestoday is 7.3,but both of them has the same problem

mattn commented 10 years ago

Could you please show me your vimrc?

wslx520 commented 10 years ago

sure,tks,I set the 'expand' key to ctrl+k,any problem for it?

set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

" emmet plugin
let g:user_emmet_expandabbr_key = '<c-k>'
set diffexpr=MyDiff()
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let eq = ''
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      let cmd = '""' . $VIMRUNTIME . '\diff"'
      let eq = '"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
endfunction
"自定义设置开始
"Windows系统下上一语句修改为
set rtp+=$VIM/vimfiles/bundle/vundle/
call vundle#rc()

 " 让 Vundle 管理 Vundle
 " 此条必须有
 Bundle 'gmarik/vundle'
 "
 " 代码源在 github 上的

 " 代码存放在其他地方
 "Bundle 'git://git.wincent.com/command-t.git'
 " ...

 filetype plugin indent on     " 必须有
 "
 " Brief help
 " :BundleList          - list configured bundles
 " :BundleInstall(!)    - install(update) bundles
 " :BundleSearch(!) foo - search(or refresh cache first) for foo
 " :BundleClean(!)      - confirm(or auto-approve) removal of unused bundles
 "
 " see :h vundle for more details or wiki for FAQ
 " NOTE: comments after Bundle command are not allowed..
set nu!
"配色方案
colorscheme desert
"语法高亮度显示
syntax on
"显示行号
set number tabstop=4
"检测文件类型
filetype on
"vim使用自动对齐,也就是把当前行的对齐格式应用到下一行
set autoindent
"依据上面的对齐格式,只能的选择对齐方式
set smartindent
"设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
"当vim进行编辑时,如果命令错误,会发出一个响声,该设置去掉响声
set vb t_vb=
"在编辑过程中,在右下角显示光标位置的状态行
set ruler
"设置游标
set cursorline
" 取消备份。  
" Turn backup off, since most stuff is in SVN, git et.c anyway...  
set nobackup  
set nowb  
set noswapfile 
autocmd! bufwritepost _vimrc source % " vimrc文件修改之后自动加载。 windows。
"找要匹配的单词。eg:如果要查找search单词,当输入到/s(回车确认选择)时,会自动找到第一个s开头的单词 
set incsearch
"设置字体和大小
set guifont=Monaco:h12:b:cDEFAULT
"在浏览器中打开网页
" 在浏览器预览 for win32
function! ViewInBrowser(name)
    let file = expand("%:p")
    exec ":update " . file
    let l:browsers = {
        \"cr":"C:/Program Files (x86)/Google/Chrome/Application/Chrome.exe",
        \"ff":"D:/Program Files (x86)/Mozilla Firefox/Firefox.exe",
        \"op":"D:/WebDevelopment/Browser/Opera/opera.exe",
        \"ie":"C:/progra~1/intern~1/iexplore.exe",
        \"ie6":"D:/Program Files/IE6.exe"
    \}
    let htdocs='E:\\xampp\\htdocs\\'
    let strpos = stridx(file, substitute(htdocs, '\\\\', '\', "g"))
    if strpos == -1
       exec ":silent !start ". l:browsers[a:name] ." file://" . file
    else
        let file=substitute(file, htdocs, "http://localhost/", "g")
        let file=substitute(file, '\\', '/', "g")
        exec ":silent !start ". l:browsers[a:name] file
    endif
endfunction
nmap <f4>cr :call ViewInBrowser("cr")<cr>
nmap <f4>ff :call ViewInBrowser("ff")<cr>
nmap <f4>op :call ViewInBrowser("op")<cr>
nmap <f4>ie :call ViewInBrowser("ie")<cr>
nmap <f4>ie6 :call ViewInBrowser("ie6")<cr>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim7.1在windows下的编码设置。By Huadong.Liu
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32")
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"解决菜单乱码
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
"解决consle输出乱码
language messages zh_CN.utf-8
"多文件编辑,minibufexpl.vim
let g:miniBufExplMapCTabSwitchBufs=1
let g:miniBufExplMapWindowsNavVim=1
let g:miniBufExplMapWindowNavArrows=1
"let g:user_emmet_mode='n'    "only enable normal mode functions.

let g:user_emmet_settings = {
\ 'php' : {
\ 'extends' : 'html',
\ 'filters' : 'c',
\ },
\ 'xml' : {
\ 'extends' : 'html',
\ },
\ 'haml' : {
\ 'extends' : 'html',
\ },
\}
"自动补全
inoremap ( ()<LEFT>
inoremap [ []<LEFT>
inoremap { {}<LEFT>
inoremap ' ''<LEFT>
inoremap " ""<LEFT>
" 按退格键时判断当前光标前一个字符,如果是左括号,则删除对应的右括号以及括号中间的内容
function! RemovePairs()
    let l:line = getline(".")
    let l:previous_char = l:line[col(".")-1] " 取得当前光标前一个字符

    if index(["(", "[", "{"], l:previous_char) != -1
        let l:original_pos = getpos(".")
        execute "normal %"
        let l:new_pos = getpos(".")

        " 如果没有匹配的右括号
        if l:original_pos == l:new_pos
            execute "normal! a\<BS>"
            return
        end

        let l:line2 = getline(".")
        if len(l:line2) == col(".")
            " 如果右括号是当前行最后一个字符
            execute "normal! v%xa"
        else
            " 如果右括号不是当前行最后一个字符
            execute "normal! v%xi"
        end

    else
        execute "normal! a\<BS>"
    end
endfunction
" 用退格键删除一个左括号时同时删除对应的右括号
inoremap <BS> <ESC>:call RemovePairs()<CR>a
" 输入一个字符时,如果下一个字符也是括号,则删除它,避免出现重复字符
function! RemoveNextDoubleChar(char)
    let l:line = getline(".")
    let l:next_char = l:line[col(".")] " 取得当前光标后一个字符

    if a:char == l:next_char
        execute "normal! l"
    else
        execute "normal! i" . a:char . ""
    end
endfunction
inoremap ) <ESC>:call RemoveNextDoubleChar(')')<CR>a
inoremap ] <ESC>:call RemoveNextDoubleChar(']')<CR>a
inoremap } <ESC>:call RemoveNextDoubleChar('}')<CR>a

"自动打开上次关闭vim时编辑的文件
" Go to last file(s) if invoked without arguments.
autocmd VimLeave * nested if (!isdirectory($HOME . "/.vim")) |
    \ call mkdir($HOME . "/.vim") |
    \ endif |
    \ execute "mksession! " . $HOME . "/.vim/Session.vim"

autocmd VimEnter * nested if argc() == 0 && filereadable($HOME . "/.vim/Session.vim") |
    \ execute "source " . $HOME . "/.vim/Session.vim"
wslx520 commented 10 years ago

I think I catch the problem,I change the keys to ctrl-h and all of problems have gone! Is this the reason?

mattn commented 10 years ago

Could you please show me a result of?:

:verbose map <c-k>
wslx520 commented 10 years ago

if I set keys to,run your code will show: v (EmmetExpandAbbr) ... D:\VIM\vim74\plugin\emmet.vim n (EmmetExpandAbbr) ... D:\VIM\vim74\plugin\emmet.vim

two results.

and I'm sorry to tell you, problem still at there,even I don't set any keys and use the defaults. for example:

a:active{ c|}

(cursor is at '|'),now expand,it will become: a:active{ caption-side: ;}

and keep this status,I back to normal mode,press u,it will become: a:active{ ca}

now you can see here has a extra letter:'a', this cause expand action to wrong way.

sometimes the extra letter will not be 'a', probably is 'n' or others.

and also, when do expand at normal mode,its run perfect.

mattn commented 10 years ago

Hmm, I can't reproduce it. I get same correct results.

wslx520 commented 10 years ago

I found a strange stuff in my gVim,I know where the extra letter from. when I expand, my vim will pick a letter from the line next to the current line and push to the current cursor point. like this:

body { c| }
#wrap{position:relative....

when expand, it will pick the 'o' in 'position' to c and so problem comes.

What a devil! If the next position of cursor in the next line is blank, the expand action will run with no mistake.

I just use vim a week, can you tell me the possible reason of this?

mattn commented 10 years ago

I don't know the reason, sorry.

wslx520 commented 10 years ago

oh,that so I have to find way myself.Thank you, If you find the reason,please tell me

antoinemichaud commented 9 years ago

Hello, i've got the same issue as wslx520.

antoinemichaud commented 9 years ago

Actually, this happens when another tag is in the next line of the currently edited one. But if the next line is blank, this doesn't happen.

And this not occurs only in GVim, but in vim as well.

mattn commented 9 years ago

@antoinemichaud what plugins anothers you use? for example auto-completion plugin?

xinyyl commented 9 years ago

I found the reason. See ement.vim of line 165 the <c-e> operation will copy the next line charaset to current position then press <c-r> =emmet#expandAbbr

i remove the <c-e> commond. then i fixed the problem sorry. I am not good at English.

mattn commented 9 years ago

Could you please point the location by github URL? I can't find L165.

xinyyl commented 9 years ago

i download the plugin from vim.org
maybe it fixed on github.
, could you update for vim.org?

mattn commented 9 years ago

Done. I'll close this after few days without any response.