【问题标题】:Vim Question: Sparkup doesn't work for files opened from a running Vim sessionVim 问题:Sparkup 不适用于从正在运行的 Vim 会话打开的文件
【发布时间】:2011-02-05 11:09:20
【问题描述】:

如果我用 Vim 从命令提示符打开一个文件(例如:vim ~/.vimrc),Sparkup 文本生成似乎工作得很好。例如,如果我插入:

html:xs

然后按下 control + e,sparkup 会生成一个漂亮的 HTML 严格样板。但是,如果我从正在运行的 Vim 会话中拆分到另一个文件,Sparkup 将停止在新打开的文件中工作。其他插件也完全有可能失去其功能。这是我的 .vimrc 文件:

set nocompatible    " use vim defaults
set number          " show line numbers
set tags=tags;$HOME/.vim/tags/ "recursively searches directory for 'tags' file
set expandtab       " tabs are converted to spac
set tabstop=4       " numbers of spaces of tab character
set shiftwidth=4    " numbers of spaces to (auto)indent
set showcmd         " display incomplete commands
set incsearch       " do incremental searching
set ruler           " show the cursor position all the time
set numberwidth=4   " line numbering takes up 5 spaces
set ignorecase      " ignore case when searching
set nowrap          " stop lines from wrapping
set incsearch       " show search matches as you type

call pathogen#helptags()
call pathogen#runtime_append_all_bundles()

filetype on            " enables filetype detection
filetype plugin on     " enables filetype specific plugins
filetype plugin indent on " Loads pyflake-vim's ftplugin files automatically when a Python buffer is opened

syntax on                 " syntax highlighing
colorscheme default

nmap <silent> <c-y> :NERDTreeToggle<CR>
nmap <silent> <c-o> :OpenBookmark 

" TagList Plugin Configuration
let Tlist_Ctags_Cmd='/usr/bin/ctags'       " point taglist to ctags
let Tlist_GainFocus_On_ToggleOpen = 1      " Focus on the taglist when its toggled
let Tlist_Close_On_Select = 1              " Close when something's selected
let Tlist_Use_Right_Window = 1             " Project uses the left window
let Tlist_File_Fold_Auto_Close = 1         " Close folds for inactive files

" Omnicompletion functions
set ofu=syntaxcomplete#complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS

au FileType py set expandtab

map <F2> :previous<CR>                  " map F2 to open previous buffer
map <F3> :next<CR>                      " map F3 to open next buffer
map <F5> :TlistToggle<CR>               " map F5 to toggle the Tag Listing
map <silent><C-Left> <C-T>              " taglist - map Ctrl-LeftArrow to jump to the method/property under your cursor
map <silent><C-Right> <C-]>             " taglist - map Ctrl-RhitArrow to jump back to your source code

" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" When vimrc is edited, reload it
autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc

highlight SpellBad term=reverse ctermbg=Gray ctermfg=Red

以下是我在 ~/.vim/bundles 中的一些其他插件:

IndexedSearch nerdtree snipmate.vim vim-css-color vim-git vim-rails vim-ruby-debugger vim-supertab vim-tcomment 要点 pyflakes-vim Textile.vim vim-cucumber vim-haml vim-repeat vim-should vim-surround vim-vividchalk jquery pysmell vim-align vim-fugitive vim-markdown vim-ruby vim-sparkup vim-taglist

【问题讨论】:

  • 您收到一些错误消息吗? :!pwd 在第一个缓冲区中返回什么?在第二个?和:!echo $PATH 在两个缓冲区中?
  • 当我使用快捷方式时,它会复制下一行的比赛,一次一个字符。没有错误消息... pwd 和 $PATH 对于两个缓冲区都是相同的。详细映射显示工作缓冲区中的 Sparkup 映射,但不显示非工作缓冲区中的 Sparkup 映射。实际上,我在非工作中没有看到 的任何映射。

标签: vim nerdtree


【解决方案1】:

会不会是这个插件绑定了一个给定的文件类型,而当你改变窗口时文件类型不一样?

如果不起作用,请尝试将您的插件添加到 ftplugins。

【讨论】:

  • 插件是为 HTML 文件设置的。如果我尝试从打开的缓冲区中拆分为具有标准 HTML 严格样板的现有 HTML 文件,则它不起作用。如果我只是在命令行打开一个 HTML 文件,那么我的 Sparkup 地图就可以正常加载了。
  • 尝试在非工作缓冲区中手动执行 :setfiletype html 并重试;可能是插件的自动命令不正确。
  • 不行...关于'setfiletype html'。问题似乎在于该 sparkup.vim 文件不是来自我从正在运行的 Vim 会话中打开的新缓冲区。如果我明确输入 ":so ~/.vim/bundle/vim-sparkup/plugin/html/sparkup.vim" 那么它可以工作。然后我尝试将 sparkup.vim 和 sparkup.py 移到一个目录中(以便它驻留在“/plugin 而不是 /plugin/html”中,认为这可能是文件类型问题,但仍然不行。我很困惑!
  • 我对 vim 的内部结构了解得不够多,无法帮助您。最后尝试:将其放入 .vim/ftplugin 中,看看是否有效。
  • 我前几天找到了答案,我以为我发了,但我猜不是。要点是插件文件夹中的 vim 设置仅在启动时加载一次。另一方面,ftplugin 文件夹中的 vim 设置是按文件加载的。所以当我拆分成一个新的缓冲区时,它会加载适当的 vim 设置。呜呼!谢谢你的线索
猜你喜欢
  • 1970-01-01
  • 2017-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多