Both "s" and "g" come from sed(1). The "s" stands for substitute and the "g" for global. The command "sed s/blah/meh/g" would replace all occurrences of "blah" with "meh" in the file, as opposed to "sed s/blah/meh/" which would just replace the first occurrence (if any) on each line.
Vim's s command has inherited this flag, although it doesn't really mean global; it just means to replace all the occurrences on the current line, as opposed to simply the first one on the line. If you want truly global scope, use :%s rather than :s. (The % works with other commands too; for example :%d will cut the entire file.)
Phillip Remaker's answer addresses your confusion spot on. Here are details of what some other vim commands stand for (and what they do). I am only considering the lower case commands here. Almost always, the upper case command does the same thing as lower case with slight changes.
- i - insert text
- a - append text
- y - yank text (Copy)
- x - cut text (Similar to regular cut shortcut, Ctrl-x)
- d - delete text (works similar to cut)
- p - paste text
- u - undo
- w - jump by start of words. Essentially go to next word and land at the beginning.
- e - jump to end of words. Essentially go to next word and land at the e
Phillip Remaker's answer addresses your confusion spot on. Here are details of what some other vim commands stand for (and what they do). I am only considering the lower case commands here. Almost always, the upper case command does the same thing as lower case with slight changes.
- i - insert text
- a - append text
- y - yank text (Copy)
- x - cut text (Similar to regular cut shortcut, Ctrl-x)
- d - delete text (works similar to cut)
- p - paste text
- u - undo
- w - jump by start of words. Essentially go to next word and land at the beginning.
- e - jump to end of words. Essentially go to next word and land at the end.
- b - jump backwards by words.
- $ - jump to end of line (Same as $ in regex)
- ^ - jump to first non-space character of the line (Similar to ^ in regex)
- 0 - Go to zeroth character of the line. (Essentially beginning of the line)
- >> - Shift text right
- << - Shift text left
- vsplit - Vertical Split.
- Ctrl-w - Control the windows after they are split.
- Ctrl-w followed by Left, Right, Up, Down arrows to toggle between the windows.
- Ctrl-w followed by Ctrl-r to rotate the windows.
- z - Control the folds. Use "Z-Fold" to memorize.
- zo - open the fold
- zc - close the fold
- ciw - change (cut) inner word.
- yiw - yank inner word.
These are the few I use. For more detailed list, 78 Keyboard Shortcuts for VIM.
Hope this helps.
Adding an "!" to the end of a command means "AND I MEAN IT DO NOT QUESTION ME!" This is just the same way you add an exclamation point to an English sentence for emphasis.
q is short for quit.
w is short for write (as in a file)
The commands are listed, left to right, in the order you want to execute them.
:w - write the file.
:q - quit the editor.
:wq - write and immediately quit.
These commands will throw an error message if you are about to overwrite a file or lose edits. That extra step is annoying for power users, so they shout the command at vi in order to bypass any questions.
:w! - WRIT
Adding an "!" to the end of a command means "AND I MEAN IT DO NOT QUESTION ME!" This is just the same way you add an exclamation point to an English sentence for emphasis.
q is short for quit.
w is short for write (as in a file)
The commands are listed, left to right, in the order you want to execute them.
:w - write the file.
:q - quit the editor.
:wq - write and immediately quit.
These commands will throw an error message if you are about to overwrite a file or lose edits. That extra step is annoying for power users, so they shout the command at vi in order to bypass any questions.
:w! - WRITE, GODDAMMIT!!! I DON'T CARE IF YOU OVERWRITE MY WORK!!
:q! - QUIT NOW!!! DO NOT QUESTION MY AUTHORITY!!
:wq! - I'M REALLY IN A HURRY HERE!! OVERWRITE THE FILE AND GET ME BACK TO THE SHELL, STAT!! I DO NOT HAVE TIME FOR YOUR TRIFLING QUESTIONS!
:qw! makes no sense, since you would quit before writing. Therefore, it is not a valid command.
Typing a number before a command says the number of times it will repeat (6dd to delete 6 lines) or the index for the command 45G is "go to line 45")
Typing a marker in a two-character action command (d-, f-, F-, y-, etc) will mark the scope of that command. For example { and } will jump to the beginning and end of a paragraph, but d{ and d} will delete from the current position to those places. Similarly, d) and d( will delete to the end or beginning of a sentence, respectively.
Remember that command interpretation happens left to right. Commands will be interpreted character by character as typed, so there needs to be some parsing uniqueness from left to right.
A ":" will start any command that has an arbirary length, or that will only be executed when "enter" is pressed, for example:
:w this_is_a_long_filename
It is also required for any command that might spawn a feedback message at the bottom of the screen (like quitting). It also allows ridiculously complex commands like a sophisticated set of deletions (see the ":d" command).
All of this is confusing to new users, but when you start working with big documents you will say, "boy, I wish there was an easy way to do $X," and you will find that there will be. vi has been honed by the refiners fire of many years serving lazy programmers looking to save keystrokes. You may come to love and appreciate its terse and quirky elegance.
PROTIP: With any well developed program, every time you think, "there should be an easier way to do this," chances are there is. You will not have been the first person to feel that pain.
Phillip did a good job with “ex” commands…which are not really vim commands, but older—and still part of vim.
Vim has its own language in “normal mode”, particularly when used with text objects. Being a modal editor, you add text in “insert mode”, and do most everything else in “normal mode” or other special modes closely associated with “normal mode”.
Generally speaking, the language is “modifier…verb”, e.g. “5d” will delete 5 lines starting with the line with the cursor. So, “d” to delete, “y” to copy (aka, “yank”), and “p” to put/paste. Usually, the commands are in lower case, and upper case
Phillip did a good job with “ex” commands…which are not really vim commands, but older—and still part of vim.
Vim has its own language in “normal mode”, particularly when used with text objects. Being a modal editor, you add text in “insert mode”, and do most everything else in “normal mode” or other special modes closely associated with “normal mode”.
Generally speaking, the language is “modifier…verb”, e.g. “5d” will delete 5 lines starting with the line with the cursor. So, “d” to delete, “y” to copy (aka, “yank”), and “p” to put/paste. Usually, the commands are in lower case, and upper case versions either reverse course or have another special meaning. (“P” will “put before”, while “p” will “put after”, “N” is “previous find”, while “n” is “next find”, “X” is “delete prior character” or “backspace”, while “x” is “delete next character”, but “D” is “delete till end of line”.
Text objects are a game-changer. A “daw” will “delete a word” (delete from cursor until a space, hyphen, or other punctuation. The “diw” will “delete inner word”, so if the cursor is in the middle of the word it will still delete the word…beginning to end. But, you can change the “w” to “s” to do the same to a sentence…or a “p” to affect a paragraph, etc.
Many “plugins” use the text objects to extend the functionality, like Tim Pope’s “Surround.” So, learning the text objects, and the “language” of Vim is very worthwhile, and can turn you into a champ of a developer.
Phillip, thank you for the reply requesting to change my post to an answer—still can’t figure out how to “change” a reply to an answer, but copy and paste still works. :-)
“G” in normal mode goes to the end of the buffer. With a number prefix, it will go to the specified line number. IOW, “1G” will go to the first line, while “$G” is a long way of stating “G”, as “$” is the end of file. A “shortcut” for “1G” is “gg”.
“G” cannot be used for going to a mark; see “:h G” for proof, as the help doesn’t mention marks, but line numbers.
To go to a named mark—or an unnamed mark—use the backtick or single-quote keys in normal mode, followed by the indicated mark. The backtick will go to the exact location of the mark, while single-quote will go to the beginning of the line
“G” in normal mode goes to the end of the buffer. With a number prefix, it will go to the specified line number. IOW, “1G” will go to the first line, while “$G” is a long way of stating “G”, as “$” is the end of file. A “shortcut” for “1G” is “gg”.
“G” cannot be used for going to a mark; see “:h G” for proof, as the help doesn’t mention marks, but line numbers.
To go to a named mark—or an unnamed mark—use the backtick or single-quote keys in normal mode, followed by the indicated mark. The backtick will go to the exact location of the mark, while single-quote will go to the beginning of the line containing the mark. The backtick and single-quote can also be used by themselves by hitting the keys twice, to toggle back and forth to previous location. Again, they work the same way, backtick going to the exact previous location, and single-quote going to the beginning of the line containing the last position.
HTH
Words that are spelled alike are homographs. Words that are pronounced alike are homophones. Homographs can be homophones.
RUN has about 150 or more different meanings (depending on the dictionary).
Here are some examples of 5-letter words that have multiple meanings.
BRAND
Symbols and styling associated with a company.
Affixing symbols to a product or object.
DRINK
A beverage.
To consume a beverage.
PAINT
A colored substance that is applied to an object and dries so that the object retains the coloring.
To apply a colored substance to an object.
A horse with a 2-color patch-like coat.
PATCH
A small
Words that are spelled alike are homographs. Words that are pronounced alike are homophones. Homographs can be homophones.
RUN has about 150 or more different meanings (depending on the dictionary).
Here are some examples of 5-letter words that have multiple meanings.
BRAND
Symbols and styling associated with a company.
Affixing symbols to a product or object.
DRINK
A beverage.
To consume a beverage.
PAINT
A colored substance that is applied to an object and dries so that the object retains the coloring.
To apply a colored substance to an object.
A horse with a 2-color patch-like coat.
PATCH
A small piece of a material meant to cover a hole.
To repair a hole.
PHONE
A communication device.
To use a communication device.
POINT
A sharp corner.
To indicate direction using a finger.
QUAIL
A bird.
To cower.
SPELL
To articulate the letters of a word.
A short amount of time.
WATER
H2O,
To hydrate plants.
Here are a few more: Adder, agape, brace, chest, close, float, flush, grave, gorge, leave, match, model, moped, mouse, novel, ought, pitch, plain, pound, rebel, recap, right, round, ruler, scale, sewer, sheer, short, spoke, stone, story, train, upset, virus, watch.
The original reason is that “vi” is the “VIsual editor”, as opposed to the normal editor, or just “ed”.
Most of the original Unix commands were two letters: “ls”, “df”, “cd”, etc.
“ed” is the “editor”, a line editor, where commands are accepted and performed on the file text, one or more lines at a time, whether or not they were displayed.
“vi” was originally a curses-based screen editor, or “visual” editor, with an interactive WYSIWYG (What You See Is What You Get) approach to editing text.
“vim” was developed out of the original “vi” code base, greatly enhanced and even given an internal program
The original reason is that “vi” is the “VIsual editor”, as opposed to the normal editor, or just “ed”.
Most of the original Unix commands were two letters: “ls”, “df”, “cd”, etc.
“ed” is the “editor”, a line editor, where commands are accepted and performed on the file text, one or more lines at a time, whether or not they were displayed.
“vi” was originally a curses-based screen editor, or “visual” editor, with an interactive WYSIWYG (What You See Is What You Get) approach to editing text.
“vim” was developed out of the original “vi” code base, greatly enhanced and even given an internal programming language, called “vimscript”.
“neovim” is a complete re-write of “vim”, mostly backward-compatible, with better multi-threading and multi-processing support.
Thank you for asking as it forced me to think a lot....
- ‘is' on adding h before ‘is' we get ‘his'.
- ‘Gater' generally means to spoil. On adding h after t, we get ‘gather' which means to accumulate.
- ‘as'. On adding h in the starting, we get ‘has'
- On adding h in the end, we get ‘ash'.
- ‘am'. On adding h in the starting, we get ‘ham' which means ‘pork'.
- “ ‘tis" is an informal way of writing “it is". On adding h after t we get ‘this'
- ‘soal' means (British english) a dirty pond. On adding h after s, we get ‘shoal' which has many different meanings like group, shallow, etc.
Upto now, I could think these 7 wor
Thank you for asking as it forced me to think a lot....
- ‘is' on adding h before ‘is' we get ‘his'.
- ‘Gater' generally means to spoil. On adding h after t, we get ‘gather' which means to accumulate.
- ‘as'. On adding h in the starting, we get ‘has'
- On adding h in the end, we get ‘ash'.
- ‘am'. On adding h in the starting, we get ‘ham' which means ‘pork'.
- “ ‘tis" is an informal way of writing “it is". On adding h after t we get ‘this'
- ‘soal' means (British english) a dirty pond. On adding h after s, we get ‘shoal' which has many different meanings like group, shallow, etc.
Upto now, I could think these 7 words. After sometime, I'll edit the answer as soon as I come across some more words.
Hope it helps.
Happy reading !!
Sure, it happens all the time in English. For example, “swallow” is a kind of bird; “swallow” is a also a verb. “Fly” is an insect; “fly” is also a verb.
So
“A swallow flies.” means that a specific kind of bird travels through the air.
“I swallow flies.” means that I have insects in my mouth, and I do the action with my throat muscles that transfers the flies into my stomach.
How do you tell the difference? Context. If you are talking about birds, about things that travel through the air, then the first sentence applies. There is also a slight difference between the sound of “a” (the indefinite ar
Sure, it happens all the time in English. For example, “swallow” is a kind of bird; “swallow” is a also a verb. “Fly” is an insect; “fly” is also a verb.
So
“A swallow flies.” means that a specific kind of bird travels through the air.
“I swallow flies.” means that I have insects in my mouth, and I do the action with my throat muscles that transfers the flies into my stomach.
How do you tell the difference? Context. If you are talking about birds, about things that travel through the air, then the first sentence applies. There is also a slight difference between the sound of “a” (the indefinite article) and “I” (first person singular pronoun) - and those small words provide context for the rest of the sentence. The “A” means that what comes next must be a noun or possibly a string of adjectives followed by a now, so “swallow” after “A” is understood to be a noun, so it is understood as a bird. Then after a noun you expect a verb, so “flies” after “swallow” in the first sentences is understood as a verb, third person singular present simple of “fly”. The whole sentence makes sense, because a swallow is a bird, and birds fly.
The second sentence starts with a subject pronoun, “I”. Because there is a subject pronoun, then what comes next has to be a verb - so we understand “swallow” in the second sentence as the verb “to swallow”. “Swallow” as a verb can be transitive - in other words you can put a noun (or noun phrase) after swallow to describe what is swallowed. So “flies” here is understood as a plural noun, the plural of the noun “fly”, a small annoying insect. So the whole sentence also makes sense, describing a slightly unpleasant action (at least, I wouldn’t want to eat flies…)
English is very sensitive to context; fortunately we aren’t usually limited just to the context within one sentence, but we can use the preceding and following text or discussion to understand what meaning is intended.
like "Jim" (and not vee-eye-em).
Reference: http://vimdoc.sourceforge.net/htmldoc/intro.html
If by writing, you mean hand written material, then put the last word by itself on the next line. If you don't like that appearance, add a short sentence as a seque to the next paragraph or simply to make the end more visually appealing. Same approach for documents prepared on a typewriter.
If you refer to output from a word processor or a layout program, you now enter the world of "type-setting." Here, there will be 2 sources to guide you:
- A style manual as instructed by the publisher. It will tell you what to do with danglers, widows, orphans and other visual aspects of the document.
- Your own i
If by writing, you mean hand written material, then put the last word by itself on the next line. If you don't like that appearance, add a short sentence as a seque to the next paragraph or simply to make the end more visually appealing. Same approach for documents prepared on a typewriter.
If you refer to output from a word processor or a layout program, you now enter the world of "type-setting." Here, there will be 2 sources to guide you:
- A style manual as instructed by the publisher. It will tell you what to do with danglers, widows, orphans and other visual aspects of the document.
- Your own idea of what "looks good."
Assuming the latter, your best bet for the dangler is to change the spacing between letters in the entire paragraph; either shrink them together to pull the word up, or expand to force a second or third word onto the same line.
Hope that helps.
:g runs a command on each line that matches a given pattern, in the form :g/pattern/cmd.
^ is a regex that matches the beginning of a line. So all lines, by definition, will match this pattern.
m0 moves a line to the 0th position (ie. the top of the buffer).
Put them all together:
:g iterates through each line, top down. Placing each successive line at the top of the file has the effect of reversing the order of lines.

viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html
If by advanced you mean infrequently used, likely many of the ex commands would fit, as would extensive use of registers. When coding, say I need to copy 10 lines of code which starts 15 lines above the cursor. “:-15,-5 t.” does the trick, pasting the lines below the current line. Obviously, the “-15,-5” is a range of lines using relative position (why I like relative line numbers), the “t” is the Copy command, and the “.” refers to the current line.
Other commands are yanking text into named registers; you can do this in normal mode or visual/command mode. Either way, you name registers with a
If by advanced you mean infrequently used, likely many of the ex commands would fit, as would extensive use of registers. When coding, say I need to copy 10 lines of code which starts 15 lines above the cursor. “:-15,-5 t.” does the trick, pasting the lines below the current line. Obviously, the “-15,-5” is a range of lines using relative position (why I like relative line numbers), the “t” is the Copy command, and the “.” refers to the current line.
Other commands are yanking text into named registers; you can do this in normal mode or visual/command mode. Either way, you name registers with a double-quote, like ‘:100,115 “ay’ would copy lines 100 thru 115 to register “a”. Pasting is done similarly, by double-quoting the “a” register followed by “p” to paste.
This is powerful stuff. If you use persistent undo, your undo state—including register contents—is written to a file, thus you can load up 10 registers or more with pre-written content you need to paste in several places, and continue working with the same saved registers the next day and the next, until you kill the register.
Depends on which language you are shootin to hear from. My americanism would say vehm. But to be a little more scandignavian, i might look at it as veem. But it i want to be a bit awkward i could run into vym, as if the y was a long i sound.
The :v
command is the same as :g!
, which is the opposite of :g
.
:g/pattern/command
executes command
on each line of the buffer that matches pattern
. Similarly :v/pattern/command
executes command
on each line of the buffer that does not match pattern
. The percentage sign at the beginning tells Vim to apply this command on the whole file, but is useless here because this is the default behavior of :v
and :g
.
Vim starts by marking each line that matches the pattern, then start again at the beginning of the file and executes the command on each line which matches (or not) the pattern. In your case,
The :v
command is the same as :g!
, which is the opposite of :g
.
:g/pattern/command
executes command
on each line of the buffer that matches pattern
. Similarly :v/pattern/command
executes command
on each line of the buffer that does not match pattern
. The percentage sign at the beginning tells Vim to apply this command on the whole file, but is useless here because this is the default behavior of :v
and :g
.
Vim starts by marking each line that matches the pattern, then start again at the beginning of the file and executes the command on each line which matches (or not) the pattern. In your case, it’s a replacement: s/foo/bar/g
replaces every occurrence of foo
with bar
in the current context. Without the trailing g
, it would only replace the first occurrence.
All have good answers. I didn’t see using marks, which presuppose prior maneuvering in a file. In conjunction with persistent undo, marks are a powerful tool. For example, I frequently need to reference a particular PL/SQL package source code in my local repository. I have places marks in a number of spots containing recognizable comments which tell me what each mark is. The marks persist from session to session. Then I have a mapping to execute the “marks” command, listing each possible mark (“a” through “z”—no shortcuts, the mapping actually has to list all 26 letters). Since there are “only
All have good answers. I didn’t see using marks, which presuppose prior maneuvering in a file. In conjunction with persistent undo, marks are a powerful tool. For example, I frequently need to reference a particular PL/SQL package source code in my local repository. I have places marks in a number of spots containing recognizable comments which tell me what each mark is. The marks persist from session to session. Then I have a mapping to execute the “marks” command, listing each possible mark (“a” through “z”—no shortcuts, the mapping actually has to list all 26 letters). Since there are “only” around 8–10 marks that I really need to see constantly, I have plenty of “room” for the occasional ad hoc mark when actively researching an issue.
G in command mode is used to go to a mark.
Use “m(letter)” to set a mark at the current location to a letter: a-z/A-Z.
If you must split a word, the rule is to split it between syl-
lables.
If the word is only one syllable it should not be split.
Make sure there are at least two letters plus the hy-
phen on the first line and three letters on the second.
vi
The abbreviation Visual Interactive doesn't seem to be right, although that is what turns up second in the Google results.
The first result is the Wikipedia page on vi that states
The name vi is derived from the shortest unambiguous abbreviation for the command
visual
in ex
ex
was a line editor in BSD Unix.
Vim
Vim stands for vi IMproved, and as the name suggests, is essentially an extended version of vi with added features. Take a look at Vim (text editor) for details about its history.
It is also worth nothing that Vim originally was an acronym for vi IMitation, but was later changed to vi IM
vi
The abbreviation Visual Interactive doesn't seem to be right, although that is what turns up second in the Google results.
The first result is the Wikipedia page on vi that states
The name vi is derived from the shortest unambiguous abbreviation for the command
visual
in ex
ex
was a line editor in BSD Unix.
Vim
Vim stands for vi IMproved, and as the name suggests, is essentially an extended version of vi with added features. Take a look at Vim (text editor) for details about its history.
It is also worth nothing that Vim originally was an acronym for vi IMitation, but was later changed to vi IMproved in its next version.
GCC, gcc
GCC stands for GNU Compiler Collection, where GNU stands for GNU's Not Unix. It includes compilers for C, C++, Objective-C and a host of other languages. Homepage - GCC, the GNU Compiler Collection.
It originally stood for GNU C Compiler, back when it only supported the C programming language.
The command gcc also means GNU Compiler Collection, and it essentially serves as a front-end for several compilers and the linker. Source - Page on stackoverflow.com
Off topic, you should also know that the actual compiler for C is cc1, and that for C++ is cc1plus. gcc is actually a driver that calls the Preprocessor, Compiler, Assembler, Linker as needed. Source - Page on stackoverflow.com
Hope that helped :)
Thanks for the A2A!
g:
is the usual prefix from global variable. There is the :g
command though (actually the :global
command).
Check their respective help entries:
:h g:
-> Vim: eval.txt:h :g
-> Vim: repeat.txt
The “g” is for global commands. It can still take a range, like “:1,14 g:/pattern/d” will delete any line containing the matching “pattern” for lines 1 through 14. The difference between “s” commands and “g” commands is that “s” does substitution, and “g” actually executes a command. The Vim Tips Wiki site has more information if you’d like to dive deeper.
Full Forms
Vi :Visual Interactive
Vim :Vi Improved
GCC:GNU Compiler Collection.
Currently GCC stands for GNU Compiler Collection as per http://gcc.gnu.org. It was earlier termed as GNU C Compiler. It is a compiler designed to support multiple programming languages and has been adopted as a standard compiler for Unix, Linux and other operating system of the BSD family.
It handled only C programming language in its initial days(back 1987). But today it has been extended to compile Objective-C, C++, Java, Fortran, Ada and Go.
Both Vi and Vim are text editors common to Unix-like systems. As n
Full Forms
Vi :Visual Interactive
Vim :Vi Improved
GCC:GNU Compiler Collection.
Currently GCC stands for GNU Compiler Collection as per http://gcc.gnu.org. It was earlier termed as GNU C Compiler. It is a compiler designed to support multiple programming languages and has been adopted as a standard compiler for Unix, Linux and other operating system of the BSD family.
It handled only C programming language in its initial days(back 1987). But today it has been extended to compile Objective-C, C++, Java, Fortran, Ada and Go.
Both Vi and Vim are text editors common to Unix-like systems. As name suggests Vim is the improved version of Vi. Vim is compatible with more wider range of OSs and includes support for several popular programming languages(Java,Perl etc.). Vim has GUI counterpart known as gvim. Features like syntax highlighting, provision for split and tabbed windows, multi-level undo-redo, spell-checking, editing files over network protocols such HTTP, SSH and FTP makes it really 'improved' over Vi.
Thanks for A2A.
The command joins consecutive blank lines into a single empty line. It returns an error if there are trailing new lines in your file
Meaning of different parts:
g - Global command (Vim documentation: repeat)
^$ - Regex to match empty line
,/. - Search pattern. Defines the range from current line(,) to the next non empty line (/.)
-j - Takes the end range as current line - 1 and performs a join (Vim documentation: change)
You should run vimtutor
from the command-line, which has been installed with vim, and which will learn you some basic commands. It's a 30min tutorial.
What they are doing is using the vim movement commands to great effect. You can move by word, by letter, by sentence, by paragraph, as well as matching brackets of varying types - as well as percentages of the file, and more.
Vim contains an entire help section dedicated to movement. Use this command to read it:
- :help motion.txt
This will provide you with all of the movement commands - of which there are many.
My company put together this short guide to doing something productive with Vim. Feel free to take a look and see if this gets you going in the right direction. The Command Line Novice’s Emergency Vim Guide
Vi - Visual interactive.
Vim - Vi IMproved.
GCC - GNU Compiler Collection
This will re-indent the whole file following the rules of the syntax script for the file type.
It is to be used in normal mode (if unsure, type ESC). 'gg’ means go to line 1, '=’ is the “indent” command, and 'G' moves the cursor to the end of file, giving the command the range it needs, which is the whole file.
It won't prettify a “compact” JavaScript or HTML file, though. The are other tools for that.
Here’s a good Quora thread with many vim commands: