VIm function that runs file through shfmt
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I've written a Vim function that formats the file using shfmt. I'd like to know if there is a way I can improve this script.
I am bothered by the fact that I can't think of a way to do this without editing the file in the subprocess and reloading the file. Is there a way to do the equivalent of %!shfmt -options
?
if exists("g:loaded_shfmt") || &compatible || ! executable('shfmt')
finish
endif
let s:save_cpoptions = &cpoptions
set cpoptions&vim
let s:switches = join(['-w', '-s', '-i', '2', '-bn', '-ci', '-sr'])
function! s:shFormat()
let l:filename = @%
let l:out = system('shfmt ' . s:switches . ' ' . l:filename)
edit!
endfunction
nnoremap <silent> <Leader>fb :call <SID>shFormat()<CR>
let &cpoptions = s:save_cpoptions
let g:loaded_shfmt = 1
formatting child-process vimscript
add a comment |Â
up vote
2
down vote
favorite
I've written a Vim function that formats the file using shfmt. I'd like to know if there is a way I can improve this script.
I am bothered by the fact that I can't think of a way to do this without editing the file in the subprocess and reloading the file. Is there a way to do the equivalent of %!shfmt -options
?
if exists("g:loaded_shfmt") || &compatible || ! executable('shfmt')
finish
endif
let s:save_cpoptions = &cpoptions
set cpoptions&vim
let s:switches = join(['-w', '-s', '-i', '2', '-bn', '-ci', '-sr'])
function! s:shFormat()
let l:filename = @%
let l:out = system('shfmt ' . s:switches . ' ' . l:filename)
edit!
endfunction
nnoremap <silent> <Leader>fb :call <SID>shFormat()<CR>
let &cpoptions = s:save_cpoptions
let g:loaded_shfmt = 1
formatting child-process vimscript
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I've written a Vim function that formats the file using shfmt. I'd like to know if there is a way I can improve this script.
I am bothered by the fact that I can't think of a way to do this without editing the file in the subprocess and reloading the file. Is there a way to do the equivalent of %!shfmt -options
?
if exists("g:loaded_shfmt") || &compatible || ! executable('shfmt')
finish
endif
let s:save_cpoptions = &cpoptions
set cpoptions&vim
let s:switches = join(['-w', '-s', '-i', '2', '-bn', '-ci', '-sr'])
function! s:shFormat()
let l:filename = @%
let l:out = system('shfmt ' . s:switches . ' ' . l:filename)
edit!
endfunction
nnoremap <silent> <Leader>fb :call <SID>shFormat()<CR>
let &cpoptions = s:save_cpoptions
let g:loaded_shfmt = 1
formatting child-process vimscript
I've written a Vim function that formats the file using shfmt. I'd like to know if there is a way I can improve this script.
I am bothered by the fact that I can't think of a way to do this without editing the file in the subprocess and reloading the file. Is there a way to do the equivalent of %!shfmt -options
?
if exists("g:loaded_shfmt") || &compatible || ! executable('shfmt')
finish
endif
let s:save_cpoptions = &cpoptions
set cpoptions&vim
let s:switches = join(['-w', '-s', '-i', '2', '-bn', '-ci', '-sr'])
function! s:shFormat()
let l:filename = @%
let l:out = system('shfmt ' . s:switches . ' ' . l:filename)
edit!
endfunction
nnoremap <silent> <Leader>fb :call <SID>shFormat()<CR>
let &cpoptions = s:save_cpoptions
let g:loaded_shfmt = 1
formatting child-process vimscript
edited Jul 30 at 5:31
200_success
123k14143398
123k14143398
asked Jul 30 at 0:36
harleypig
1185
1185
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f200562%2fvim-function-that-runs-file-through-shfmt%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password