Vim переключение между выделенным и невыделенным синтаксисом
Вот моя проблема:
- Я открываю файл с
vim /etc/file.toml
Синтаксис с подсветкой - Я редактирую и сохраняю
- Иногда (не каждый раз), когда я открываю файл позже, он больше не выделяется синтаксисом.
У кого-нибудь есть идеи, как решить эту проблему? Кеш проблема?
Обратите внимание: что эта проблема возникает практически с каждым расширением файла, я не переключаю пользователя (всегда root).
1 ответ
Попробуйте установить syntax enable
вместо syntax on
в вашем.vimrc.
Прямо из :h syntax
This command switches on syntax highlighting: >
:syntax enable
What this command actually does is to execute the command >
:source $VIMRUNTIME/syntax/syntax.vim
If the VIM environment variable is not set, Vim will try to find
the path in another way (see |$VIMRUNTIME|). Usually this works just
fine. If it doesn't, try setting the VIM environment variable to the
directory where the Vim stuff is located. For example, if your syntax files
are in the "/usr/vim/vim50/syntax" directory, set $VIMRUNTIME to
"/usr/vim/vim50". You must do this in the shell, before starting Vim.
*:syn-on* *:syntax-on*
The ":syntax enable" command will keep your current color settings. This
allows using ":highlight" commands to set your preferred colors before or
after using this command. If you want Vim to overrule your settings with the
defaults, use: >
:syntax on
Читайте здесь для получения дополнительной информации.
РЕДАКТИРОВАТЬ: После некоторого дополнительного исследования, я обнаружил, что если вышеупомянутое не работает, это потому, что плагин filetype для этого конкретного типа файла перезаписывает пользовательские настройки. Чтобы бороться с этим, вы можете создать новую папку с именем after
в вашей домашней папке vim. Каждый файл в after
Источник после любых файлов в /usr/share/vim74
, Структура after
должен соответствовать структуре папки папки vim74.
Чтобы было проще, я написал быстрый скрипт
#!/usr/bin/bash
# Make the after folders you need
mkdir -p $HOME/.vim/after/ftplugin
# Create the Global Settings file for syntax highlighting and formatting options
touch $HOME/.vim/after/fo_globals.vim
# Create links to the fo_globals file
for file in /usr/share/vim/vim74/ftplugin/*.vim
do
ln -s $HOME/.vim/after/fo_globals.vim $HOME/.vim/after/ftplugin/`basename $file`
done
Затем заполните файл globals с параметрами синтаксиса и форматирования. Моя выглядит так.
syntax enable
set formatoptions-=c
set formatoptions-=r
set formatoptions-=o
set autoindent
set smartindent
set nocindent
set backspace=indent,eol,start
set expandtab
set tabstop=4
set shiftwidth=4
set shiftround