No plug-in vim programming tips

Source: Internet
Author: User

This article turns from the cool shell –coolshell.cn, the author is Chenhao. But here only a part of the personal thought commonly used skills, and made a few adjustments, here Vim version is 7.3.

Testing on Vim 7.3 is possible

Browse the Code

First, let's start by browsing the code. Sometimes, we need to look at multiple files, so the traditional practice is that we open multiple TTY terminals, each TTY with vim to open a file, and then switch back and forth. This is very inefficient. We want to open multiple files in a vim and even browse the program directory.

The commands for navigating the directory are simple: (You can also vim a directory directly) first, let's start by browsing the code. Sometimes, we need to look at multiple files, so the traditional practice is that we open multiple TTY terminals, each TTY with vim to open a file, and then switch back and forth. This is very inefficient. We want to open multiple files in a vim and even browse the program directory.

The commands for navigating the directory are simple: (You can also vim a directory directly)


:Ex

Note that it is capitalized. As a result, you will see the following interface:
! [] (Http://coolshell.cn//wp-content/uploads/2014/03/Explorer.png)
In this interface, you can use J, K keys to move up and down, then enter, enter a directory, or find a file. You can see a bunch of commands on it: In this interface, you can move up and down with the J, K keys, then enter, enter a directory, or find a file. You can see that there are a bunch of commands:

    • "–" to the parent directory
    • "D" Delete file (uppercase)
    • "R" Change file name (uppercase)
    • "S" to sort files (lowercase)
    • "X" execution file (lowercase)

Of course, open files will flush out existing open files-that is, you only see one file.

If you want to change the directory you are currently browsing, or view the directory you are currently browsing, you can use the same command as the shell:


:cd <dir> – 改变当前目录:pwd - 查看当前目录

Buffer

In fact, you use: Ex to browse open files are not closed, these files are in the buffer. You can use the following command to view the buffer:


:ls

So, under your vim, you will see the following interface:
! [] (Http://coolshell.cn//wp-content/uploads/2014/03/buffer_ls.png)
You can see Vim opened four files, the number is 4,5,6,7, if you want to switch open files, this time, you do not press ENTER (press the also OK, just press on it will not see: LS output buffer list), You can use the following command to toggle the file (4 in the back of buffer to cut to the 4th file, which is SRC/HTTP/NGX_HTTP.C):

:buffer 4

Or

:buffer src/http/ngx_http.c

Attention

    • You can fill in the command with vim just as you would in the shell by typing a command in the TAB key.
    • You can also use the first few characters like GDB, as long as there is no conflict. such as: Buff

You can also switch quickly by using the following command:


:bnext 缩写 :bn:bprevious 缩写 :bp:blast

, we can also see that 5 has a%a, which represents the current file, and the associated tags are as follows:
-(inactive buffer zone)
A (currently activated buffer)
H (hidden buffer zone)
% (current buffer area)
# (Swap buffer)
= (read-only buffer)
+ (buffer area that has changed)

Window split screen browsing

Believe you in the "Vim window split screen" in the article, you already know how to split the window. In fact, I do not use the splitter window command, but instead use the browse file command to separate the window. Such as:

Split the current window up and down and browse the directory below:


:Hex 全称为 :Hexplore (在下边分屏浏览目录)

If you want to be on top, you're in: Add one behind the He!

:He! (在上分屏浏览目录)

If you want to split the screen right and left, you can do this:

:Ve 全称为 :Vexplore (在左边分屏间浏览目录,要在右边则是 :Ve!)

Split screen sync move

To make the files in the two split-screen move synchronously, it is very simple that you need to enter the following commands into the two screens that need to be moved synchronously (equivalent to using the "padlock Chain"):


:set scb

If you need to untie it, enter the following command:

:set scb!

Note: Set SCB is a shorthand for set scrollbind.

Other Tips

Character-related

【guu 】 把一行的文字变成全小写。或是【Vu】【gUU】 把一行的文件变成全大写。或是【VU】按【v】键进入选择模式,然后移动光标选择你要的文本,按【u】转小写,按【U】转大写【ga】 查看光标处字符的ascii码【g8】 查看光标处字符的utf-8编码【gf】  打开光标处所指的文件 (这个命令在打到#include头文件时挺好用的,当然,仅限于有路径的)【*】或【#】在当前文件中搜索当前光标的单词

Indentation Correlation

【>>】向右给它进当前行 【<<】向左缩进当前行【=】  缩进当前行 (和上面不一样的是,它会对齐缩进)【=%】 把光标位置移到语句块的括号上,然后按=%,缩进整个语句块(%是括号匹配)【G=gg】 或是 【gg=G】  – 缩进整个文件(G是到文件结尾,gg是到文件开头)

Cursor Movement related

【Ctrl + O】向后回退你的光标移动【Ctrl + I 】向前追赶你的光标移动

These two shortcuts are useful in the tab page and in Windows to trace your cursor keys forward and backward, which also facilitates you to jump the cursor. "Ctrl + O" Backwards Rewind your cursor movement

System-related

【K】(大写K),调出当前光标下系统函数的manual手册

No plug-in vim programming tips

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.