Syntax highlighting in Bash vi-input mode
If I enable bash's input mode using set -o vi
, then press Esc followed by v, I get a vi window which allows me to edit a temporary file which is executed once I leave. In that window I would like to enjoy Vim syntax highlighting fo开发者_开发技巧r Bash scripts. It doesn't suffice to execute :syntax enable
. The problem might be related to the fact that the temporary file has no .sh
ending nor a #!/bin/bash
head which could be used to determine the filetype.
I'd use the shorter formulation:
au BufRead,BufNewFile bash-fc-* set filetype=sh
I believe this type of autocmd is the canonical way to handle filetype assignments (at least, my .vimrc has a number of them).
@Eric Fortis, please chime in or correct me if there's a reason you did it differently.
Add this to your .vimrc
if expand('%:t') =~?'bash-fc-\d\+'
setfiletype sh
endif
the temporary files are of the form bash-fc-3537253897
, so the regex matches if the file begins with bash-fc-
and applies the filetype.
精彩评论