Vim editor tutorial pdf




















Vim Tutorial - The official Vim documentation is excellent and includes a step-by-step tutorial. You can also access this tutorial inside the Vim program through the :vimtutor command. If you spend a lot of time typing text, learning Vim will be totally worth the effort.

I wrote this article inside Visual Studio Code with Vim key bindings. He holds an engineering degree in Computer Science I. Read more on Lifehacker and YourStory. We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

Published in: Code. Share on:. No problem. We have you covered! Note that this is an article explicitly for beginners new to Vim. Vim is the editor of choice for many developers and power users. It inherits the key bindings of vi, but also adds a great deal of functionality and extensibility that are missing from the original vi. What the heck do we mean by modal?

In Vim, the mode that the editor is in determines whether the alphanumeric keys will input those characters or move the cursor through the document. For example, many text editors and word processors require you to use the mouse to click a menu item or icon, or use the Ctrl-s hotkey combination, to save a file. In Vim, you can save a file without your hands leaving the keyboard, and sometimes without even leaving the home keys.

More on that later. So, why would you want to learn Vim? Vi is the lingua franca of system administration. You might be skeptical. The first week was painful.

The month after that was okay. Some people disagree on how many modes Vim actually has. When you run vim filename to edit a file, Vim starts out in command mode. This means that all the alphanumeric keys are bound to commands, rather than inserting those characters. To get out of insert mode, hit the Escape key. No problem, press : and Vim will switch to last-line mode. Vim is now waiting for you to enter a command like :w to write the file or :q to exit the editor.

After the new text is entered, vi remains in the insert mode. Copies the current word from the character the lowercase w cursor is on, until the end of the word. This helps undo the last change that was done in the file. Typing 'u' again will re-do the change. In case you open multiple files using vi, use :p to go to the previous file in the series. In case you open multiple files using vi, use :N to go to the previous file in the series.

The vi editor has two kinds of searches: string and character. When you start these commands, the command just typed will be shown on the last line of the screen, where you type the particular string to look for. The n and N commands repeat the previous search command in the same or the opposite direction, respectively.

Some characters have special meanings. This is put in an expression escaped with the backslash to find the ending or the beginning of a word. The character search searches within one line to find a character entered after the command. The f and F commands search for a character on the current line only. The t and T commands search for a character on the current line only, but for t , the cursor moves to the position before the character, and T searches the line backwards to the position after the character.

You can change the look and feel of your vi screen using the following :set commands. Once you are in the command mode, type :set followed by any of the following commands. Sets the width of a software tabstop.

If wrapscan is set, and the word is not found at the bottom of the file, it will try searching for it at the beginning. If this option has a value greater than zero, the editor will automatically "word wrap". The vi has the capability to run commands from within the editor.

To run a command, you only need to go to the command mode and type :! So your right index and middle fingers move you up and down lines, and your index and ring fingers move you left and right by one character.

When you use uppercase you ignore some delimiters within a string that may break it into two words. This uppercasing of a given command having different and more powerful effects is something we'll see frequently. While you're in normal mode it's possible to jump back and forth between two places, which can be extremely handy. Ok, so we've done a bunch of moving within our text; now let's make some changes.

The first thing to remember is that the motions will always be with us—they're part of the language they're modifiers in the vocabulary above. Image from Michael Jakl. The first thing we need to grasp is the concept of modes. It's a bit counterintuitive at first but it becomes second nature once you grok it.

Most guides start with this bit, but I find it a bit obtuse to lead with, and I think the transition point from Normal to Insert is a great place to introduce it. There are some other modes as well, but we won't mess with them here as they tend to live outside primer territory. Let's recall our language: Verb, Modifier, Noun.

So we're assuming we're starting in Normal Mode, and we're going to switch into Insert Mode in order to change something. Our verb is going to start us off, and we have a few options. We can change c , insert i , or append a , and we can do variations on these, as seen below. As you can see, there are lots of ways to start entering text. There are also some shortcuts shown above as well for doing multiple things at once, such as deletion and entering Insert Mode.

It works as you'd imagine—either on the letter under the cursor, or on a selection. It's sometimes helpful to format text quickly, such as paragraphs, and this can easily be done with the following command:.

Now that we know how to change text, let's see how to do straight deletes. As you're probably getting now, it's very similar—just a different action to start things off. You can't have a text editor without undo and redo.

As you've probably noticed, Vim does its best to make the keys for the actions feel intuitive, and undo and redo are not exceptions. Both commands can be used repeatedly, until you either go all the way back to the last save, or all the way forward to your current state. One of the most powerful commands in all of Vim is the period ". Well, the period ". Many tasks you do will make a lot of sense to repeat. Going into insert mode and adding some text, for example. You can do it once and then just move around and add it again with just the ".

Another text editor essential is being able to quickly copy and paste text, and Vim is masterful at it. Vim does copying a bit different than one might expect. The command isn't c , as one might expect. If you'll remember, c is already taken for "change". Vim instead uses y for "yank" as it's copy command and shortcut. Remember, just like with any other copy you're not messing with the source text—you're just making another Cutting text is simple: it's the same as deleting.

So whatever syntax you're using for that, you're actually just pulling that deleted text into a buffer and preparing it to be pasted. Pasting is fairly intuitive—it uses the p command as its base.

So, if you delete a line using dd , you can paste it back using p. Also remember that you can undo any paste with the universal undo command " u ". This is a quick trick you can use to swap the position of two lines of text. The first part deletes the line you're on, and the second part puts it back above where it used to be. We'd be in pretty bad shape if we couldn't spellcheck, and vim does it quite well. First we need to set the option within our conf file. When you have set spell enabled within your conf file, misspelled words are automatically underlined for you.

You can also enable or disable this by running :set spell and :set nospell. Either way, once you've got some misspellings you can then advance through them and take action using the following commands:. The first just makes it easy to "fix" something:.

This one gets rid of spellchecking when I don't want to see it—like when I'm in creative mode. I can then re-toggle it with the same command.

Another powerful feature of Vim is its ability to do powerful substitutions. They're done by specifying what you're looking for first, then what you're changing it to, then the scope of the change.



0コメント

  • 1000 / 1000