匹配不工作

发布于 2024-12-02 15:26:09 字数 3824 浏览 1 评论 0原文

我正在使用 Macvim 7.3 snapshot 57。我似乎无法让 matchit 在我的任何文件中工作。

我在开始标签上按 %。它不会带我到结束标签...

我的 vimrc 文件:

" Pathogen settings
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()

set nocompatible

set number
set ruler
set cursorline
syntax on

" Disable all blinking
set guicursor+=a:blinkon0

" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set cindent
set smartindent
set autoindent
set list listchars=tab:\ \ ,trail:·

" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase

" Status bar
set laststatus=2

" Start without the toolbar
set guioptions-=T

" Default gui color scheme
" "color default
" color molokai
color railscasts+

" Command-/ to toggle comments
map <D-/> :TComment<CR>j

" Remember last location in file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif

" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby

" Open split buffers below instead of above current buffer
set splitbelow

" Session options
let g:session_autoload = 1
let g:session_autosave = 1

" Buffer navigation
map <C-K> <C-W><C-K>
map <C-J> <C-W><C-W>
map <C-H> <C-W><C-H>
map <C-L> <C-W><C-L>

" Rails navigation options
nmap <leader>rc :Rcontroller 
nmap <leader>rv :Rview 
nmap <leader>rm :Rmodel 

" Tab completion
" Also needed for better Rails navigation auto-completion
set wildmode=list:longest,list:full

" Open up side panel left (NERDTree) and right(Tagbar)
" nmap <leader>\ :NERDTreeToggle<CR> :TagbarToggle<CR>
nmap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>

" Allow single click for NERDTree
let NERDTreeMouseMode = 3
let g:NERDTreeWinSize = 30
" autocmd VimEnter * NERDTree

" Tagbar options
let tagbar_singleclick = 1
let g:tagbar_sort = 0
let g:tagbar_width = 30
" autocmd VimEnter * nested TagbarOpen

" The Janus plugin sets this to noequalalways for the Zoominfo plugin
" However, we want to set this to equalalways instead, since we want to
" have equal window height when a new window is opened. i.e. via ctrl+w+s
set equalalways

" Matchit already installed in newer versions of vim.
" Don't need to add this onto pathogen bundle folder. We only need
" to configure it.
" Configure matchit so that it goes from opening tag to closing tag
au FileType html,eruby,rb,css,js,xml runtime! macros/matchit.vim

" Set backup and swp dir. Don't forget to clear tmp dir out once in a while
set backupdir=~/.vim/tmp/backup
set directory=~/.vim/tmp/swp

" Detect if a tab was closed, and ensure that height of main window fills the screen (100% height)
au TabEnter * let &lines = 100

" <leader>\ to open or close NERDTree and Tagbar, under the following conditions:
" 1) Only close both if NERDTree and Tagbar are both opened
" 2) Open both if NERDTree and Tagbar are closed OR if one is already opened
function! ToggleNERDTreeAndTagbar()
  let w:jumpbacktohere = 1

  " Detect which plugins are open
  if exists('t:NERDTreeBufName')
      let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
  else
      let nerdtree_open = 0
  endif
  let tagbar_open = bufwinnr('__Tagbar__') != -1

  " Perform the appropriate action
  if nerdtree_open && tagbar_open
      NERDTreeClose
      TagbarClose
  elseif nerdtree_open
      TagbarOpen
  elseif tagbar_open
      NERDTree
  else
      NERDTree
      TagbarOpen
  endif

  " Jump back to the original window
  for window in range(1, winnr('$'))
    execute window . 'wincmd w'
    if exists('w:jumpbacktohere')
      unlet w:jumpbacktohere
      break
    endif
  endfor
endfunction

I am using Macvim 7.3 snapshot 57. I can't seem to get matchit to work in any of my files.

I press % on an opening tag. It doesn't take me to the closing tag...

My vimrc file:

" Pathogen settings
call pathogen#runtime_append_all_bundles()
call pathogen#helptags()

set nocompatible

set number
set ruler
set cursorline
syntax on

" Disable all blinking
set guicursor+=a:blinkon0

" Whitespace stuff
set nowrap
set tabstop=2
set shiftwidth=2
set expandtab
set cindent
set smartindent
set autoindent
set list listchars=tab:\ \ ,trail:·

" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase

" Status bar
set laststatus=2

" Start without the toolbar
set guioptions-=T

" Default gui color scheme
" "color default
" color molokai
color railscasts+

" Command-/ to toggle comments
map <D-/> :TComment<CR>j

" Remember last location in file
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
endif

" Thorfile, Rakefile and Gemfile are Ruby
au BufRead,BufNewFile {Gemfile,Rakefile,Thorfile,config.ru} set ft=ruby

" Open split buffers below instead of above current buffer
set splitbelow

" Session options
let g:session_autoload = 1
let g:session_autosave = 1

" Buffer navigation
map <C-K> <C-W><C-K>
map <C-J> <C-W><C-W>
map <C-H> <C-W><C-H>
map <C-L> <C-W><C-L>

" Rails navigation options
nmap <leader>rc :Rcontroller 
nmap <leader>rv :Rview 
nmap <leader>rm :Rmodel 

" Tab completion
" Also needed for better Rails navigation auto-completion
set wildmode=list:longest,list:full

" Open up side panel left (NERDTree) and right(Tagbar)
" nmap <leader>\ :NERDTreeToggle<CR> :TagbarToggle<CR>
nmap <leader>\ :call ToggleNERDTreeAndTagbar()<CR>

" Allow single click for NERDTree
let NERDTreeMouseMode = 3
let g:NERDTreeWinSize = 30
" autocmd VimEnter * NERDTree

" Tagbar options
let tagbar_singleclick = 1
let g:tagbar_sort = 0
let g:tagbar_width = 30
" autocmd VimEnter * nested TagbarOpen

" The Janus plugin sets this to noequalalways for the Zoominfo plugin
" However, we want to set this to equalalways instead, since we want to
" have equal window height when a new window is opened. i.e. via ctrl+w+s
set equalalways

" Matchit already installed in newer versions of vim.
" Don't need to add this onto pathogen bundle folder. We only need
" to configure it.
" Configure matchit so that it goes from opening tag to closing tag
au FileType html,eruby,rb,css,js,xml runtime! macros/matchit.vim

" Set backup and swp dir. Don't forget to clear tmp dir out once in a while
set backupdir=~/.vim/tmp/backup
set directory=~/.vim/tmp/swp

" Detect if a tab was closed, and ensure that height of main window fills the screen (100% height)
au TabEnter * let &lines = 100

" <leader>\ to open or close NERDTree and Tagbar, under the following conditions:
" 1) Only close both if NERDTree and Tagbar are both opened
" 2) Open both if NERDTree and Tagbar are closed OR if one is already opened
function! ToggleNERDTreeAndTagbar()
  let w:jumpbacktohere = 1

  " Detect which plugins are open
  if exists('t:NERDTreeBufName')
      let nerdtree_open = bufwinnr(t:NERDTreeBufName) != -1
  else
      let nerdtree_open = 0
  endif
  let tagbar_open = bufwinnr('__Tagbar__') != -1

  " Perform the appropriate action
  if nerdtree_open && tagbar_open
      NERDTreeClose
      TagbarClose
  elseif nerdtree_open
      TagbarOpen
  elseif tagbar_open
      NERDTree
  else
      NERDTree
      TagbarOpen
  endif

  " Jump back to the original window
  for window in range(1, winnr('
))
    execute window . 'wincmd w'
    if exists('w:jumpbacktohere')
      unlet w:jumpbacktohere
      break
    endif
  endfor
endfunction

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

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

发布评论

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

评论(8

红墙和绿瓦 2024-12-09 15:26:09

由于 Vim 附带了 matchit 插件,我所需要做的就是激活它:

vim ~/.vimrc

然后将以下内容添加到您的 .vimrc 中:

set nocompatible
filetype plugin on
runtime macros/matchit.vim

Since Vim comes shipped with matchit plugin, all I needed to do was activate it:

vim ~/.vimrc

Then add the following into your .vimrc:

set nocompatible
filetype plugin on
runtime macros/matchit.vim
桃气十足 2024-12-09 15:26:09

matchit 插件的页面显示:

确保您的 vimrc 文件中有一行

:filetype plugin on

。这启用了文件类型插件,其中许多插件告诉
matchit.vim 要使用的匹配对。

The page of the matchit plugin says:

Make sure you have a line like

:filetype plugin on

in your vimrc file. This enables filetype plugins, many of which tell
matchit.vim which matching pairs to use.

枫以 2024-12-09 15:26:09

这条线

runtime macros/matchit.vim

是激活 matchit 的标准方法,它适用于我所有的机器。

输入后 matchit 可以工作吗?

:runtime macros/matchit.vim

在正常模式下

This line

runtime macros/matchit.vim

is the standard way of activating matchit and it works on all my machines.

Does matchit work after you type

:runtime macros/matchit.vim

in normal mode ?

静赏你的温柔 2024-12-09 15:26:09

仅供参考:在 vim 8 中,runtime macros/matchit.vim 变为 packadd!匹配

FYI: in vim 8 runtime macros/matchit.vim becomes packadd! matchit.

长伴 2024-12-09 15:26:09

在将一些 vim 插件更新到 7.3 的最新版本后,我开始遇到同样的问题。

但是当我运行

:MatchDebug

它为我解决了这个问题。

I started having the same issue after I updated some of my vim plugings to the latest version for 7.3.

But when I run

:MatchDebug

it fixes the issue for me.

动听の歌 2024-12-09 15:26:09

当有注释的大括号时,我在 C++/C 中使用 matchit 查找正确的匹配大括号时遇到问题。以下步骤摘自此论坛帖子,作者:这个人,为我解决了这个问题,也几乎解释了整个事情的工作方式:

  1. 创建文件夹 ~/.vim/plugin 如果它尚不存在:

    mkdir ~/.vim/plugin 
    
  2. 创建一个具有以下名称的文件
    ~/.vim/plugin/matchit.vim :

    vi ~/.vim/plugin/matchit.vim 
    

    以及以下内容:

    运行时宏/matchit.vim 
    
  3. 创建目录 ~/.vim/doc(如果尚不存在):

    mkdir ~/.vim/doc
    
  4. 将 /usr/share/vim/vim73/macros/matchit.txt 复制到 ~/.vim/doc/ :

    cp /usr/share/vim/vim73/macros/matchit.txt ~/.vim/doc/
    
  5. 打开 vi

    <前><代码>vi

    并在其中执行以下内容:

    :helptags ~/.vim/doc 
    
  6. 确保您的 ~/.vimrc 包含以下内容之一:

    源 $VIMRUNTIME/vimrc_example.vim 
    

    运行时 vimrc_example.vim 
    

    文件类型插件开启 
    

    文件类型插件缩进 
    
  7. 在您的 vimrc 中添加以下自动命令:

    " 使 matchit 在类 C 文件类型上工作 
    “ c 和 cpp 已经由它们的 ftplugin 处理 
    au 文件类型 css,javascript 
            \ 让 b:match_words = &matchpairs 
    
  8. 重新启动 Vim。重新

I had a problem with matchit finding the correct matching brace in C++/C when there were commented braces. The following steps, taken from this forum post written by this guy, solved it for me and also pretty much explained the way the whole thing works:

  1. Create the folder ~/.vim/plugin if it is not already there:

    mkdir ~/.vim/plugin 
    
  2. Create a file with the name
    ~/.vim/plugin/matchit.vim :

    vi ~/.vim/plugin/matchit.vim 
    

    and the following contents:

    runtime macros/matchit.vim 
    
  3. Create the directory ~/.vim/doc if it is not already there:

    mkdir ~/.vim/doc
    
  4. Copy /usr/share/vim/vim73/macros/matchit.txt to ~/.vim/doc/ :

    cp /usr/share/vim/vim73/macros/matchit.txt ~/.vim/doc/
    
  5. Open vi

    vi
    

    and execute the following in it:

    :helptags ~/.vim/doc 
    
  6. Make sure that your ~/.vimrc includes one of the following:

    source $VIMRUNTIME/vimrc_example.vim 
    

    or

    runtime vimrc_example.vim 
    

    or

    filetype plugin on 
    

    or

    filetype plugin indent on 
    
  7. Add the following autocommand in your vimrc:

    " make matchit work on C-like filetypes 
    " c and cpp are already handled by their ftplugin 
    au Filetype css,javascript 
            \ let b:match_words = &matchpairs 
    
  8. Restart Vim.

书信已泛黄 2024-12-09 15:26:09

我也遇到过类似的问题。我已经尝试使用 VIM 提供的脚本运行时宏/matchit.vim,但它不起作用。
所以我从 http://www.1.13.2 版本下载了这个脚本。 vim.org/scripts/script.php?script_id=39,将其解压缩到 ~/vimfiles 中,它就可以工作了!

I've had similar problem. I've tried runtime macros/matchit.vim with VIM-provided script and it didn't work.
So I've downloaded this script in version 1.13.2 from http://www.vim.org/scripts/script.php?script_id=39, unzipped it into ~/vimfiles and it works!

忘你却要生生世世 2024-12-09 15:26:09

对于 Lua,您需要将此行添加到 init.lua 中:

vim.g.loaded_matchit = true

当我安装 Homebrew 时,这是在 Linux 上

For Lua you need to add this line to your init.lua:

vim.g.loaded_matchit = true

This was on Linux when I instlled with Homebrew

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