Show Line Numbers
:set number
This command is used to displaying line numbers in the editor.
:set nonumber
This is the counter command to the first numer. That is, this command will hide the line numbers.Auto Indent
:autoindent
This command will auto indent the line as the previous line.At any time, if you need to remove the indentation of the line you can press Ctrl+d.
Switching to New File
If you are working on a file in VIM and want to switch to a new file then you can use the following command:
:e <file_name>
Split Screen
Sometimes we want to compare 2 files or the segments of same file. At such time, split feature of vim comes in handy. Screen can be easily split in vim.Split Screen Horizontally
:split
This code will split the screen horizontally. You can pass optional filename, if you want to open new file in the new window. If you don't pass any value, then the same file will be opened.Split Screen Vertically
:vsplit
This code will split the screen vertically. Similar, to horizontal split, you can also pass a filename to open in the new window. Navigating the Splitted Screens
You can navigate the splitted screens by pressing Ctrl+w TWICE.You can also do this by pressing Ctrl+w and then using the ARROW keys.
Close / Unsplit the Splitted Screens
CLICK HEREMove to the End of Line
$
Move to the Last Line
:$
Move to a Line Number
:<line_number>
Note: :$ will move to last line.Delete All
:1,$d
Copy/Paste Lines
yy
This command will copy the current line.
<number>yy
This command will copy <number> lines starting from the current line.
p
or
P
This command will paste the copied text.Cut/Paste Lines
dd
This command will cut the current line.
<number>dd
This command will cut <number> lines starting from the current line.
p
or
P
This command will paste the copied text.Copy/Cut Paste Selected Text
- Place the cursor to the position from where the text is to copied.
- Press v to begin the text selction.
- Move cursor to select the text.
- Press y to COPY or d to CUT the selected text.
- Press p or P to paste the text.
Insert Text (Spaces) in Multiple Lines at once
- Within VIM select block visual mode, by pressing CTRL-V .
- Use the cursor keys to select the lines you want to add the spaces to.
- Then enter :'<,'> norm I
- This will then insert a single space to the beginning of your select lines.
- :'<,'> : For the line I selected
- norm : Execute the following sequence of keystrokes as if I was in normal mode
- I: Insert at the beginning of the line the following characters
- [space]: The character(s) you would like to insert
No comments:
Post a Comment