如何在命令行中放置占位符

时间:2015-10-29 11:05:21

标签: vim

实施例: 在我的.vimrc

vmap <leader>ii :EasyAlign<Space>((Some hint what to type))

按下<leader>ii后,我在命令行:EasyAlign<Space>((Some hint what to type))中显示此内容当我开始自动输入(new text)时,它会取代((Some hint what to type))

像html中的占位符:

<input type="text" name="fname" placeholder="First name"><br>

1 个答案:

答案 0 :(得分:4)

我所知道的并不相似。它可以模拟到某一点,例如:

function! Prompt(prompt, hint)
  echo a:prompt . a:hint
  let c = getchar()
  if type(c)
    " if a special key (like e.g. cursor keys), clear the hint, ignore the key
    call feedkeys(a:prompt)
  elseif c == 27
    " Esc cancels the whole thing, clears the prompt
    redraw!
  else
    " Feed the prompt and the first key to Vim
    call feedkeys(a:prompt . nr2char(c))
  endif
endfunction

vmap <leader>ii :<C-U>call Prompt(":'<,'>EasyAlign ", "(some hint here)")<CR>

(在地图中,V模式中仅:会为您提供:'<,'>;因此我们会删除<C-U>的范围,并且必须在提示中将其恢复)

(编辑以涵盖getchar返回<Left>之类的字符串时的情况