gpt4 book ai didi

javascript - 如何将 jscs 自动修复功能集成到 vim 中?

转载 作者:数据小太阳 更新时间:2023-10-29 03:48:31 25 4
gpt4 key购买 nike

我正在尝试获取可以在 vim 中运行的命令以获取 jscs auto correct我的代码中的格式问题。到目前为止,我想出了:

:nmap <F5> :!jscs -x .<CR>

没问题,但它在整个目录上运行,我需要向 vim 确认我想重新加载缓冲区。有没有办法让 vim 仅修复当前文件并在不重新加载的情况下显示更改?

最佳答案

这将在您保存文件时通过 jscs 的修复模式传输当前文件(在实践中您的里程可能会有所不同!):

function! JscsFix()
"Save current cursor position"
let l:winview = winsaveview()
"Pipe the current buffer (%) through the jscs -x command"
% ! jscs -x
"Restore cursor position - this is needed as piping the file"
"through jscs jumps the cursor to the top"
call winrestview(l:winview)
endfunction
command! JscsFix :call JscsFix()

"Run the JscsFix command just before the buffer is written for *.js files"
autocmd BufWritePre *.js JscsFix

它还创建了一个命令 JscsFix您可以随时使用 :JscsFix 运行它.要将其绑定(bind)到 key (在本例中为 <leader>g ),请使用 noremap <leader>g :JscsFix<cr> .

关于javascript - 如何将 jscs 自动修复功能集成到 vim 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29819168/

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