47

From Vim's documentation, :x and ZZ are equivalent; they only save the file if it has been modified, then quit Vim: Write current file, if modified, and quit (same as ":x"). (Note: If there are several windows for the current file, the file is written if it was modified and the window is closed). :wq on the other hand writes the file and quits Vim (...


31

There actually is a help command in Vim to tell you about the differences: :help vi_diff (note the underscore: :help vi_diff) From Vim's site, the biggest are: unlimited undo You can do xxxx and undo each of the four deletes. When was the last time you typed "jjjj" and then found out the caps lock key was on? You accidentally joined five lines ...


26

From nvi(1): HISTORY The ex editor first appeared in 1BSD. The nex/nvi replacements for the ex/vi editor first appeared in 4.4BSD. Some background, from memory, so I hope got the details correct: In the beginning, UNIX was free. Everyone could request a copy from Ken, and he would send you a tape with the source (allegedly with the text "love, ...


23

As akshay pointed out, Vim's documentation explains, that :x and ZZ are equivalent and only save a file if the associated buffer has been changed. Whereas :wq saves the buffer to the corresponding file, even if it is unchanged. In both cases, the contents of the buffer will be saved to disk. Obviously the outcome is the same, so why bother, right? But wait....


18

From nvi(1): u Undo the last change made to the file. If repeated, the u command alternates between these two states. The . command, when used immediately after u, causes the change log to be rolled forward or backward, depending on the action of the u command. So press u, and then keep pressing . for more undo; If you ...


18

I found a paper "An Introduction to Display Editing with Vi" by William Joy (vi creator) and Mark Horton (vi maintainer since 1979). From the paper it is clear that the default Y behavior is not a mistake, but a desired feature. In the "Rearranging and duplicating text" section they mention this: Try the command YP. This makes a copy of the current line ...


17

Y was the yank command of the first vi version (ex-1.1, January 1, 1978). This version did not have the yy cammand. ex-2.2 (May 6, 1979) did have both yy and Y. So actually yy is a synonym for Y (Y predates yy).


14

Vim has many features that Vi does not, even features that are not obviously "advanced" features. In practice, this means that if you are used to Vi, you will likely encounter very few differences if you start using Vim (or some other Vi clone), but if you are used to Vim and if your "reflexes" include features such as visual mode highlighting, any key ...


5

Bill Joy (the original author of vi) explains this in An Introduction to Display Editing with Vi. The [[ and ]] operations require the operation character to be doubled because they can move the cursor far from where it currently is. While it is easy to get back with the command ``, these commands would still be frustrating if they were easy to hit ...


4

This is answered to some degree in statox's answer to the question you linked. The key to your question is an understanding of vi's registers. When you yank text, it gets placed in register 0, and the unnamed register gets pointed to register 0. When you delete text, it gets placed in register 1, and the unnamed register gets pointed to register 1. When ...


4

Most comparisons give more functionality to Vim than to vi, but there is one exception. There was an "open" mode in vi, and Vim doesn't really have this mode. Open mode is a single-line mode that was used back in the day with terminals that didn't have electronic displays, i.e. teletypes, letterprinters, and the like, and also with displays where the cursor ...


3

The Vim FAQ has a well formatted list: https://vimhelp.org/vim_faq.txt.html#faq-1.4 Excerpt from the FAQ: Multi-level undo Tabs, Multiple windows and buffers Flexible insert mode (can use arrow keys in Insert Mode) Macros Visual mode (visually select sections of text) Block operators Online help system Command-line editing and history Command line ...


3

is Vim minimal (i.e. the default vi on Cygwin) basically a POSIX compliant implementation of vi? No. The vi in Cygwin's vim-minimal package still has features not defined by POSIX. I've verified the availability of visual mode and windowing support, for example. What other common 'minimal' vi's exist? BSD's nvi is pretty minimal, though it has some ...


3

vi was designed for use with glass terminals, the protocols of which often use many of the control-x commands down at the low end of ASCII. Others were reassigned in the move from paper terminals, such as Ctrl-L (form feed), which vi reinterprets from "form feed" to mean "repaint display" instead, that being more appropriate to a text editor. Commands like "...


3

This will be a bit convoluted, but, try: :map q :%s/Name. /\^V^V^M&/g^M Each ^x is produced by pressing CtrlVCtrlx, so the actual sequence here is: CtrlV CtrlV for the first ^V, CtrlV CtrlV for the second ^V, CtrlV Enter for the first ^M. And again for the last ^M. From man ex: Lines may be split by substituting new-line characters into them. The ...


3

Vim In Vim you can match any character including newline with \_.. You can use this to construct a pattern that matches a whole line, any amount of stuff, and then that same line: /\(^.*$\)\_.*\n\1$/ Now you want to delete all lines in a file that match the first, not including the first. The substitution to delete the last line that matches the first is: ...


3

When I used to use a real vi, I'd write to and read from a file, like you mention in your comment. I had something like this in my .exrc: ab wtemp w !/bin/cat > ~/temp ab rtemp r !/bin/cat ~/temp So to yank the current line: :.wtemp Or set marks, then: :'a,'b wtemp Then hit ^6 to switch to the alternate file (same as :e #), then: :rtemp You can ...


3

In original vi, and in tools with POSIX BRE or ERE, there's no way to look for strings not at the beginning of the line. However, in all of these, you can use regex groups to match any character before your actual target pattern, and then keep it unchanged in the replacement. In general, when you want to insert something between two strings, you use groups, ...


3

The key syntax with brackets, such as <Esc>, is specific to Vim. In plain vi, you need to enter an actual ESC character in your mapping. You can do so by pressing Ctrl+V, followed by ESC, which will insert an actual ESC and will be displayed as ^[. The command will look like: :inoremap jj ^[ But note that the ^[ is a single ESC character and is ...


3

If you want to run Vim, then type vim. ☺ On a more serious note, most of the Linux distributions provide different builds of Vim, with varying feature levels (i.e., the --with-features=... argument when running ./configure), GUI support, and enabled language bindings. Speaking with my Debian maintainer hat on, I provide these packages: vim-tiny: small ...


2

As mentioned by Christian Brabandt, the OP has small vim. The solution is to install the vim package. One can usually tell the difference with vim --version.


2

The original Vi does support modelines of the second form, however, modelines has to be set before the file is read. The manpage of ex says: modelines, ml default: nomodelines If modelines is set, then the first 5 lines and the last five lines of the file will be checked for ex command lines and the comands issued. To be ...


2

You could use a negative lookbehind: \(^\)\@<!Name\d \( \) Are special matching parentheses ^ Is beginning of line, of course \@<! is a negative lookbehind. Essentially, if it finds what's in the parentheses, it excludes it from the match. See :h \@<! for more information.


2

It would appear that the only POSIX way to do this is to use an external filter, such as sed. For example, to delete the 17th line of your file only if it is exactly identical to the 5th line, and otherwise leave it unchanged, you can do the following: :1,17!sed '5h;17{G;/^\(.*\)\n\1$/d;s/\n.*$//;}' (You could run sed on the entire buffer here, or you ...


2

The roots of the family trees of vi clones seem to be: 1977: "Traditional vi", Bill Joy's original source, ported and free to use since 2002. 1985: microEmacs, from which the vi-alike "vile" was developed 1987: stevie, from which vim and xvi were developed 1990: elvis, from which nvi was developed 2000: busybox's "tiny vi"


2

You could create an alias that sets your $TERM variable alias vi='TERM=rxvt-unicode-256color vi' Add that to your shell's rc file and it should be defined for every terminal you launch.


2

The text is dragged/moved/pulled/yanked into to clipboard. It's just a synonymous found to be easy to remember the y key, since all other keys are used.


2

Once the cursor is on the @ you can press s to "substitute" the current character. This will delete the current character and leave you in insert mode. Basically, you could replace all your xi and xa with s: map! [ [?]@^[F?s map! { {?}@^[F?s map! ^V^I ^[f@s


2

So it turns out that all Vi clones are, well, different. For example, 0"ayh clears register "a" in Vim, but not in Elvis; while 0"ad0 works in Elvis, but not in Vim. As Busybox seems to ship "Vi" of its own, you have no other choice than to experiment and to find the right keys yourself.


1

I can't speak to the history of the command, but I think of [ and ] as previous and next. It's used for many motions. See help various-motions for several examples of square bracket motions. Therefore, <C-]> becomes "Control-Next". help CTRL-] describes it as "Jump to the definition". When I'm pairing that's a bit long winded, so I usually say "drill ...


Only top voted, non community-wiki answers of a minimum length are eligible