VI / VIM Editor • Linux Tutorial - Pranab Das
Có thể bạn quan tâm
- Welcome
- Commandline
- Vi editor
- Git
- Docker
- Shell scripting
- Regular Expression
- Misc
- Resources
- License
VI / VIM is a simple and powerful editor. If you are accessing a remote workstation or cluster where you don't have the option to launch graphical programs, VIM is a great option. Almost any Linux or UNIX system has VI editor preinstalled. Recent OS will likely have VIM (Vi IMproved) instead of classic VI editor. You can check the version of VI by:
vi--versionIn case it is not installed in your system, you can install using a package manager:
# ubuntu / debianaptinstallvim- Open / create a file_name to read and/or write:
-
Go into INSERT mode by (check in the bottom of the window for --INSERT--) by pressing [shift]+[I] or simply [I].
-
Go into REPLACE mode (check in the bottom for --REPLACE--) by pressing [shift] + [R].
-
Go into readonly / normal mode by pressing [esc].
-
To save file, first go into readonly mode ([esc]) and then type:
- To exit vim, first go into readonly mode ([esc]) and then:
- You can combine both to save and exit (keyboard shortcut [Shift]+[Z Z]):
- Exit without saving (keyboard shortcut [Shift]+[Z Q]):
-
Search in the file: Type / followed by the phrase you are looking for. Press N go to next match. You can search backwards using ?
-
See line numbers: :set nu
-
Hide line numbers: :set nonu
-
Spellcheck: :set spell
-
Turn off spellcheck: :set nospell
-
Set user spell file: :set spellfile=~/.vim/en.utf-8.add
-
Browse files and folders using file explorer: :E
Keyboard shortcuts
Key bindings | Description |
---|---|
G | Go to the end of the file |
5G | Go to specific line of the file (here line 5) |
5H | Move relative to the top line on the screen |
3L | Move relative to the bottom line on the screen |
gg | Go to the beginning of file |
control + F | Scroll forward one page |
control + B | Scroll backward one page |
$ | Go to the end of line |
0 | Go to the beginning of line |
dd | Delete a whole line |
u | Undo (or type :u; :2u (undo twice) or :U (undo all)) |
control + R | Redo |
control + L | Redraw / reload |
z= | Spelling suggestions |
zg | Add new word to the user dictionary |
zug | Remove word from the dictionary |
. | Repeat last command |
db | Delete one word backwards |
dw | Delete one word forwards |
d$ / D | Delete to the end of line |
d0 | Delete to the beginning of line |
- Compare two files:
- Move a line up / down: this can be achieved by few key combinations. To move one line above its current position: ddkP.
- dd to delete current line and put it in default register
- k or j to move up or down
- P to paste above current line.
visual mode
Enter Visual mode by pressing v, V or [control] + v for visual character, line or block modes, respectively. Select text using the arrow keys on the key board. You can:
-
Press c it will clear the selected part and enter into insert mode.
-
Press y to copy (yanked).
-
You can paste in another location in VIM by pressing p.
-
Press "+y to copy to system clipboard, you can paste in another program using your system shortcut like [command] + v or [control] + v.
-
Comment multiple lines:
- Enter block visual mode: [control] + v
- Select the lines (first col) using up / down arrow keys
- Enter insert mode: [shift] + i
- Type commenting character e.g., #
- Press [esc].
-
Un-comment multiple lines:
- Enter block visual mode: [control] + v
- Select the lines (one or multiple columns) using arrow keys
- Press x followed by [esc].
vimrc
You can customize your vi editor by creating a ~/.vimrc file and saving your settings there. Like:
syntaxonsettabstop=4setrulercolorscheme darkbluesettextwidth=80setcc=81setautoindentsetspellhi SpellBad ctermbg=Yellowhi SpellBad ctermfg=DarkRedsetspellfile=~/.vim/en.utf-8.add" Syntax highlight for custom filetypesau BufRead,BufNewFile *.insetfiletype=fortranau BufRead,BufNewFile *.out setfiletype=fortranau BufRead,BufNewFile matplotlibrc setfiletype=pythonsethlsearchhi Search ctermbg=LightBluehi Search ctermfg=black- Convert tabs to spaces. Add the following to your .vimrc:
Convert existing tabs to spaces by :retab (once the above settings are added).
Plugins
- Installing vimplug:
- Installing plugins using vimplug: add this to your .vimrc
Save the file :w. Then install plugins by issuing :PlugInstall.
You can modify or add your own settings to a plugin. For example, if you want to call Limelight along with Goyo. Go to
~/.vim/plugged/goyo.vim/autoload/goyo.vimand add a line Limelight. You may add other settings, say, set spell etc.PreviousCommandlineNextGit
- Keyboard shortcuts
- visual mode
- vimrc
- Plugins
Từ khóa » Vi In Linux Tutorial
-
Unix/Linux - The Vi Editor Tutorial - Tutorialspoint
-
Master The Vi Text Editor - Linux Tutorial
-
VI Editor With Commands In Linux/Unix Tutorial - Guru99
-
VI Editor - Linux Tutorial #14 - YouTube
-
Basic Vi Commands - Colorado State University
-
Vi Editor With Commands - Javatpoint
-
[PDF] VI-TUTORIAL.pdf
-
Vi Editor Tutorial For Beginners - Vegibit
-
Vi Text Editor Tutorial - Linux Tutorial From PenguinTutor
-
[PDF] Unix The Vi Editor Tutorial
-
Vi Editor In UNIX - GeeksforGeeks
-
How To Use The UNIX-LINUX Vi Text Editor: Tips, Tricks, And ...
-
An Introduction To The Vi Editor | Enable Sysadmin - Red Hat
-
Using Vi, The Unix Visual Editor - University Of Washington