您更喜欢如何在 Vim 中的缓冲区之间切换?

发布于 2024-07-08 23:03:13 字数 277 浏览 7 评论 0原文

我尝试过 MiniBufExplorer,但我通常会看到几个窗口显示或完全关闭它。 我想要的是类似 LustyJuggler 的增量搜索方式,我在 Emacs 中的缓冲区之间切换。 肯定有这样的脚本吗?

I've tried MiniBufExplorer, but I usually end up with several windows showing it or close it altogether. What I'd like is something like LustyJuggler with incremental search, the way I switch between buffers in Emacs. Surely there is a script like this?

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

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

发布评论

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

评论(16

生死何惧 2024-07-15 23:03:13

我曾经使用选项卡和多个 gvim 实例的组合,将相关文件组保留为每个实例中的选项卡。 只要我在一个实例中没有出现太多选项卡,选项卡栏就会一目了然地显示您正在编辑的每个文件的名称。

然后我读了 Jamis Buck 的一篇文章,介绍了他如何从 TextMate 切换到 回到 vim,并学习了一些很棒的技巧:

  • Ctrl+w sCtrl+< kbd>w v 分割当前窗口
  • Ctrl+6 在同一窗口的两个缓冲区之间来回切换。
  • 很棒的 fuzzyfinder.vim 可以自动完成文件搜索在您当前的目录或缓冲区中,您当前打开了
  • Jamis 自己的 fuzzy_file_finderfuzzyfinder_textmate,它稍微修改了 fuzzyfinder 的工作方式,使其更像TextMate 中的类似功能(据我所知,区别在于它匹配文件名中的任何位置,而不是仅从开头匹配)。 观看此视频以了解其实际效果。

现在我只有一个 gvim 实例,将其最大化,并将其拆分为多个窗口,这样我就可以同时查看多个文件。 我将 Ctrl+F 绑定到 fuzzyfinder\_textmate,所以现在如果我输入(比如说)Ctrl+F mod/usob 它打开 app/models/user\_observer.rb。 我几乎不再理会标签了。

更新 2010/08/07

尽管 fuzzyfinder\_textmate 仍然很棒,正如 Casey 在评论中指出的那样,但它已不再维护。 另外,在处理大型项目(大量目录或文件)时,它(和/或 fuzzyfinder.vim )会变得有点慢且不稳定,所以我一直在寻找替代方案。

幸运的是,似乎有一个非常好的替代方案,即 Wincent ColaiutaCommand-T 插件。 这与 fuzzyfinder\_textmate 的行为非常相似(如果不是稍微好一点的话),但速度明显更快; 它还具有很好的功能,例如能够以拆分或垂直拆分方式打开找到的文件。 感谢(并投票!)大卫·里弗斯指出了这一点。

I used to use a combination of tabs and multiple gvim instances, keeping groups of related files as tabs in each instance. So long as I didn't end up with too many tabs in one instance, the tab bar shows you the name of each file you're editing at a glance.

Then I read a post by Jamis Buck on how he switched from TextMate back to vim, and learned some great tricks:

  • Ctrl+w s and Ctrl+w v to split the current window
  • Ctrl+6 to switch back and forth between two buffers in the same window.
  • the awesome fuzzyfinder.vim which gives you auto-completing search of files in your current directory or of buffers you currently have open
  • Jamis' own fuzzy_file_finder and fuzzyfinder_textmate, which slightly modify how fuzzyfinder works to behave more like a similar feature in TextMate (as far as I can tell, the difference is that it matches anywhere in the filename instead of only from the start). Watch this video to see it in action.

Now I just have one gvim instance, maximised, and split it into multiple windows so I can see several files at once. I bound Ctrl+F to fuzzyfinder\_textmate, so now if I type (say) Ctrl+F mod/usob it opens up app/models/user\_observer.rb. I almost never bother with tabs any more.

Update 2010/08/07

While fuzzyfinder\_textmateremains awesome, as Casey points out in the comments, it's no longer maintained. Also, it (and/or fuzzyfinder.vim) gets a bit slow and unstable when working with large projects (lots of directories or files), so I've been looking for an alternative.

Fortunately, there seems to be a very nice alternative in the form of Wincent Colaiuta's Command-T plugin. This has very similar (if not slightly better) behaviour to fuzzyfinder\_textmate, but is noticeably faster; it also has nice features like being able to open the found file in a split or vertical split. Thanks (and upvotes!) to David Rivers for pointing to it.

染火枫林 2024-07-15 23:03:13

我使用基础知识 - ':ls' + ':bn'/':bp' + ':b'

I use the basics - ':ls' + ':bn'/':bp' + ':b <part-of-name>'

任性一次 2024-07-15 23:03:13

我喜欢“ctrl-w s”和“ctlr-w v”来分割窗口。 然后我按住 ctrl 映射移动键(h、j、k、l)以在分割窗口之间移动:

" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-l> <C-w><Right>
map <C-h> <C-w><Left>

必须将手移到箭头键上很烦人。

接下来,我设置了 ctlr-tab 在当前窗口中的缓冲区之间进行切换(就像许多其他环境一样):

" Switch to alternate file
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>

在过去的几年里,这些对我来说非常有效,尽管 vim 总是有比你知道的更多的秘密。

I like "ctrl-w s" and "ctlr-w v" to split the window. Then I map the movement keys (h, j, k, l) with ctrl held down to move between the split windows:

" Map ctrl-movement keys to window switching
map <C-k> <C-w><Up>
map <C-j> <C-w><Down>
map <C-l> <C-w><Right>
map <C-h> <C-w><Left>

Having to move my hand over to the arrow keys is annoying.

Next, I set up ctlr-tab to switch between buffers in the current window (like a lot of other environments):

" Switch to alternate file
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>

These have worked pretty well for me over the last several years although vim always has more secrets than you can know.

宛菡 2024-07-15 23:03:13

我已经使用 Wincent Colaiuta 的 Command-T vim 插件 几个月了。 Wincent 用 C 语言编写了其中需要快速的部分,我必须说确实如此! 而且,我认为它的文件模式匹配逻辑甚至比 Textmate 的 Command-T 更好。 查看

VIM 的 Command-T 插件提供
极其快速、直观的机制
用于以最小的速度打开文件
击键次数。 它的名字叫
“Command-T”因为它的灵感来自
“转到文件”窗口绑定到
TextMate 中的 Command-T。

通过键入来选择文件
出现在他们路径中的角色,
并按算法排序
知道出现在
某些位置(例如,
紧接在路径分隔符之后)
应该给予更多的权重。

更轻松的缓冲区切换包含许多有用的提示。 我已将以下内容调整到我的 .vimrc 中,它会自动完成缓冲区名称,将最有用的缓冲区切换命令映射到我的中。 和左侧主行键,并在状态行中显示当前缓冲区编号:

"" Tab triggers buffer-name auto-completion
set wildchar=<Tab> wildmenu wildmode=full

let mapleader = ","

map <Leader>t :CommandT<Return>
map <Leader>a :bprev<Return>
map <Leader>s :bnext<Return>
map <Leader>d :bd<Return>
map <Leader>f :b 

"" Show the buffer number in the status line.
set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

我还使用 MiniBufExplorer,它在其自己的水平分割顶部提供每个列出的缓冲区的紧凑列表。

I have been using Wincent Colaiuta's Command-T vim plugin for a couple months now. Wincent wrote the parts of it that need to be fast in C, and I must say that it is! And, I think its file pattern matching logic is even better than Textmate's Command-T. Check out the screencast.

The Command-T plug-in for VIM provides
an extremely fast, intuitive mechanism
for opening files with a minimal
number of keystrokes. It's named
"Command-T" because it is inspired by
the "Go to File" window bound to
Command-T in TextMate.

Files are selected by typing
characters that appear in their paths,
and are ordered by an algorithm which
knows that characters that appear in
certain locations (for example,
immediately after a path separator)
should be given more weight.

Easier buffer switching contains many useful tips. I have adapted the following to my .vimrc, which does buffer-name auto-completion, maps the most useful buffer-switching commands to my <Leader> and left-side home row keys, and shows the current buffer number in the status line:

"" Tab triggers buffer-name auto-completion
set wildchar=<Tab> wildmenu wildmode=full

let mapleader = ","

map <Leader>t :CommandT<Return>
map <Leader>a :bprev<Return>
map <Leader>s :bnext<Return>
map <Leader>d :bd<Return>
map <Leader>f :b 

"" Show the buffer number in the status line.
set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P

I also use MiniBufExplorer, which provides a compact listing of each listed buffer in its own horizontal split up top.

挖个坑埋了你 2024-07-15 23:03:13
nmap <Leader>bb :ls<CR>:buffer<Space>

没有人提到好插件 ctrlp.vim。 使用此插件,您可以按名称搜索缓冲区。

nmap <Leader>bb :ls<CR>:buffer<Space>

and nobody mentioned nice plugin ctrlp.vim. Using this plugin you can search buffer by name.

很快妥协 2024-07-15 23:03:13

我使用

CTRL-J 作为下一个缓冲区

CTRL-K 作为上一个缓冲区

CTRL -L 表示下一个选项卡

CTRL-H 表示上一个选项卡

这是 .vimrc 配置:

map <C-J> :bnext<CR>
map <C-K> :bprev<CR>
map <C-L> :tabn<CR>
map <C-H> :tabp<CR>

请参阅 http://syskall.com/my-biggest-vim-productivity-boost/

I use

CTRL-J for next buffer

CTRL-K for previous buffer

CTRL-L for next tab

CTRL-H for previous tab

Here is the .vimrc configuration:

map <C-J> :bnext<CR>
map <C-K> :bprev<CR>
map <C-L> :tabn<CR>
map <C-H> :tabp<CR>

See http://syskall.com/my-biggest-vim-productivity-boost/

雪若未夕 2024-07-15 23:03:13
imap <A-1> <Esc>:tabn 1<CR>i
imap <A-2> <Esc>:tabn 2<CR>i
imap <A-3> <Esc>:tabn 3<CR>i
imap <A-4> <Esc>:tabn 4<CR>i
imap <A-5> <Esc>:tabn 5<CR>i
imap <A-6> <Esc>:tabn 6<CR>i
imap <A-7> <Esc>:tabn 7<CR>i
imap <A-8> <Esc>:tabn 8<CR>i
imap <A-9> <Esc>:tabn 9<CR>i

map <A-1> :tabn 1<CR>
map <A-2> :tabn 2<CR>
map <A-3> :tabn 3<CR>
map <A-4> :tabn 4<CR>
map <A-5> :tabn 5<CR>
map <A-6> :tabn 6<CR>
map <A-7> :tabn 7<CR>
map <A-8> :tabn 8<CR>
map <A-9> :tabn 9<CR>
imap <A-1> <Esc>:tabn 1<CR>i
imap <A-2> <Esc>:tabn 2<CR>i
imap <A-3> <Esc>:tabn 3<CR>i
imap <A-4> <Esc>:tabn 4<CR>i
imap <A-5> <Esc>:tabn 5<CR>i
imap <A-6> <Esc>:tabn 6<CR>i
imap <A-7> <Esc>:tabn 7<CR>i
imap <A-8> <Esc>:tabn 8<CR>i
imap <A-9> <Esc>:tabn 9<CR>i

map <A-1> :tabn 1<CR>
map <A-2> :tabn 2<CR>
map <A-3> :tabn 3<CR>
map <A-4> :tabn 4<CR>
map <A-5> :tabn 5<CR>
map <A-6> :tabn 6<CR>
map <A-7> :tabn 7<CR>
map <A-8> :tabn 8<CR>
map <A-9> :tabn 9<CR>
Spring初心 2024-07-15 23:03:13

我最近变得更加简约。

要循环缓冲区,我使用未受损的 ]b[bhttps://github.com/tpope/vim-unimpaired

要直接跳转到打开的缓冲区,只需使用 Vim 的制表符补全功能 :b 即可。 几个字母足以通过一两个选项卡到达任何打开的缓冲区。

与打开缓冲区类似,我使用 :e 以及相对路径和制表符完成。

我偶尔也会使用 :ls 来查看我打开了哪些缓冲区(并检查它们的修改状态)。

为了摆脱缓冲区,我使用 :bw 来擦除缓冲区。 我通常会进行临时分割并更改缓冲区以保留我的布局,但因为 :bw 也会关闭活动窗口。

我尝试过的所有 minibuf 东西最终都让我烦恼,我不希望一些智能匹配的东西为我打开随机文件。 如果我确实需要浏览某些内容,我会使用 NERDtree (:e .)。

IDK,最近我也放弃了 Yankring(因为它搞砸了 xp)并开始使用寄存器,并且我最近决定 f/t 运动是有史以来最伟大的事情...

I've recently gone more minimalistic.

To cycle buffers I use ]b and [b from unimpaired: https://github.com/tpope/vim-unimpaired

To jump straight to an open buffer just use Vim's tab completion with :b. A few letters is enough to get to any open buffer with a tab or two.

Similarly to open buffers I use :e with relative paths and tab complete.

I also use :ls occasionally to see what buffers I have open (and to check their modified status).

To get rid of a buffer I use :bw to wipe the buffer. I usually make a temporary split and change buffers to preserve my layout though since :bw also closes the active window.

All the minibuf things I tried just ended up annoying me, and I don't want some smart-matching thing opening random files for me. If I really need to browse for something I use NERDtree (:e .).

IDK, Lately I also dropped Yankring (because it screws up xp) and started using registers, and I recently decided the f/t movements are the greatest thing ever...

挽心 2024-07-15 23:03:13

要列出缓冲区并在缓冲区之间切换,我使用:

nnoremap <Leader>l :ls<CR>:b<space>

要在缓冲区之间切换:

map <Leader>n :bn<CR>
map <Leader>p :bp<CR>

To list and switch between buffers I use:

nnoremap <Leader>l :ls<CR>:b<space>

To switch between buffers:

map <Leader>n :bn<CR>
map <Leader>p :bp<CR>
演多会厌 2024-07-15 23:03:13

优秀的 Buffer Explorer,已经变得如此强大了我发现自己希望可以在其他应用程序中使用它。 我发现在主动编辑两个以上文件时它的速度非常快。

The excellent Buffer Explorer, the be has gotten to be such strong muscle memory that I find myself wishing I could use it in other applications. I find it to be extremely fast when actively editing more than two files.

能怎样 2024-07-15 23:03:13

我花了相当长的时间来构建我的 .vimrc 来处理这个我已经从事了四年的 HTML::Mason 项目,所以我有一个奇怪的选项卡和分割窗口的组合。 为了您的观看享受:

map ;o :Sex <CR>
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-l> <C-W>l
map <C-h> <C-W>h
map ;] :tabnext<CR>
map ;[ :tabprev<CR>
map <C-t> :tabe +"browse ."<CR>
map <C-O> :NERDTreeToggle ~/curr/trunk/<CR>

I've spent quite a while building my .vimrc to work with this HTML::Mason project I've been on for four years, so I have an odd mix of tabs and split windows. For your viewing enjoyment:

map ;o :Sex <CR>
map <C-J> <C-W>j
map <C-K> <C-W>k
map <C-l> <C-W>l
map <C-h> <C-W>h
map ;] :tabnext<CR>
map ;[ :tabprev<CR>
map <C-t> :tabe +"browse ."<CR>
map <C-O> :NERDTreeToggle ~/curr/trunk/<CR>
南风起 2024-07-15 23:03:13

我使用 tselectbuffer。 它非常快,并且与 bufexplorer 不同,它不会占用窗口空间。 它还有增量搜索。我尝试了 minibufexplorer,发现缓冲区中的导航有点困难。

I use tselectbuffer. It's really fast and unlike bufexplorer doesn't take space in your window. It also has a incremental search.I tried minibufexplorer and I found the navigation in the buffer a bit difficult.

生来就爱笑 2024-07-15 23:03:13

我已将 映射到 :bp:bn,尽管我承认我不使用它,因为文件数量大于 10。然后我将 映射到 Gnome Terminal 的上一个和下一个选项卡,我通常为我从事的 4 个不同项目中的每一个运行 4 个 vim 实例。 我仍然非常希望下一个和上一个缓冲区能够进入我一直在处理的缓冲区的历史记录,而不是缓冲区列表中的顺序。

I have mapped <S-J> and <S-K> to :bp and :bn, although I admit I don't use it as the number of files is greater than 10. I have then mapped <C-J> and <C-K> to Gnome Terminal's previous and next tabs, and I usually run 4 instances of vim for each of the 4 different projects I work on. I still really wish next and previous buffer would go to the history of buffers I have been working on, and not the order int he buffer list.

翻身的咸鱼 2024-07-15 23:03:13

我使用 tselectbuffer。 它非常快,并且与 bufexplorer 不同,它不会占用窗口空间。 它还有增量搜索。我尝试了 minibufexplorer,发现缓冲区中的导航有点困难。

I use tselectbuffer. It's really fast and unlike bufexplorer doesn't take space in your window. It also has a incremental search.I tried minibufexplorer and I found the navigation in the buffer a bit difficult.

一场信仰旅途 2024-07-15 23:03:13

我使用简单的 :vsplit 与 ^W+w/^W+r 和 :tabnew 与 Ctrl+Alt+PgUp/PgDown 组合键。

i use simple :vsplit with ^W+w/^W+r and :tabnew with Ctrl+Alt+PgUp/PgDown key combinations.

瑕疵 2024-07-15 23:03:13

当 Vim 会话中打开多个缓冲区时,跟踪缓冲区及其各自的缓冲区编号可能会变得困难。 如果是这种情况,使用简单的映射可以更轻松地切换到不同的文件:

:nnoremap (F5) :buffers(CR):buffer(空格)

vim.wikia.com

When there are several buffers open in a Vim session, it can become difficult to keep track of the buffers and their respective buffer numbers. If this is the case, switching to a different file can be made easier using a simple map:

:nnoremap (F5) :buffers(CR):buffer(Space)

vim.wikia.com

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