gpt4 book ai didi

css - Vim - Css 光标位置

转载 作者:行者123 更新时间:2023-11-28 10:56:09 25 4
gpt4 key购买 nike

从这个问题开始 HTML cursor position

按 ENTER 展开 css 时如何获得正确的光标位置。

评论部分是我尝试更新函数以使其也适用于 css 的失败尝试。

function! Expander()
let line = getline(".")
let col = col(".")
let first = line[col-2]
let second = line[col-1]
let third = line[col

if first ==# ">"
if second ==# "<" && third ==# "/"
return "\<CR>\<C-o>==\<C-o>O"

else
return "\<CR>"

endif
"else if first ==# "{"
"if second ==# "}"
"return "\<CR>\<C-o>==\<C-o>O"

else
return "\<CR>"

endif

endfunction

我对有或没有该功能的解决方案持开放态度。 emmet 和 sparkup 等插件非常适合从缩写文本创建 html,但不能解决这个简单的问题。

我希望光标在输入时位于此处。

#SomeID {
|
}

最佳答案

这是我在链接答案中提出的功能的扩展版本。它试图扩展 () , {} , []<tag></tag> .

" the main function
function! SmartEnter()
" beware of the cmdline window
if &buftype == "nofile"
return "\<CR>"
endif

" get the character on the left of the cursor
let previous = getline(".")[col(".")-2]

" get the character on the right of the cursor
let next = getline(".")[col(".")-1]

" do the right thing
if previous ==# "{"
return PairExpander(previous, "}", next)
elseif previous ==# "["
return PairExpander(previous, "]", next)
elseif previous ==# "("
return PairExpander(previous, ")", next)
elseif previous ==# ">"
return TagExpander(next)
else
return "\<CR>"
endif
endfunction

" expands {}, (), []
function! PairExpander(left, right, next)
let pair_position = searchpairpos(a:left, "", a:right, "Wn")
if a:next !=# a:right && pair_position[0] == 0
return "\<CR>" . a:right . "\<C-o>==\<C-o>O"
elseif a:next !=# a:right && pair_position[0] != 0 && indent(pair_position[0]) != indent(".")
return "\<CR>" . a:right . "\<C-o>==\<C-o>O"
elseif a:next ==# a:right
return "\<CR>\<C-o>==\<C-o>O"
else
return "\<CR>"
endif
endfunction

" expands <tag></tag>
function! TagExpander(next)
if a:next ==# "<" && getline(".")[col(".")] ==# "/"
if getline(".")[searchpos("<", "bnW")[1]] ==# "/" || getline(".")[searchpos("<", "bnW")[1]] !=# getline(".")[col(".") + 1]
return "\<CR>"
else
return "\<CR>\<C-o>==\<C-o>O"
endif
else
return "\<CR>"
endif
endfunction

关于css - Vim - Css 光标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22597768/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com