vim tips

Keyword Lookup
The K command is designed to look up the selected text using the “man” command. It
works just like the normal-mode K command except that it uses the highlighted text
as the keyword.


Inserting Text
The command Istring<Esc> inserts the text on each line starting at the left side of
the visual block, as seen in Figure 6.9.
You start by pressing CTRL-V to enter visual block mode. Now you define your
block. Next you type I to enter insert mode followed by the text to insert. As you
type, the text appears on the first line. After you press <Esc> to end the insert, the text
will magically be inserted in the rest of the lines contained in the visual selection.
Figure 6.9 shows how this process works.
If the block spans short lines that do not extend into the block, the text is not
inserted in that line. Figure 6.10 illustrates what happens to short lines.
If the string contains a newline, the I acts just like a normal-mode insert (i) com-
mand and affects only the first line of the block.

The Vim editor has lots of commands that help the programmer indent his program
correctly.The first ones discussed here merely shift the text to the left (<<) or the
right (>>).
The left shift command (<<) shifts the current line one shift width to the left.The
right shift command (>>) does the same in the other direction. But what is a shift
width? By default, it is 8. However, studies have shown that an indentation of 4 spaces
for each level of logic is the most readable. So a shift width of 4 would be much nicer.
To change the size of the shift width, use the following command:

block = indent


The = Command
The =motion command indents the selected text using Vim’s internal formatting pro-
gram. If you want to indent a block of text, for example, you can use the = command
to do it.The motion in this case is the % (go to matching {}) command. Figure 7.5
shows the results.


Shifting a Block of Text Enclosed in {}
Suppose that you want to indent the text encoded in {} one level. Position the cursor
on the first (or last) {.
Execute the command >%.This shifts the text right to where the motion takes you.
In this case, % takes you to the matching {}.
Figure 7.14 shows how these commands work.

Unfortunately this shifts the {} in addition to the text. Suppose you just want to shift
what is in the {}.Then you need to do the following:
1. Position the cursor on the first {.
2. Execute the command >i{.

The K command gets the subject from the word under the cursor. But what if you need
to select the section number? It is simple; the K command takes a count argument. If
specified, this is used as the section number.Therefore, if you position the K over the
word mkdir and execute the 2K, you will get the mkdir(2) page.
You can customize the K command. It runs the program specified by the
'keywordprg' option. By default, on UNIX this is man.


The command :cprevious or :cNext goes to the previous error. Similarly, the com-
mand :clast goes to the last error and :crewind goes to the first.The :cnfile goes to
first error message for the next file (see Figure 7.28).
If you forget what the current error is, you can display it using the following
command:
:cc
To see a list of errors, execute this command:
:clist
Figure 7.29 shows the output of a :clist command.
If you want to list only a subset of the errors, you can give :clist a range of errors
to list. For example:
:clist 3,5
:clist ,5
:clist 5,
(List errors 3 through 5)
(List errors 1-5)
(List errors 5 to the end)
The Vim editor suppresses all informational messages. If you want everything, use the
following command:
:clist!
The override option (!) tells Vim to not suppress anything.

Saving Your Setting
After performing all your :map, :abbreviate, and :set commands, it would be nice if
you could save them and use them again.
The command :mkvimrc writes all your settings to a file.The format of this com-
mand is as follows:
:mkvimrc file
file is the name of the file to which you want to write the settings.
You can read this file by using the following command:
:source file
During startup, the Vim editor looks for an initialization file. If it is found, it is auto-
matically executed. (Only the first file found is read.)


Automatic Completion Details
For the most part, the Vim editor does the right thing when it comes to automatic
completion. At times, however, you might want to fine-tune your completions.
The ‘complete’ option controls where Vim searches for words.The form of this
option is as follows:
:set complete=key,key,key
key is a key letter (and possible argument).The possible key values are as follows:
. Current file
b Files in loaded buffers, not in a window
d Definitions in the current file and in files included by a #include directive
i Files included by the current file through the use of a #include directive
k The file defined by the ‘dictionary’ option (discussed later in this chapter)
kfile The file named {file}
t The “tags” file. (The ] character can be used as well.)
u Unloaded buffers
w Files in other windows



The S Command
The S command deletes the current line and puts the editor in insert mode. If a count
is specified, it deletes count lines.This differs from the C command in that the C com-
mand deletes from the current location to the end of the line, whereas the S command
always works on the entire line. Figure 18.18 illustrates the use of the S command.

Instant Word Searches
The * command searches for the word under the cursor. For example, position the
cursor on the first const. Pressing * moves the cursor to the next occurrence of the
word, specifically line 26. Figure 19.5 shows the results.


Special Registers
Vim has a number of special registers.The first is the unnamed register, whose name is
double quote (“).
Others include the registers 1 through 9. Register 1 contains the last text you
deleted; register 2 the next to last, and so on.
(Back in the bad old days of Vi, these registers were a lifesaver.You see, Vi had only
one level of undo. So if you deleted three lines by executing dd three times, you were
out of luck if you wanted to undo the delete using the u command. Fortunately, the
three lines were stored in registers 1, 2, and 3, so you could put them back with
“1P”2P”3P.You can also use the command “”P.. (“”P and two dots).
Other special registers include the following:
Register Description Writeable
0 The last yanked text Yes
- The last small delete No
. The last inserted text No
% The name of the current file No
# The name of the alternate file No
/ The last search string No
: The last “:” command No
_ The black hole (more on this later) Yes
= An expression (see next page) No
* The text selected with the mouse Yes

Spaces and Tabs
If you are using a combination of tabs and spaces, you just edit normally.The Vim
defaults do a fine job of handling things.
But you can make life a little easier by setting the ‘softtabstop’ option.This
option tells Vim to make the Tab key look and feel as if tabs were set at the value of
‘softtabstop’, but use a combination of tabs and spaces to fake things (see Figure 23.3).
After you execute the following command, every time you press the Tab key the
cursor moves to the next 4-column boundary:
:set softtabstop=4
The first time you press it, however, you get 4 spaces inserted in your text.The second
time, Vim takes out the 4 spaces and puts in a tab (thus taking you to column 8).


Smart Tabs
Another related option is the ‘smarttab’ option.With this option on (:set smarttab),
tabs inserted at the beginning of a line are treated like soft tabs.The tab size used in
this case is defined the ‘shiftwidth’ option.
But tabs inserted elsewhere in the text act just like normal tabs. Note that you must
have soft tabs off (:set softtabstop=0) for this option to work. Figure 23.4 shows
sample results.
Smart indenting is a combination of soft tabs and normal tabs.When you execute
the following command, Vim treats tabs at the beginning of a line differently:
:set smarttab
Suppose, for example, that you have the following settings:
:set shiftwidth=4
:set tabstop=8
:set smarttabs
Tab stops are every eight spaces and the indentation size is four spaces.When you type
<Tab> at the beginning of a line, the cursor will move over the indentation size (four
spaces). Doing a double <Tab> moves over two indention sizes (eight spaces [4*2]).


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值