打开vim编辑器 vim/_如何在Vim编辑器中有效使用多个文件

打开vim编辑器 vim/

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I prefer using vim editor.

很多时候,我们需要一起处理多个文件。 如果是Windows系统,则可以使用基于GUI的编辑器来完成任务。 但是如果您使用腻子或仅使用CLI(命令行界面)作为编辑文件的选项该怎么办。 我更喜欢使用vim编辑器。

After doing some experiments and knowing some important commands, I though to share with you. So i have written few commands point wise which may be useful for you while editing multiple files using vim (not GVIM, although these commands are valid there too.)

经过一些实验并且了解了一些重要的命令之后,我还是与大家分享。 所以我只写了一些明智的命令,这对于使用vim编辑多个文件时可能很有用(不是GVIM,尽管这些命令在那里也有效)。

Tested on Linux box under vim v6.3 and vim v7.1

在vim v6.3和vim v7.1下的Linux盒子上测试

    Open multiple files in vim altogether

一起在vim中打开多个文件

        Vim file1 file2 file3 ….

Vim file1 file2 file3…。

        Vim dirPath/pattern for files like vim perlfiles/*.pl     open multiple files in vim

Vim dirPath / pattern for vim perlfiles / *。pl之类的文件在vim中打开多个文件

        It will load in buffer simultaneously so that you can go back and forth to navigate files

它将同时加载到缓冲区中,以便您可以来回浏览文件

   Open files in vim one by one

在vim中一一打开文件

        Vim file1

Vim文件1

        After opening it you can type :e file2 .    This command will be used only to open one file in buffer at one time.     use of :e command in vim

打开后,您可以输入:e file2。 此命令将仅用于一次打开缓冲区中的一个文件。 在vim中使用:e命令

        If you try to open more it will throw error. For ex:  :e file2 file3    error while using :e in vim for multiple files

如果尝试打开更多,它将引发错误。 例如::e file2 file3在vim中对多个文件使用:e时出错

        It will not load instantly in buffer.

它不会立即加载到缓冲区中。

        You need to load it manually by browsing that file for the first time. Use command :b filename(now it will be loaded in buffer) ex:   :b file2

您需要通过首次浏览该文件来手动加载它。 使用命令:b filename(现在它将被加载到缓冲区中)例如::b file2

        In vim v7 we can use :tabe filename too (to see filename in tab)

在vim v7中,我们也可以使用 :tabe文件名(在选项卡中查看文件名)

        :b filename (tab completion will not work in earlier version. In Vim7 it will work.)

:b文件名(制表符补全在早期版本中将不起作用。在Vim7中它将起作用。)

        set wildmenu  in your .vimrc profile to use enhanced tab completion while navigating files through buffer.

在.vimrc配置文件中设置wildmenu,以在通过缓冲区导航文件时使用增强的制表符完成功能。

    To know how many files have been opened and you are currently in which files

要知道已经打开了多少文件,并且您当前处于哪个文件中

         use command :ls

使用命令:ls

        Or : args    args command in vim

或者:vim中的args args命令

        or :ar to list file namesar command in vim

或:ar列出文件名vim中的命令

    % refers to the file currently visible and # refers to the alternate file. (When you are using: ls to list files in buffer). You can easily toggle between these two files by pressing <ctrl>-shift-6:ls command in multiple files -vim

%表示当前可见的文件,#表示备用文件。 (使用时:ls列出缓冲区中的文件)。 您可以通过在多个文件中按<ctrl> -shift-6:ls命令轻松地在这两个文件之间切换-vim

    To Navigate files use following options:

要浏览文件,请使用以下选项:

         use :bn for next file in buffer :bp for previous file in buffer.Menu command in vim :menu

:bn用于缓冲区中的下一个文件:bp用于缓冲区中的上一个文件。vim:menu中的菜单命令

         Use :bn or :nb to browse nth file (n being a positive integer). :bn or :bnext is just an alias. You can use any one of them. Ex: 2b or b2 would open file which is at second buffer

使用:bn或:nb浏览第n个文件(n为正整数)。 :bn或:bnext只是一个别名。 您可以使用其中任何一个。 例如:2b或b2将打开第二个缓冲区中的文件

        :e filename - Edit a file in a new buffer

:e filename-在新缓冲区中编辑文件

        :bnext (or :bn) - go to next buffer

:bnext(或:bn)-转到下一个缓冲区

        :bprev (of :bp) - go to previous buffer

:bprev(of:bp)-转到上一个缓冲区

        :bd - delete a buffer (close a file)

:bd-删除缓冲区(关闭文件)

        :sp filename - Open a file in a new buffer and split window

:sp filename-在新的缓冲区和分割窗口中打开文件

        ctrl+ws - Split windows (my vim gets hung, don’t know why). If you find the reason please let meknow. Ctrl+s doesn’t work in my vim editor under putty.

ctrl + ws-分割窗口(我的vim挂了,不知道为什么)。 如果您找到原因,请让我知道。 Ctrl + s在腻子下的vim编辑器中不起作用。

        ctrl+ww - switch between windows

ctrl + ww-在Windows之间切换

        ctrl+wq - Quit a window

ctrl + wq-退出窗口

        ctrl+wv - Split windows vertically

ctrl + wv-垂直分割窗口

        You can use :n also for browsing next file and :prev for previous file

您也可以使用:n浏览下一个文件,并且:prev查看上一个文件

By default vim will not allow you to switch to another buffer unless and until you save the current buffer.  It will throw an error message like this: "E37: No write since last change (add ! to override)  error on unsaved files in buffer -vim"

默认情况下,除非保存当前缓冲区,否则vim将不允许您切换到另一个缓冲区。 它将引发如下错误消息:“ E37:自上次更改以来没有写入(添加!以覆盖)在缓冲区-vim中未保存的文件上出现错误”

So to avoid this just write set hidden in your .vimrc profile so that it will let you switch buffers even if you have unsaved changes in the one you are leaving. Use this option if you know what changes you have made. (Be careful).

因此,要避免这种情况,只需在.vimrc配置文件中隐藏隐藏的写集,以便即使您要保留的设置中未保存的更改也可以切换缓冲区。 如果您知道所做的更改,请使用此选项。 (小心)。

You can use tab for multiple files in vim by using tabe filename (but only one file name will be allowed at one time). Then browse opened files in tab using gt (for next file) and gT (for previous file). Even if file is not saved you can move from one tab to other tab.

您可以通过使用tabe文件名在vim中将tab用于多个文件(但一次只允许一个文件名)。 然后使用gt(代表下一个文件)和gT(代表上一个文件)浏览标签中打开的文件。 即使未保存文件,也可以从一个选项卡移动到另一选项卡。

You can split your screen by entering the number with command sb instead of just b. ex: 2sb means split the current window with the second buffer at the top horizontally. And ctrl+w  o will bring back into single file edit mode

您可以通过输入命令sb而不是b来分割屏幕。 例如:2sb表示将当前窗口分割为水平,第二个缓冲区在顶部。 ctrl + w o将返回单文件编辑模式

    Use :ctrl+d to see the list of all available option under vim.

使用:ctrl + d查看vim下所有可用选项的列表。

    Use :menu to see available menu to use.

使用:menu查看可用的菜单。

I am still experimenting vim features. If I will come to know anything else apart from these features, I will update this post with latest stuff.

我仍在尝试vim功能。 如果除了这些功能我将了解其他任何内容,我将使用最新的内容更新此帖子。

If you know anything related to this topic or if you find any problem while using those commands, please revert here as comment with detailed issues.

如果您知道与该主题相关的任何信息,或者在使用这些命令时发现任何问题,请在此处回复为带有详细问题的注释。

Source: Alien Coders (my website)

资料来源: 外星人编码员 (我的网站)

翻译自: https://www.experts-exchange.com/articles/8530/How-to-use-multiple-files-efficiently-in-vim-editor.html

打开vim编辑器 vim/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值