annotate runtime/doc/usr_04.txt @ 32936:c517845bd10e v9.0.1776

patch 9.0.1776: No support for stable Python 3 ABI Commit: https://github.com/vim/vim/commit/c13b3d1350b60b94fe87f0761ea31c0e7fb6ebf3 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Sun Aug 20 21:18:38 2023 +0200 patch 9.0.1776: No support for stable Python 3 ABI Problem: No support for stable Python 3 ABI Solution: Support Python 3 stable ABI Commits: 1) Support Python 3 stable ABI to allow mixed version interoperatbility Vim currently supports embedding Python for use with plugins, and the "dynamic" linking option allows the user to specify a locally installed version of Python by setting `pythonthreedll`. However, one caveat is that the Python 3 libs are not binary compatible across minor versions, and mixing versions can potentially be dangerous (e.g. let's say Vim was linked against the Python 3.10 SDK, but the user sets `pythonthreedll` to a 3.11 lib). Usually, nothing bad happens, but in theory this could lead to crashes, memory corruption, and other unpredictable behaviors. It's also difficult for the user to tell something is wrong because Vim has no way of reporting what Python 3 version Vim was linked with. For Vim installed via a package manager, this usually isn't an issue because all the dependencies would already be figured out. For prebuilt Vim binaries like MacVim (my motivation for working on this), AppImage, and Win32 installer this could potentially be an issue as usually a single binary is distributed. This is more tricky when a new Python version is released, as there's a chicken-and-egg issue with deciding what Python version to build against and hard to keep in sync when a new Python version just drops and we have a mix of users of different Python versions, and a user just blindly upgrading to a new Python could lead to bad interactions with Vim. Python 3 does have a solution for this problem: stable ABI / limited API (see https://docs.python.org/3/c-api/stable.html). The C SDK limits the API to a set of functions that are promised to be stable across versions. This pull request adds an ifdef config that allows us to turn it on when building Vim. Vim binaries built with this option should be safe to freely link with any Python 3 libraies without having the constraint of having to use the same minor version. Note: Python 2 has no such concept and this doesn't change how Python 2 integration works (not that there is going to be a new version of Python 2 that would cause compatibility issues in the future anyway). --- Technical details: ====== The stable ABI can be accessed when we compile with the Python 3 limited API (by defining `Py_LIMITED_API`). The Python 3 code (in `if_python3.c` and `if_py_both.h`) would now handle this and switch to limited API mode. Without it set, Vim will still use the full API as before so this is an opt-in change. The main difference is that `PyType_Object` is now an opaque struct that we can't directly create "static types" out of, and we have to create type objects as "heap types" instead. This is because the struct is not stable and changes from version to version (e.g. 3.8 added a `tp_vectorcall` field to it). I had to change all the types to be allocated on the heap instead with just a pointer to them. Other functions are also simply missing in limited API, or they are introduced too late (e.g. `PyUnicode_AsUTF8AndSize` in 3.10) to it that we need some other ways to do the same thing, so I had to abstract a few things into macros, and sometimes re-implement functions like `PyObject_NEW`. One caveat is that in limited API, `OutputType` (used for replacing `sys.stdout`) no longer inherits from `PyStdPrinter_Type` which I don't think has any real issue other than minor differences in how they convert to a string and missing a couple functions like `mode()` and `fileno()`. Also fixed an existing bug where `tp_basicsize` was set incorrectly for `BufferObject`, `TabListObject, `WinListObject`. Technically, there could be a small performance drop, there is a little more indirection with accessing type objects, and some APIs like `PyUnicode_AsUTF8AndSize` are missing, but in practice I didn't see any difference, and any well-written Python plugin should try to avoid excessing callbacks to the `vim` module in Python anyway. I only tested limited API mode down to Python 3.7, which seemes to compile and work fine. I haven't tried earlier Python versions. 2) Fix PyIter_Check on older Python vers / type##Ptr unused warning For PyIter_Check, older versions exposed them as either macros (used in full API), or a function (for use in limited API). A previous change exposed PyIter_Check to the dynamic build because Python just moved it to function-only in 3.10 anyway. Because of that, just make sure we always grab the function in dynamic builds in earlier versions since that's what Python eventually did anyway. 3) Move Py_LIMITED_API define to configure script Can now use --with-python-stable-abi flag to customize what stable ABI version to target. Can also use an env var to do so as well. 4) Show +python/dyn-stable in :version, and allow has() feature query Not sure if the "/dyn-stable" suffix would break things, or whether we should do it another way. Or just don't show it in version and rely on has() feature checking. 5) Documentation first draft. Still need to implement v:python3_version 6) Fix PyIter_Check build breaks when compiling against Python 3.8 7) Add CI coverage stable ABI on Linux/Windows / make configurable on Windows This adds configurable options for Windows make files (both MinGW and MSVC). CI will also now exercise both traditional full API and stable ABI for Linux and Windows in the matrix for coverage. Also added a "dynamic" option to Linux matrix as a drive-by change to make other scripting languages like Ruby / Perl testable under both static and dynamic builds. 8) Fix inaccuracy in Windows docs Python's own docs are confusing but you don't actually want to use `python3.dll` for the dynamic linkage. 9) Add generated autoconf file 10) Add v:python3_version support This variable indicates the version of Python3 that Vim was built against (PY_VERSION_HEX), and will be useful to check whether the Python library you are loading in dynamically actually fits it. When built with stable ABI, it will be the limited ABI version instead (`Py_LIMITED_API`), which indicates the minimum version of Python 3 the user should have, rather than the exact match. When stable ABI is used, we won't be exposing PY_VERSION_HEX in this var because it just doesn't seem necessary to do so (the whole point of stable ABI is the promise that it will work across versions), and I don't want to confuse the user with too many variables. Also, cleaned up some documentation, and added help tags. 11) Fix Python 3.7 compat issues Fix a couple issues when using limited API < 3.8 - Crash on exit: In Python 3.7, if a heap-allocated type is destroyed before all instances are, it would cause a crash later. This happens when we destroyed `OptionsType` before calling `Py_Finalize` when using the limited API. To make it worse, later versions changed the semantics and now each instance has a strong reference to its own type and the recommendation has changed to have each instance de-ref its own type and have its type in GC traversal. To avoid dealing with these cross-version variations, we just don't free the heap type. They are static types in non-limited-API anyway and are designed to last through the entirety of the app, and we also don't restart the Python runtime and therefore do not need it to have absolutely 0 leaks. See: - https://docs.python.org/3/whatsnew/3.8.html#changes-in-the-c-api - https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-c-api - PyIter_Check: This function is not provided in limited APIs older than 3.8. Previously I was trying to mock it out using manual PyType_GetSlot() but it was brittle and also does not actually work properly for static types (it will generate a Python error). Just return false. It does mean using limited API < 3.8 is not recommended as you lose the functionality to handle iterators, but from playing with plugins I couldn't find it to be an issue. - Fix loading of PyIter_Check so it will be done when limited API < 3.8. Otherwise loading a 3.7 Python lib will fail even if limited API was specified to use it. 12) Make sure to only load `PyUnicode_AsUTF8AndSize` in needed in limited API We don't use this function unless limited API >= 3.10, but we were loading it regardless. Usually it's ok in Unix-like systems where Python just has a single lib that we load from, but in Windows where there is a separate python3.dll this would not work as the symbol would not have been exposed in this more limited DLL file. This makes it much clearer under what condition is this function needed. closes: #12032 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Sun, 20 Aug 2023 21:30:04 +0200
parents f8116058ca76
children 4635e43f2c6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29314
f8116058ca76 release version 9.0
Bram Moolenaar <Bram@vim.org>
parents: 24024
diff changeset
1 *usr_04.txt* For Vim version 9.0. Last change: 2021 Feb 22
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 VIM USER MANUAL - by Bram Moolenaar
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 Making small changes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 This chapter shows you several ways of making corrections and moving text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 around. It teaches you the three basic ways to change text: operator-motion,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 Visual mode and text objects.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 |04.1| Operators and motions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 |04.2| Changing text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 |04.3| Repeating a change
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15 |04.4| Visual mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 |04.5| Moving text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 |04.6| Copying text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 |04.7| Using the clipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 |04.8| Text objects
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 |04.9| Replace mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 |04.10| Conclusion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 Next chapter: |usr_05.txt| Set your settings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 Previous chapter: |usr_03.txt| Moving around
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 Table of contents: |usr_toc.txt|
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 *04.1* Operators and motions
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 In chapter 2 you learned the "x" command to delete a single character. And
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 using a count: "4x" deletes four characters.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 The "dw" command deletes a word. You may recognize the "w" command as the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 move word command. In fact, the "d" command may be followed by any motion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 command, and it deletes from the current location to the place where the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 cursor winds up.
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
36 The "4w" command, for example, moves the cursor over four words. The "d4w"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 command deletes four words.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 To err is human. To really foul up you need a computer. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 ------------------>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 d4w
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 To err is human. you need a computer. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 Vim only deletes up to the position where the motion takes the cursor. That's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 because Vim knows that you probably don't want to delete the first character
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 of a word. If you use the "e" command to move to the end of a word, Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 guesses that you do want to include that last character:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 To err is human. you need a computer. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 -------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 d2e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 To err is human. a computer. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 Whether the character under the cursor is included depends on the command you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 used to move to that character. The reference manual calls this "exclusive"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 when the character isn't included and "inclusive" when it is.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 The "$" command moves to the end of a line. The "d$" command deletes from the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 cursor to the end of the line. This is an inclusive motion, thus the last
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 character of the line is included in the delete operation:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 To err is human. a computer. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 ------------>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 d$
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 To err is human ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 There is a pattern here: operator-motion. You first type an operator command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 For example, "d" is the delete operator. Then you type a motion command like
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 "4l" or "w". This way you can operate on any text you can move over.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 *04.2* Changing text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 Another operator is "c", change. It acts just like the "d" operator, except
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 it leaves you in Insert mode. For example, "cw" changes a word. Or more
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 specifically, it deletes a word and then puts you in Insert mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 To err is human ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 ------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 c2wbe<Esc>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 To be human ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87 This "c2wbe<Esc>" contains these bits:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 c the change operator
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 2w move two words (they are deleted and Insert mode started)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 be insert this text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 <Esc> back to Normal mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
94 You will have noticed something strange: The space before "human" isn't
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
95 deleted. There is a saying that for every problem there is an answer that is
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
96 simple, clear, and wrong. That is the case with the example used here for the
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
97 "cw" command. The c operator works just like the d operator, with one
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
98 exception: "cw". It actually works like "ce", change to end of word. Thus
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
99 the space after the word isn't included. This is an exception that dates back
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
100 to the old Vi. Since many people are used to it now, the inconsistency has
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
101 remained in Vim.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 MORE CHANGES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
106 Like "dd" deletes a whole line, "cc" changes a whole line. It keeps the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
107 existing indent (leading white space) though.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
108
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
109 Just like "d$" deletes until the end of the line, "c$" changes until the end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
110 of the line. It's like doing "d$" to delete the text and then "a" to start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
111 Insert mode and append new text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
112
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
113
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
114 SHORTCUTS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
115
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
116 Some operator-motion commands are used so often that they have been given a
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
117 single-letter command:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
118
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
119 x stands for dl (delete character under the cursor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
120 X stands for dh (delete character left of the cursor)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
121 D stands for d$ (delete to end of the line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
122 C stands for c$ (change to end of the line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
123 s stands for cl (change one character)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
124 S stands for cc (change a whole line)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
125
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
126
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
127 WHERE TO PUT THE COUNT
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
128
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
129 The commands "3dw" and "d3w" delete three words. If you want to get really
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
130 picky about things, the first command, "3dw", deletes one word three times;
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
131 the command "d3w" deletes three words once. This is a difference without a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
132 distinction. You can actually put in two counts, however. For example,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 "3d2w" deletes two words, repeated three times, for a total of six words.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 REPLACING WITH ONE CHARACTER
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 The "r" command is not an operator. It waits for you to type a character, and
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 will replace the character under the cursor with it. You could do the same
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 with "cl" or with the "s" command, but with "r" you don't have to press <Esc>
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
141 to get back out of insert mode.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 there is somerhing grong here ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 rT rt rw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 There is something wrong here ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 Using a count with "r" causes that many characters to be replaced with the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 same character. Example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 There is something wrong here ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 5rx
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 There is something xxxxx here ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 To replace a character with a line break use "r<Enter>". This deletes one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 character and inserts a line break. Using a count here only applies to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 number of characters deleted: "4r<Enter>" replaces four characters with one
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 line break.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 *04.3* Repeating a change
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163
21676
1b345fb68ae3 Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 18879
diff changeset
164 The "." command is one of the simplest yet powerful commands in Vim. It
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 repeats the last change. For instance, suppose you are editing an HTML file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 and want to delete all the <B> tags. You position the cursor on the first <
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 and delete the <B> with the command "df>". You then go to the < of the next
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
168 </B> and delete it using the "." command. The "." command executes the last
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
169 change command (in this case, "df>"). To delete another tag, position the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 cursor on the < and use the "." command.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 To <B>generate</B> a table of <B>contents ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 f< find first < --->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 df> delete to > -->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 f< find next < --------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 . repeat df> --->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 f< find next < ------------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 . repeat df> -->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
180 The "." command works for all changes you make, except for "u" (undo), CTRL-R
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
181 (redo) and commands that start with a colon (:).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 Another example: You want to change the word "four" to "five". It appears
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 several times in your text. You can do this quickly with this sequence of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 commands:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187 /four<Enter> find the first string "four"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 cwfive<Esc> change the word to "five"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 n find the next "four"
6180
6921742f396a Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 5294
diff changeset
190 . repeat the change to "five"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 n find the next "four"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 . repeat the change
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 etc.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 *04.4* Visual mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198 To delete simple items the operator-motion changes work quite well. But often
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 it's not so easy to decide which command will move over the text you want to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 change. Then you can use Visual mode.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 You start Visual mode by pressing "v". You move the cursor over the text you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 want to work on. While you do this, the text is highlighted. Finally type
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 the operator command.
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
205 For example, to delete from the middle of one word to the middle of another
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
206 word:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208 This is an examination sample of visual mode ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 ---------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 velllld
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 This is an example of visual mode ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 When doing this you don't really have to count how many times you have to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215 press "l" to end up in the right position. You can immediately see what text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 will be deleted when you press "d".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
217
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
218 If at any time you decide you don't want to do anything with the highlighted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
219 text, just press <Esc> and Visual mode will stop without doing anything.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
220
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
221
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
222 SELECTING LINES
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
224 If you want to work on whole lines, use "V" to start Visual mode. You will
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
225 see right away that the whole line is highlighted, without moving around.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
226 When you move left or right nothing changes. When you move up or down the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
227 selection is extended whole lines at a time.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
228 For example, select three lines with "Vjj":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
229
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
230 +------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
231 | text more text |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
232 >> | more text more text | |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
233 selected lines >> | text text text | | Vjj
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
234 >> | text more | V
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
235 | more text more |
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
236 +------------------------+
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
237
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239 SELECTING BLOCKS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 If you want to work on a rectangular block of characters, use CTRL-V to start
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
242 Visual mode. This is very useful when working on tables.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
243
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
244 name Q1 Q2 Q3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 pierre 123 455 234
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
246 john 0 90 39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 steve 392 63 334
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 To delete the middle "Q2" column, move the cursor to the "Q" of "Q2". Press
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 CTRL-V to start blockwise Visual mode. Now move the cursor three lines down
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 with "3j" and to the next word with "w". You can see the first character of
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
252 the last column is included. To exclude it, use "h". Now press "d" and the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
253 middle column is gone.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
254
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
255
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
256 GOING TO THE OTHER SIDE
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
258 If you have selected some text in Visual mode, and discover that you need to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
259 change the other end of the selection, use the "o" command (Hint: o for other
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
260 end). The cursor will go to the other end, and you can move the cursor to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
261 change where the selection starts. Pressing "o" again brings you back to the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
262 other end.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264 When using blockwise selection, you have four corners. "o" only takes you to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 one of the other corners, diagonally. Use "O" to move to the other corner in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266 the same line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267
2033
de5a43c5eedc Update documentation files.
Bram Moolenaar <bram@zimbu.org>
parents: 1702
diff changeset
268 Note that "o" and "O" in Visual mode work very differently from Normal mode,
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269 where they open a new line below or above the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 *04.5* Moving text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
274 When you delete something with "d", "x", or another command, the text is
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
275 saved. You can paste it back by using the "p" command. (The Vim name for
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 this is put).
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 Take a look at how this works. First you will delete an entire line, by
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 putting the cursor on the line you want to delete and typing "dd". Now you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 move the cursor to where you want to put the line and use the "p" (put)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 command. The line is inserted on the line below the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 a line a line a line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 line 2 dd line 3 p line 3
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 line 3 line 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 Because you deleted an entire line, the "p" command placed the text line below
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 the cursor. If you delete part of a line (a word, for instance), the "p"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288 command puts it just after the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
289
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
290 Some more boring try text to out commands. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
291 ---->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
292 dw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
293
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
294 Some more boring text to out commands. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
295 ------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
296 welp
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
297
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
298 Some more boring text to try out commands. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
299
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
300
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 MORE ON PUTTING
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
303 The "P" command puts text like "p", but before the cursor. When you deleted a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
304 whole line with "dd", "P" will put it back above the cursor. When you deleted
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
305 a word with "dw", "P" will put it back just before the cursor.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
306
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
307 You can repeat putting as many times as you like. The same text will be used.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
308
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
309 You can use a count with "p" and "P". The text will be repeated as many times
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
310 as specified with the count. Thus "dd" and then "3p" puts three copies of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
311 same deleted line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
312
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
313
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
314 SWAPPING TWO CHARACTERS
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
315
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
316 Frequently when you are typing, your fingers get ahead of your brain (or the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
317 other way around?). The result is a typo such as "teh" for "the". Vim
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
318 makes it easy to correct such problems. Just put the cursor on the e of "teh"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
319 and execute the command "xp". This works as follows: "x" deletes the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
320 character e and places it in a register. "p" puts the text after the cursor,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
321 which is after the h.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
322
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
323 teh th the ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
324 x p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
325
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
326 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
327 *04.6* Copying text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
328
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
329 To copy text from one place to another, you could delete it, use "u" to undo
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
330 the deletion and then "p" to put it somewhere else. There is an easier way:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
331 yanking. The "y" operator copies text into a register. Then a "p" command
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
332 can be used to put it.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
333 Yanking is just a Vim name for copying. The "c" letter was already used
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
334 for the change operator, and "y" was still available. Calling this
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
335 operator "yank" made it easier to remember to use the "y" key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
336
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
337 Since "y" is an operator, you use "yw" to yank a word. A count is possible as
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
338 usual. To yank two words use "y2w". Example:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
339
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
340 let sqr = LongVariable * ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
341 -------------->
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
342 y2w
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
343
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
344 let sqr = LongVariable * ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
345 p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
346
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
347 let sqr = LongVariable * LongVariable ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
348
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
349 Notice that "yw" includes the white space after a word. If you don't want
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
350 this, use "ye".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
351
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
352 The "yy" command yanks a whole line, just like "dd" deletes a whole line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
353 Unexpectedly, while "D" deletes from the cursor to the end of the line, "Y"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354 works like "yy", it yanks the whole line. Watch out for this inconsistency!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
355 Use "y$" to yank to the end of the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
356
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
357 a text line yy a text line a text line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
358 line 2 line 2 p line 2
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
359 last line last line a text line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
360 last line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
361
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
362 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
363 *04.7* Using the clipboard
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
364
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
365 If you are using the GUI version of Vim (gvim), you can find the "Copy" item
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
366 in the "Edit" menu. First select some text with Visual mode, then use the
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
367 Edit/Copy menu item. The selected text is now copied to the clipboard. You
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
368 can paste the text in other programs. In Vim itself too.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
369
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
370 If you have copied text to the clipboard in another application, you can paste
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
371 it in Vim with the Edit/Paste menu item. This works in Normal mode and Insert
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
372 mode. In Visual mode the selected text is replaced with the pasted text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
373
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
374 The "Cut" menu item deletes the text before it's put on the clipboard. The
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
375 "Copy", "Cut" and "Paste" items are also available in the popup menu (only
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
376 when there is a popup menu, of course). If your Vim has a toolbar, you can
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
377 also find these items there.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
378
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
379 If you are not using the GUI, or if you don't like using a menu, you have to
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
380 use another way. You use the normal "y" (yank) and "p" (put) commands, but
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
381 prepend "* (double-quote star) before it. To copy a line to the clipboard: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
382
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
383 "*yy
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
384
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
385 To put text from the clipboard back into the text: >
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
386
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
387 "*p
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
388
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
389 This only works on versions of Vim that include clipboard support. More about
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
390 the clipboard can be found in section |09.3| and here: |clipboard|.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
391
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
392 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
393 *04.8* Text objects
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
394
1125
96cd8222a819 updated for version 7.1a
vimboss
parents: 874
diff changeset
395 If the cursor is in the middle of a word and you want to delete that word, you
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
396 need to move back to its start before you can do "dw". There is a simpler way
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
397 to do this: "daw".
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
398
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
399 this is some example text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
400 daw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
401
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
402 this is some text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
403
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
404 The "d" of "daw" is the delete operator. "aw" is a text object. Hint: "aw"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
405 stands for "A Word". Thus "daw" is "Delete A Word". To be precise, the white
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
406 space after the word is also deleted (or the white space before the word if at
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
407 the end of the line).
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
408
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
409 Using text objects is the third way to make changes in Vim. We already had
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
410 operator-motion and Visual mode. Now we add operator-text object.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411 It is very similar to operator-motion, but instead of operating on the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 between the cursor position before and after a movement command, the text
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
413 object is used as a whole. It doesn't matter where in the object the cursor
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 was.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 To change a whole sentence use "cis". Take this text:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 Hello there. This ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 is an example. Just ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
420 some text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
421
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
422 Move to the start of the second line, on "is an". Now use "cis":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
423
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
424 Hello there. Just ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 some text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
426
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
427 The cursor is in between the blanks in the first line. Now you type the new
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
428 sentence "Another line.":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
429
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
430 Hello there. Another line. Just ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 some text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433 "cis" consists of the "c" (change) operator and the "is" text object. This
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
434 stands for "Inner Sentence". There is also the "as" ("A Sentence") object.
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
435 The difference is that "as" includes the white space after the sentence and
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
436 "is" doesn't. If you would delete a sentence, you want to delete the white
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
437 space at the same time, thus use "das". If you want to type new text the
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
438 white space can remain, thus you use "cis".
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 You can also use text objects in Visual mode. It will include the text object
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 in the Visual selection. Visual mode continues, thus you can do this several
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 times. For example, start Visual mode with "v" and select a sentence with
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 "as". Now you can repeat "as" to include more sentences. Finally you use an
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 operator to do something with the selected sentences.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 You can find a long list of text objects here: |text-objects|.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 *04.9* Replace mode
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 The "R" command causes Vim to enter replace mode. In this mode, each
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 character you type replaces the one under the cursor. This continues until
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 you type <Esc>.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 In this example you start Replace mode on the first "t" of "text":
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 This is text. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 Rinteresting.<Esc>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 This is interesting. ~
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 You may have noticed that this command replaced 5 characters in the line with
237
73354c21f1e4 updated for version 7.0066
vimboss
parents: 7
diff changeset
462 twelve others. The "R" command automatically extends the line if it runs out
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 of characters to replace. It will not continue on the next line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 You can switch between Insert mode and Replace mode with the <Insert> key.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466
24024
ef454a7f485d Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 21676
diff changeset
467 When you use <BS> (backspace) to make a correction, you will notice that the
ef454a7f485d Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 21676
diff changeset
468 old text is put back. Thus it works like an undo command for the previously
ef454a7f485d Update runtime files.
Bram Moolenaar <Bram@vim.org>
parents: 21676
diff changeset
469 typed character.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 *04.10* Conclusion
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
474 The operators, movement commands and text objects give you the possibility to
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
475 make lots of combinations. Now that you know how they work, you can use N
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 operators with M movement commands to make N * M commands!
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
478 You can find a list of operators here: |operator|.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 For example, there are many other ways to delete pieces of text. Here are a
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
481 few common ones:
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 x delete character under the cursor (short for "dl")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 X delete character before the cursor (short for "dh")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 D delete from cursor to end of line (short for "d$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 dw delete from cursor to next start of word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 db delete from cursor to previous start of word
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 diw delete word under the cursor (excluding white space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 daw delete word under the cursor (including white space)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 dG delete until the end of the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 dgg delete until the start of the file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 If you use "c" instead of "d" they become change commands. And with "y" you
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 yank the text. And so forth.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
497 There are a few common commands to make changes that didn't fit somewhere
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 else:
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
500 ~ Change case of the character under the cursor, and move the
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 cursor to the next character. This is not an operator (unless
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502 'tildeop' is set), thus you can't use it with a motion
18719
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
503 command. It does work in Visual mode, where it changes case
99586852c2db Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14519
diff changeset
504 for all the selected text.
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 I Start Insert mode after moving the cursor to the first
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 non-blank in the line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
508
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
509 A Start Insert mode after moving the cursor to the end of the
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
510 line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
511
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
512 ==============================================================================
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
513
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
514 Next chapter: |usr_05.txt| Set your settings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
515
14519
5c5908e81e93 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 13963
diff changeset
516 Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: