In Vim, there is a solution. Vim can automatically replace tabs to spaces. So, when you insert tab into your code, Vim will automatically replace it with 4 white spaces. To replace tabs with white spaces, type in the following Vim command in your vimrc file.
Luckily, Vim has remedies for that. To do that, open your vimrc file and type in the following Vim command:. You can add Vim functions and other commands on the vimrc file to configure Vim. I was born in Bangladesh. Vim is an open source command line text editor. To delete a line, position the cursor anywhere on the line and type dd. The line and the space it occupied are removed.
The vi editor also includes these features. The methods for copying or moving small blocks of text in vi involves the use of a combination of the yank , delete , and put commands. Note that Y does the same thing as yy. The yy command works well with a count: to yank 11 lines, for example, type 11yy. Eleven lines, counting down from the cursor, are yanked, and vi indicates this with a message at the bottom of the screen: 11 lines yanked.
You can also use the P or p commands immediately after any of the deletion commands discussed earlier. This action puts the text you deleted above or below the cursor, respectively. Use only cursor-moving commands between yanking or deleting and putting. If you delete or yank any other text before putting the new text in place, the lines you yanked or deleted are lost. To move one line, position the cursor anywhere on the line and type dd.
For example, to delete 5 lines, type 5dd. Next, move the cursor to the line above where you want the deleted line reinserted and type p. This inserts the text on a new line below the cursor. Many vi commands can be preceded by a repeat factor called a count —a number that precedes the command and tells it how many times to repeat the operation.
Most of the commands in the previous sections take counts. For instance, 3dd repeats the command to delete a line three times, therefore deleting three lines.
You can also use counts with commands to move the cursor, such as 3w and 2Ctrl-F. Typing a period. For example, if you have just deleted a line with dd , you can move the cursor to another line and delete it by simply typing a period.
Rather than counting lines on the screen and then searching for an insertion point, you give vi a range of lines to be moved or copied and then specify the line before the insertion point. Of course, with a delete command there is no insertion point. To turn line numbers on , type :set nu and press Return. Line numbers appear in the left margin. Note that these numbers do not appear when you print out the file.
They are visible only on the screen. To turn line numbers off , type :set nonu and press Return. The basic form of the ex copy command is:. The first two numbers separated by a comma specify the range of lines to be copied. The third number is the line before the insertion point. For example, to copy lines 1 through 5 of paint and place the copy after line 12, you would type the following:. The basic form of the ex move command is similar to the copy command that is discussed in the previous section.
Line ranges and insertion points are specified in the same ways, including use of the abbreviations. To delete a range of lines, use the command form:. A character string is one or more characters in succession. A string might include letters, numbers, punctuation, special characters, blank spaces, tabs, or carriage returns. A string can be a grammatical word or it can be part of a word. Type n to go to the next occurrence of the string. Type N to go to the previous occurrence. To search backward in a file, you can use?
In this situation, the directions of n and N are reversed. To change it back to the default, case-sensitive mode, type :set noic. If vi finds the requested string, the cursor stops at its first occurrence.
If the string is not found, vi displays Pattern not found on the last line of the screen. You can use these special characters as commands to the search function. If you want to search for a string that includes one or more of these characters, you must precede the special character with a backslash.
You can make searches more precise by tagging the string with indicators for the following characteristics:. Thus, to match a word, rather than a string, combine the end-of-word and beginning-of-word tags in the search pattern. To match any character, type a period. To search for alternative characters in a string, enclose the alternatives in brackets. You can effectively combine brackets and the asterisk to look for well-defined alternatives.
The procedure for replacing a text string is based on the search procedures that are discussed previously. You can use all the special matching characters for searches in search-and-replace. You can modify this command to halt the search and make vi query whether you want to make the replacement in each instance. Respond with y for yes or n for no. To go to the last line of an open file, type G.
To return to the first line of the file, type 1G. For example, suppose that you quit the file paint while editing line You can access that line by opening the file and typing 51G.
The general form of the command is:. If you do not specify a line number, vi inserts the file at the current cursor position. For example, if you wanted to insert the file orwell at line 84 of the file paint , you would type:. For example, to edit the file orwell while you are editing paint :. To edit orwell , type :n orwell and press Return.
When you are finished working with orwell and have saved your work, you have three choices:. Return to paint. Type :n and press Return. Change case of letter uppercase or lowercase. Note — The view utility is a read-only version of vi. Starting vi The following sections describe how to start vi , type text in a file, save write the file, and quit vi.
The vi editing screen appears in a moment: Figure 6—1 vi Editing Screen The cursor appears in the upper left corner of the screen. Status Line The last line of the screen, called the status line , shows the name of the file and the number of lines and characters in the file. Two Modes of vi Two modes of operation in vi are entry mode and command mode. Note — Occasionally you might need to instruct vi to clear or redraw the screen to eliminate, for example, extraneous system messages.
Command Mode When you open a file with vi , you are in command mode. Ending a Session When you edit a file in vi , your changes are not made directly to the file. Caution — Although it's possible to run multiple, simultaneous vi sessions on one file, it is not a good idea. Saving Changes and Quitting vi vi is rich in substantively synonymous commands that control the save of the buffer contents to a file and the exit from vi.
Saving Save the contents of the buffer write the buffer to the file on disk by typing: :w Press Return. Saving and Quitting Save and quit by typing: :wq Press Return. Alternatively, type ZZ. Quitting Without Saving When you've made no changes to a file and want to quit, type: :q Press Return. Basic vi Commands The following sections explain the following categories of vi commands.
Moving around in a file Inserting text Changing and substituting text Undoing changes to text Deleting text Checking your spelling Formatting your file output Repeating commands Moving Around in a File In the previous sections you learned how to create, save, print, and exit a vi file. Moving the Cursor When you start vi , the cursor is in the upper left corner of the vi screen.
Note — Most vi commands are case sensitive. Moving With Arrow Keys If your machine is equipped with arrow keys, try these now. If the arrow keys don't work for you, you can use the following substitutes: To move left, press h. To move down, press j. To move up, press k. Moving Left Press the Back Space key to move the cursor one character to the left.
Moving Right Press the Space Bar to move the cursor one character to the right. Paging and Scrolling If you move down when the cursor is at the bottom of the screen, or move up when the cursor is at the top of the screen, you will see the text scroll up or down. Page Backward One Screen To scroll backward that is. Inserting Text vi provides many commands for inserting text.
Append Type a append to insert text to the right of the cursor. Insert Insert text to the left of the cursor by typing i from command mode. Open Line Use these commands to open new lines, either above or below the current cursor position. Changing Text Changing text involves the substitution of one section of text for another.
Changing a Word To replace a word, position the cursor at the beginning of the word to be replaced. Once you refresh the bashrc file using the source command, your bash prompt will change like the image below. You can also change the limit of command history that is displayed when the UP arrow is pressed. Redundant command sequences can be put in bashrc under a function. This will save a lot of time and effort. While editing the bashrc file, users should be careful and always take a backup before making any changes.
Your email address will not be published. Bashrc File. Prev 10 practical examples of regex with grep. Comments dv says:. May 23, at pm.
0コメント