If you are interested in learning more than just the Vim Basics, I highly recommend using this program by Jovica Ilic. This article covers how you can move your cursor to a specific line in the Vim editor. It is case-sensitive, so make sure they are in lowercase. Then you make some edits and want to move to the first line how do you do that? To do that, press the 'gg' combination. If you want to move to the last line of a text file in Vim, the 'G' key will move the cursor to the last line in the file.īy default, when you open a file in Vim, the cursor will be on the first line. Multiple windows can display the same file or buffer. A window, in essence, is a view of a buffer. Along with the buffer, Vim creates a window through which we do the editing. The original file remains intact until we save our changes. Several keyboard shortcuts are used for navigation. When we open a file, Vim loads its contents into memory. When you start the Vim editor, you can use several command-line options.These. The same can be done by using the 'gg' instead of 'G'. If you use the command vim, the editing occurs inside your command window. Press the 'Enter' key and voila, you are on the 30th line of that file. So I will type the line number that I want to go to, '30', and follow it with a single uppercase 'G'. Let's say that I want to move my cursor to line 30. Please make sure you are either in Visual or Normal mode. What matters is the line number of the line that you want to move your cursor to. In this method, the line that your cursor is on does not matter. In an instance where you have a sure/faint idea of what is on line 'x', there are 2 ways you can move your cursor to line 'x'. If you press the 'j' key after typing a number 'x' (in normal mode), the cursor will move 'x' lines down. Now, type any number In our case, we want to move our cursor up by 10 lines, so type '10' and then press the 'k' key. Make sure that you are in Normal mode you can do that by pressing the Escape (Esc) Key. You can activate Command-Line mode from Normal mode by. Move the cursor relatively to the line you are onĪssume that you are on line 54 and you want to move the cursor up 10 lines here is how you can achieve that. As a final note, Vim also has Command-Line mode, which shouldnt be confused with. If you already have a file opened for editing and you have enabled line numbers in Vim, you can try one of the following ways of moving the cursor up or down. If you know the total number of lines in a particular file, you can specify a number that is greater than the number of lines in a file while opening the file in Vim and the cursor will be at the bottom-most line. vim +5 foo.rsĪs you can see in the video, the 'main.rs' file opened with the cursor at line 30 instead of line 1. Simply type 'vim', with a line number specified after '+' sign and followed by the filename. You can make Vim open a file with your cursor at a particular line. Whenever you open a file in Vim, the cursor will be on line 1. When you blaze through your work in Vim efficiently, you will feel higher than anyone.īut for that to happen, you need to master the navigation in Vim. Vim is a powerful editor that, at worst, will only feel fast.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |