Wil*_*unn 9 javascript vim jscs
我正在尝试获取一个命令,我可以在vim中运行,以便在我的代码中使jscs自动纠正格式化问题.到目前为止,我想出了:
: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.将它绑定到一个键(在这种情况下<leader>g)使用noremap <leader>g :JscsFix<cr>.
| 归档时间: | 
 | 
| 查看次数: | 914 次 | 
| 最近记录: |