Vim a text editor for writing code where you navigate around the screen with a keyboard instead of a mouse it's based on the original unix text editor vi which came about in 1976 then, vi improved or vim followed it in 1991 with a bunch of improvements
Vim is rock stable and is continuously being developed to become even better. Among its features are:
- persistent, multi-level undo tree
- extensive plugin system
- support for hundreds of programming languages and file formats
- powerful search and replace
- integrates with many tools
- insert (i)
- visual (v)
- command (:)
Command mode (Where you give commands to the editor to get things done . Press ESC for command mode) Most of them below are in command mode:
x - to delete the unwanted character
u - to undo the last the command and U to undo the whole line
CTRL-R to redo
A - to append text at the end
:wq - to save and exit
:q! - to trash all changes
dw - move the cursor to the beginning of the word to delete that word
2w - to move the cursor two words forward.
3e - to move the cursor to the end of the third word forward.
0 (zero) to move to the start of the line.
d2w - which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w
dd to delete the line and 2dd to delete to line .number can be changed for deleting the number of consecutive words
If you have like 20 settings, you don't want to set them all the time every time you open Vim. So you want to have a settings file a configuration file that does it for you. And for that you have the VIM rc file, which is located at the user directory
vi ~/.vimrc
If the file is there, vim loads it, or VIM is going to open it. If it's not there,it will get created in VIM and Vim is still going to load it. So we're going to open up the VIM rc file .Enter the insert mode and set the reqired settings and customize accordingly
set number
set relativenumber
set tabstop=3
set autoindent
set shiftwidth=4
set mouse=a
colorscheme slate
Sure! Here's an example of explaining "Basic Vim Usage" using Markdown:
To open a file in Vim, you can use the command vim <filename>
in your terminal. For example, to open a file called "example.txt," you'd use vim example.txt
.
By default, Vim opens in normal mode. If you are not in normal mode, press the Esc
key to switch to it.
In normal mode, you can move the cursor using the arrow keys or these common navigation commands:
h
: Move leftj
: Move downk
: Move upl
: Move right
To start typing or editing text, you need to enter insert mode. Press i
(for insert) in normal mode to switch to insert mode.
To save changes to the file, you need to be in normal mode. First, press Esc
to ensure you are in normal mode, and then use the command :w
(short for write) and press Enter
. This will save the file without closing Vim.
To close the file and exit Vim, ensure you are in normal mode (Esc
), and then use the command :q
(short for quit) and press Enter
. If you have unsaved changes, Vim will prevent you from exiting and prompt you to save the changes first.
To save changes and quit Vim in one command, you can use :wq
and press Enter
.
If you want to quit Vim without saving any changes, you can use :q!
and press Enter
. This will forcefully exit Vim without saving.
In normal mode, you can copy text by moving the cursor to the start of the text you want to copy and then pressing v
to enter visual mode. Move the cursor to select the desired text and press y
(short for yank) to copy it. To paste the copied text, press p
in normal mode.
In normal mode, you can undo changes with the u
command and redo changes with Ctrl + r
.
Remember to use proper Markdown formatting and headings to make your content organized and easy to read. Markdown supports basic formatting such as bold, italic, code blocks, bullet points, and more, which you can utilize to enhance the presentation of your explanations.
Certainly! Below is a Markdown-based Vim tutorial for intermediate and advanced users. Feel free to modify and expand as needed:
- Advanced Movement
- Working with Multiple Files
- Customizing Vim
- Advanced Editing
- Advanced Search and Replace
- Working with Macros
Use marks to quickly navigate between different parts of a file.
- Set a mark:
m{letter}
- Jump to a mark: `{letter}
Navigate through jump locations and track changes.
- Jump to the previous location:
Ctrl+O
- Jump to the next location:
Ctrl+I
- View change list:
:changes
Manage multiple files using buffers.
- Open a file in a new buffer:
:badd {file}
- Switch between buffers:
:bnext
,:bprev
- List all buffers:
:ls
Organize buffers using tabs.
- Open a new tab page:
:tabnew
- Switch between tabs:
gt
(next tab),gT
(previous tab) - Close a tab:
:tabclose
Personalize your Vim environment by editing your vimrc
file.
- Edit vimrc:
:e $MYVIMRC
- Reload vimrc:
:source $MYVIMRC
Extend Vim's functionality with plugins.
- Use a plugin manager like Vim-Plug.
- Install plugins: Add
Plug 'user/repository'
to your vimrc, then run:PlugInstall
.
Perform advanced text manipulation in visual mode.
- Visual block mode:
Ctrl+V
- Visual line mode:
Shift+V
Utilize registers to copy and paste text.
- Yank to a register:
"ayy
- Paste from a register:
"ap
Execute commands on specific lines or patterns.
- Run a command on all lines matching a pattern:
:g/pattern/command
Perform substitutions with confirmation.
- Substitute all occurrences in a line:
:s/pattern/replacement/gc
Automate repetitive tasks using macros.
- Record a macro:
q{register}
- Execute a macro:
@{register}
Repeat the last recorded macro.
- Repeat last macro:
@@
These are just a few examples of the many advanced features Vim has to offer. Experiment with these concepts and explore the vast world of Vim customization and efficiency. Happy editing!