HOW TO USE VIM FROM BASIC


I've been using vim for about several years, and even today I find some tips and tricks! This article will review some of the things I use most often in vim, and I hope we get some great answers with some of your favorite tips! Let's go.

Let's start with some basic concepts first, then in the article, we'll get to some of the most exciting tips/tricks.


image from Wikimedia: link

Open a file, scroll, insert, and save the text.
When you want to edit a file in vim, simply type vim file.txt. You enter vim in "normal" mode and you can move around the file using the H J K L keys (or use the arrow keys if you wish).

h Move the pointer one character to the left
j Move the cursor one character up
k Move the cursor one character down
l Move the pointer one character to the right

Now that you have become where you want to be in the file, you'll need to click on the letter i to switch to "insert" mode. Now, you can type some text. Press ESC (escape key) to exit "insert" mode and return to "normal" mode.

We've just finished editing the file and going back to normal mode. To save the file, simply type :wq (write to quit).

However, there is much to see and we will analyze some of that now.

Move (Bonus)

Without a doubt, you want to be able to scroll through the file to find where you want to edit it. I've already explained some common methods, but there are other practical ways to sort your file.

5h Move the cursor 5 characters to the left
2j The cursor moves 2 lines up
3k The cursor moves 3 lines down
6l Move the cursor 6 characters to the right

1G  moves the cursor to line 1. You can replace the number 1 with any number to get this line of the file. For example: 25G  will take in line 25 of the file.
G can take you to the last line of the file.
Ctrl-f will move one page forward
Ctrl-b will return one page back

There are many, but these are the most common I use.


Insertion mode

Perhaps the most common way to enter insertion mode is to press I as described above. This will take you to insert the position where the cursor sits in the document. But there are other options! I will remind them here:

i will put you into insertion mode just in front of where the cursor is located.
a will put you in insertion mode, but place after cursor place
o start a new line below where the cursor is located and place it in insertion mode
I (uppercase i) Place it at the beginning of the current line and in insertion mode
A will place you in the insertion mode and move the cursor to the end of the current line.
O (uppercase) starts a new line above its current position and places it in insertion mode


When you finish insertion mode, make sure to press ESC to return to normal mode.

Quit/Save

:q to Exit, do not save - they do not work unless no changes have been made.
:q! Leave, do not save - works even if changes have been made.
:w writes/saves the file, does not close.
:wq writes/saves the file, closes - will not work if the file is read-only
:wq! Type / save the file, close it - will force write even if the file is read-only
:x writes/saves the file, closes - will not work if the file is read-only
:x! Type / save the file, close it - will force write even if the file is read-only
ZZ writes/saves the file, closes it - will not work if the file is read-only - NOTE NO: It is used.

Copy / Paste / Delete / Search / Replace

Deleting a vim character is as easy as moving the cursor over it and pressing the x key in normal mode. Let's list some ways you can delete, replace, copy, and paste. You will need to do all this while you are in "normal" mode.

Yanks (copying)
yw yanks (copy) word; more specifically, it moves from its position at the end of the word
yy yanks (copy) line
5yy yanks (copy) 5 lines

Delete (and/cut)
x Delete the character
5x erase 5 characters
dw Remove the word - more specifically, delete from the position until the end of the word
dd Delete the line

Paste (works after yanks or deleting)
p Pastes anything deleted or deleted (any of the above-mentioned drag/drop operations)

Search
/pattern to find a file for your style. Look down, but it will be set and you'll see the beginning of the file after seeing what's on your back.
? pattern will look for your pattern in the opposite direction. Practical if it is at the end of the log file and looks for the last match closest to the end.

Replace
Replace r with the current character .. so replacing s with a letter t would move the pointer over s and rt
R replaces the word/string from the cursor point. You do R and then you will stick to your variant.

Search and Replace
:s/old/new replaces the first instance of the old string with the new string in the current line
:s/old/new/ g Replace all instances of the old string with the new string in the current line
:%s/old/new/g g Replace all instances of the old string with the new string in the entire file
:7,25s/old/new Replace all instances of the old string with the new string in lines 7 through 25
in the fresh air

Other useful things

You can undo - you can still hit to u undo the changes you've made.
U Undo the entire line - This will undo the last line you modified to its original state
CTRL-r redo - will  undo you

:set paste This will enable Paste Mode, so the paste will not be automatically indented on your paste
:set nopaste This will turn off Paste Mode,
:set numbers This will display the number lines along the left side
:set nonumbers This will turn off line number
:set ic Ignores the situation when looking for things

:his History of Your command
:! this with commands such as pwd or ls to run commands within vim

Get help inside vim

If you are wondering how to use something, vim has an incredible help command you can call to learn more about things ... Just enter the normal mode and type h followed by the command you are asking, such as dd Solo: q Leave the help.

Roll

Well, that's all I can think of now; you can go back and update this article in the future. I know there are more than a ton of FIM. You can always use vim on a Linux system for more information at any time!

Source and thanks to: Linux.org

Answer below with some of the most common things you use within vim!

  • [message]
    • ##laptop## Support
      • Support Us by Disable your ad block.
      • thank you

COMMENTS

Name

7zip,1,Android,8,Android Emulator,1,APK,2,AppImage,1,Apple,3,APT,3,Arch,5,ASUS,1,Black Shark,1,BlueStack,1,Calculator,1,Cinnamon,1,Client,3,Code,3,Comic,1,Compression Tool,1,Debian,6,DELL,1,Desktop,2,Developers,3,Elementary OS,1,Encryption,1,FACEBOOK,1,Fedora,4,fix,2,Fortnite,1,Gadgets,4,Gamer,4,Gaming,1,geeks,11,GNOME,3,GNOME TWEAK TOOL,1,Google,2,Google Go,1,Hacking Tools,1,How To,19,IBM,1,IDE,1,Intel,1,iOS,4,iPads,1,Javascript,1,Kali Linux,1,KDE,2,Laptop,1,linux,24,Linux Mint,6,LXDE,1,Mac,2,MacOS,4,Manjaro,2,MATE,1,MX Linux,1,Network,3,NEWS,9,Open Source,16,OpenSuse,3,ParrotSec,1,Password,2,Programming,2,Programs,6,Repository,1,Review,2,ROG Phone,1,Security,4,Server,1,SmartPhone,3,SNAP,1,Snapd,1,Software,3,SONY,1,TECH,13,Text Editor,2,Torrent,1,tutorial,16,Ubuntu,10,Ubuntu Kylin,2,vim,1,VMware,1,VPN,1,Web Master,1,Whatsapp,1,Windows,5,Windows Phone,1,XFCE,1,Xiaomi,1,XPS,1,Zorin OS,1,
ltr
item
Linuxer Geeks: HOW TO USE VIM FROM BASIC
HOW TO USE VIM FROM BASIC
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjymD6YoSytyMmAd38PIwbT5XtTzfiDtGZBitcu-xxNEZTOrYExz3X_yv7dLLneoeDkYxG8OukivyciK9tvj8jCkESq3Rn1VL-FW50sqVj9rS4jE27Hp_aGfWQaQEWN0pjLwG7NLxgoaGc/s640/carbon+%25288%2529.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjymD6YoSytyMmAd38PIwbT5XtTzfiDtGZBitcu-xxNEZTOrYExz3X_yv7dLLneoeDkYxG8OukivyciK9tvj8jCkESq3Rn1VL-FW50sqVj9rS4jE27Hp_aGfWQaQEWN0pjLwG7NLxgoaGc/s72-c/carbon+%25288%2529.png
Linuxer Geeks
https://linuxergeeks.blogspot.com/2019/06/how-to-use-vim-from-basics.html
https://linuxergeeks.blogspot.com/
https://linuxergeeks.blogspot.com/
https://linuxergeeks.blogspot.com/2019/06/how-to-use-vim-from-basics.html
true
7822317774280320736
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share. STEP 2: Click the link you shared to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy