终端 vim 中的语法高亮显示,但 gVIM 中没有

发布于 2024-09-30 03:18:57 字数 4727 浏览 7 评论 0原文

我目前在终端中使用 VIM,并且有完美的语法突出显示。但是当我尝试使用 gvim 时,无论什么类型的文件或输入多少次: ":syntax on" 我都没有得到任何语法突出显示。有人有什么想法吗?

谢谢。

这是我的 .vimrc 供有兴趣的人使用:

" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()

" My color theme for vim
colors sorcerer

" Disable line wrapping for now
set nowrap

" Enable the mouse even when vi is used in the terminal
set mouse=a

" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'

" This shows what you are typing as a command.  I love this!
set showcmd

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v

" Gimme some breathing room at the bottom please...
set scrolloff=5

" makes vim usable with screen
set restorescreen

" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>


"Kill error bells
set noerrorbells
set visualbell
set t_vb=

" Turn on spell check
" set spell

" Thesaurus!! 
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt

" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")

let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1

" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden

" Turn on incremental search
set incsearch
set smartcase

" Long history is long
set history=1000
set undolevels=1000

" No need for a vi backup file
set nobackup

" Colors!!
set t_Co=256

" Compatibility
set nocompatible

set formatprg=par

" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0

" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…

" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround

" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>

"allow backspacing over everything in insert mode
set backspace=indent,eol,start

set showmode "show current mode down the bottom

"Setting the status line...

set statusline=%f       "tail of the filename

"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*

"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*

set statusline+=%h      "help file flag
set statusline+=%y      "filetype
set statusline+=%r      "read only flag
set statusline+=%m      "modified flag

"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*


" Auto completion options
set wildmode=list:longest  "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete

"display tabs and trailing spaces
set list

" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•


let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i

command W w !sudo tee % > /dev/null

" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*


" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'

filetype on        " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.


" VIM 7.3 features here...
if v:version >= 703
    set relativenumber
    set undofile
endif

I am currently using VIM in the terminal and have perfect syntax highlighting happening. But then when I try to use gvim no matter what type of file or how many times I type: ":syntax on" I don't get any syntax highlighting. Any ideas anyone?

Thank you.

Here is my .vimrc for those who are interested:

" Turn on pathogen for all plug-ins installed after 9/13/2010
call pathogen#helptags()
call pathogen#runtime_append_all_bundles()

" My color theme for vim
colors sorcerer

" Disable line wrapping for now
set nowrap

" Enable the mouse even when vi is used in the terminal
set mouse=a

" Since I use linux, I want this
let g:clipbrdDefaultReg = '+'

" This shows what you are typing as a command.  I love this!
set showcmd

" Automatically cd into the directory that the file is in
autocmd BufEnter * execute "chdir ".escape(expand("%:p:h"), ' ')

"Fix Vim's regex...
nnoremap / /\v
vnoremap / /\v

" Gimme some breathing room at the bottom please...
set scrolloff=5

" makes vim usable with screen
set restorescreen

" Disable the arrow keys... helps the learning
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>


"Kill error bells
set noerrorbells
set visualbell
set t_vb=

" Turn on spell check
" set spell

" Thesaurus!! 
set thesaurus+=/usr/share/myspell/dicts/mthesaur.txt

" Some NERDTree love
let NERDTreeBookmarksFile=expand("$HOME/.vim/NERDTreeBookmarks")

let NERDTreeShowBookmarks=1
let NERDTreeQuitOnOpen=1
let NERDTreeHighlightCursorline=1
let NERDTreeShowFiles=1
let NERDTreeShowHidden=1

" Make swapping windows easier...
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Allow for buffers to be hidden so that they need not be closed to go to
" another file
set hidden

" Turn on incremental search
set incsearch
set smartcase

" Long history is long
set history=1000
set undolevels=1000

" No need for a vi backup file
set nobackup

" Colors!!
set t_Co=256

" Compatibility
set nocompatible

set formatprg=par

" Syntastic!!
let g:syntastic_enable_signs=1
let g:syntastic_auto_loclist=1
let g:syntastic_quiet_warnings=0

" For soft wrapping text
command! -nargs=* Wrap set wrap linebreak nolist
set showbreak=…

" Sandro spacing preferences here
set number
set expandtab
set autoindent
set smartindent
set softtabstop=4
set shiftwidth=4
set shiftround

" Sandro key mapping here
map <F2> :NERDTreeToggle<CR>

"allow backspacing over everything in insert mode
set backspace=indent,eol,start

set showmode "show current mode down the bottom

"Setting the status line...

set statusline=%f       "tail of the filename

"display a warning if the file format isn't Unix
set statusline+=%#warningmsg#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*

"display a warning if file encoding isn't UTf-8
set statusline+=%#warningmsg#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*

set statusline+=%h      "help file flag
set statusline+=%y      "filetype
set statusline+=%r      "read only flag
set statusline+=%m      "modified flag

"Syntastic!!
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*


" Auto completion options
set wildmode=list:longest  "Change tab completion to be like Bash's
set wildignore=*.o,*.obj,*~,*.swp,*.pyc "Files to ignore on auto complete

"display tabs and trailing spaces
set list

" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\•,extends:»,precedes:«,trail:•


let g:pydiction_location='~/.vim/after/ftplugin/pydiction/complete-dict'
set sm
set ai
let java_highlight_all=1
let java_highlight_functions="style"
let java_allow_cpp_keywords=1
set tags=~/.tags
set complete=.,w,b,u,t,i

command W w !sudo tee % > /dev/null

" IMPORTANT: win32 users will need to have 'shell slash' set so that latex
" can be called correctly.
"set shell slash

" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to always generate a file-name.
"set grepprg=grep\ -nH\ $*


" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
" let g:tex_flavor='latex'

filetype on        " enables filetype detection
filetype plugin on " enables filetype specific plug-ins
syntax on
filetype indent on " OPTIONAL: This enables automatic indentation as you type.


" VIM 7.3 features here...
if v:version >= 703
    set relativenumber
    set undofile
endif

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

草莓酥 2024-10-07 03:18:57
  1. 使用 :let g:colors_name 查看已加载的颜色方案的名称,该值应该是 'sorcerer',如果不是,则出现严重错误
    • 输入 :hi Operator,您的“xxx”部分应该带有颜色,并且您应该在输出中看到 guifg=
    • .vimrc 顶部添加一个新行,仅包含单词“finish”,这将停止 vim 处理您的 .vimrc。使用 :colors default:syntax on 应该足以打开语法突出显示。如果这有效,那么只需将 finish 行向下移动到 .vimrc 中,直到找到破坏语法突出显示的部分。
    • 在 Windows 上,gVim 使用名为 _vimrc 的文件,因此也请检查该文件。
  1. Use :let g:colors_name to see the name of the colourscheme that has been loaded, the value should be 'sorcerer', if it's not then something has gone seriously wrong
    • Type :hi Operator, you 'xxx' part should be coloured and you should see guifg=<color> in the output.
    • Put a new line at the top of your .vimrc containing just the word "finish", this will stop vim processing your .vimrc. Using :colors default and :syntax on should be enough to get syntax highlighting turned on. If this works then just move the finish line down through your .vimrc until you find the section that is breaking syntax highlighting.
    • On windows, gVim uses a file called _vimrc, so check for that as well.
绻影浮沉 2024-10-07 03:18:57

当你在 gvim 中输入 :version 时,你会看到 +syntax 列在你的功能列表中吗?

尝试将其与常规 Vim 版本进行比较。也许您的 gvim 版本不包含语法突出显示功能。

When you type :version in gvim do you see +syntax listed in your features list?

Try comparing that to your regular Vim version. Maybe your gvim build didn't include the syntax highlighting feature.

剩一世无双 2024-10-07 03:18:57

当我最终弄清楚如何获取 gvim 7.3 后,问题就得到了解决。然后语法高亮就神奇地出现了。

The issue was fixed once I finally figured out how to get gvim 7.3. Then the syntax highlighting magically came.

孤单情人 2024-10-07 03:18:57

基于 Thien 的回应,我也有同样的经历(set syntax=on 失败,菜单选项成功,但只有在 Vim 重新启动后才会成功)。

菜单选项显然会触发 :syn=on,将其添加到 _vimrc 确实会持续启用语法高亮,而 set syntax=on 则没有。我将把它留给有更多经验的人来解释这两者之间的区别。

Building on Thien's response, I also had the same experience (set syntax=on fails, the menu options succeed but only until Vim is restarted).

The menu option apparently triggers :syn=on, and adding that to _vimrc does enable syntax highlighting persistently where set syntax=on did not. I'll leave it to someone with more experience to explain the difference between those two.

来世叙缘 2024-10-07 03:18:57

set syntax=xxx 在 Windows XP 上的 gvim 7.3 中对我不起作用,尽管它在 cygwin 中的 vim 中起作用。要获得语法突出显示,我必须转到 Menu >语法>在菜单中显示文件类型 >选择语法。我猜想菜单命令和 vim 命令在 Windows 上与 gvim 做的事情不一样。

set syntax=xxx was not working for me in gvim 7.3 on Windows XP although it did for vim in cygwin. To get syntax highlighting I had to go to Menu > Syntax > Show filetypes in menu > select syntax. I guess the menu command and the vim commands don't do the same thing with gvim on Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文