简体   繁体   English

一些简单的vim命令

[英]some simple vim commands

sorry if this isn't exactly a programming question. 很抱歉,如果这不是一个编程问题。

I mainly use Vim to edit my programs. 我主要使用Vim编辑程序。 So my question to all the Vim experts out there is: 所以我对所有Vim专家的疑问是:

  1. is there a way to select and scroll in Vim? 有没有办法选择和滚动Vim? I want to copy a bunch of code, and in the pass I have always copied everything I can view on the vim screen then paste it to where-ever, then scroll down then copy and paste..repeat..until done. 我想复制一堆代码,并且在传递过程中,我总是复制了可以在vim屏幕上查看的所有内容,然后将其粘贴到任何位置,然后向下滚动然后复制并粘贴..repeat ..直到完成。 Is there a way I can efficiently copy a large block of code? 有没有办法可以有效地复制大量代码?

  2. Formatting lines of code- you know when you copy and paste some code sometime 10 lines of code turn into 30 really messy lines of code? 格式化代码行-您知道有时在复制和粘贴一些代码时将10行代码变成30条真正凌乱的代码行吗? well, is there a command to reformat the code? 好,有没有重新格式化代码的命令? In the pass I manually go back and properly indent everything which sometime is super repetitive when you got 500 lines. 在通过过程中,我手动返回并正确缩进所有内容,当您获得500行时,这有时是超级重复的。 I saw on other sites something about the command being 1G = G can someone confirm that? 我在其他站点上看到有关命令1G = G ,有人可以确认吗? when I try it in my command line, I get a error E464: ambiguous use of user-command line which I have no idea what that even means. 当我在命令行中尝试时,出现错误E464: ambiguous use of user-command line ,我什至不知道那是什么意思。

I do know there is a help command in Vim,but I have no idea where to even start when there is something like 200 txt files and frankly this is faster :) 我确实知道Vim中有一个帮助命令,但是当有200个txt文件之类的东西时,我什至不知道从哪里开始,而且坦率地说,这样更快:)

Your questions are around basic use of vi / Vim. 您的问题与vi / Vim的基本用法有关。 Do yourself a favor and go through a Vim tutorial; 帮个忙,并通过一个Vim教程; you'll find many on the web, and Vim comes with it's own introduction, vimtutor . 您会在网上找到很多,Vim附带了它自己的介绍vimtutor

On Unix, if Vim has been properly installed, you can start it from the shell: 在Unix上,如果已正确安装Vim,则可以从shell启动它:

vimtutor 维姆托

On MS-Windows you can find it in the Program/Vim menu. 在MS-Windows上,您可以在Program / Vim菜单中找到它。 Or execute vimtutor.bat in the $VIMRUNTIME directory. 或在$ VIMRUNTIME目录中执行vimtutor.bat。

Also, learn how to look up commands and navigate the built-in :help ; 另外,学习如何查找命令并浏览内置的:help it is comprehensive and offers many tips. 它是全面的,并提供了许多技巧。 You won't learn Vim as fast as other editors, but if you commit to continuous learning, it'll prove a very powerful and efficient editor. 学习Vim的速度不会像其他编辑器那样快,但是如果您坚持不懈地学习,它将证明它是一个功能强大且高效的编辑器。

The vim way is to entirely forget selection using the mouse for more than a screenful, but to set a mark, move to the other end of the desired text, then yank to mark: vim的方法是完全忘记使用鼠标进行的选择,而不只是进行筛选,而要设置一个标记,移至所需文本的另一端,然后拖动以标记:

  1. Set mark m at beginning of text with mm 在文本的开头用mm设置标记m
  2. Move to end of text 移至文字结尾
  3. Yank to mark with y'm y'm标记
  4. Paste with P or p 贴上Pp

This whole answer is only helpful if you can use register + as clipboard. 仅当您可以将register +用作剪贴板时,整个答案才有用。 Try "+yy in VIM, try to paste it in another application to see if you can use the clipboard, if you can: 在VIM中尝试"+yy ,尝试将其粘贴到另一个应用程序中,看是否可以使用剪贴板,如果可以的话:

You should really read the manuals and other help: 您应该真正阅读手册和其他帮助:
To yank lines (simple) : http://vim.wikia.com/wiki/Moving_lines_up_or_down 拉动线条(简单): http : //vim.wikia.com/wiki/Moving_lines_up_or_down
To address lines: Addressing in VIM 地址行: 在VIM中寻址
That is to start with. 首先是。

Some examples of what you can do: 您可以做什么的一些示例:
:.,+50y a yank 50 lines from current and 50 ahead to register a, use A instead to append to register A. :.,+50y a从当前位置拉50行,然后向前50条,以注册a,改用A附加到寄存器A。
:.,/some pattern/y A yank (append) from current to first line that match /some pattern/ to register a. :.,/some pattern/y A从当前到与/ some pattern /匹配的第一行的重载(追加)以注册a。
"Ay/some pattern<CR> will do the same thing. "Ay/some pattern<CR>会做同样的事情。

Once you learn how you should address, it's easy to combine commands with addressing, eg the "indenting command" = : 一旦学习了寻址方式,就可以轻松地将命令与寻址结合起来,例如“缩进命令” =
=} auto indent to the end of current paragraph =}自动缩进当前段落的末尾
=/some pattern<CR> auto indent to line matching /some pattern/ =/some pattern<CR>自动缩进以匹配行/某些模式/
Mark something in Visual mode and type = it will auto indent the selected text. 在可视模式下标记某些内容,然后键入=它将自动缩进所选文本。

And so on... So read manuals, you will have a great use of it. 依此类推...阅读手册,您将可以大量使用它。
In the above examples you can use register + to "yank" to the clipboard instead of register a . 在上面的示例中,您可以使用register +来“拉”到剪贴板,而不是注册a

For pasting in VIM without it retabbing the text, try 要在不重新标记文本的情况下粘贴到VIM中,请尝试

:set paste

before pasting. 粘贴之前。

Use :set nopaste to turn it off. 使用:set nopaste将其关闭。

Also, make sure you paste in insert mode . 另外,请确保以insert mode粘贴。

If you are looking for advanced VIM command, then my blog post may help. 如果您正在寻找高级VIM命令,那么我的博客文章可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM