Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Indent in vim:
1- press V and select multiple lines
2- press > (you can press > as many times as you want to indent more)

Unindent in vim:
1- press V and select multiple lines
2- press < (you can press < as many times as you want to unindent more)

#vim #commands #indent #unindent
Display line numbers in vim. If a file is open with vim press ESC (if you are in insert mode) and then press colon (:) and type:

set number


The above command will print line numbers in front of each line.

Now if you want to hide line numbers you just need to press colon again and type:

set nonumber


#vim #tricks #line_number #nonumber #number
If you want to undo something in vim use u key and in case you want to redo an action just press ^r.

#vim #undo #redo
One the most useful commands in vim is to delete or change inside of a block like {} or inside of a charater like "SOME THING".

In case you want to just delete inside of something and you don't want to go into INSERT mode just press di keyboard buttons in order, otherwise press ci keyboard buttons to go in INSERT mode and change something.

Let's give an example. Suppose we have lines like below and we have opened it in vim:
user_id = "43dd94e5d79ffeb2ffffabd112d5e945"
name = "Alireza"
dob = "SECRET :)"

Place the cursor between double quotes somewhere in the SECRET :) and press d then press c keys and finally press double quote ("). The vim will search for the surrounding double quotes and will remove everything inside of it. Our output is:
user_id = "43dd94e5d79ffeb2ffffabd112d5e945"
name = "Alireza"
dob = ""

Now let's assume we have a block of code like below:
users_data = {
}

Go inside of the block of curly braces (`{}`) and put your cursor inside of the block. Now press c on your keyboard then press i afterward, and at the end press { on your keyboard. It will delete everything inside of {} for you and put your vim mode in INSERT mode. So you would have the following output:
users_data = {
}

You can do the same with every block of code and every character like (), [], '', etc.

ci stands for Change Inside
di stands for Delete Inside

#vim #tricks #commands #change #delete #ci #di
A quick way to comment/uncomment lines in vim:

Put your cursor on the first # character, press Ctrl+V, and go down until the last commented line and press x, that will delete all the # characters vertically.


For commenting a block of text is almost the same:

- First, go to the first line you want to comment, press Ctrl+V. This will put the editor in the VISUAL BLOCK mode.

- Then using the arrow key and select until the last line.

- Now press Shift+I, which will put the editor in INSERT mode and then press #. This will add a hash to the first line.

- Then press Esc (give it a second), and it will insert a # character on all other selected lines.

#vim #comment #comment_out #visual_block
You can open new tabs in vim using tabe command:
:tabe

At the top of the vim you would see [No Name] which refers to the current file
name. Now in order to navigate between tabs you can use the below command when your vim is in command mode:
gt

To go to the previous tab use:
gT

#vim #tab #multi_window #gt #tabe #tips
Change default editor of crontab in linux from nano to vim:

export EDITOR=vim

You can put this code inside of ~/.bashrc.

NOTE: export is used to set an environment variable in linux.

#linux #crontab #editor #vim #nano
If you want to disable mouse in vim 8 in new Debian, put the below line in your ~/.vimrc:

set mouse=c

It just kills me when I want to work with vim with mouse enabled!

#linux #debian #vim #mouse_enabled
When I paste something in vim all lines get indentation:

line
line
line

To solve this issue just go to command mode by pressing ESC on your keyboard now type:

:set paste

Then paste your code. Note that the text in the tooltip now says -- INSERT (paste) --.


NOTE: After you pasted your code, turn off the paste-mode, so that auto-indenting when you type works correctly again.

:set nopaste


You can set a keyboard shortcut for it (here F5):

set pastetoggle=<F5>


#editor #vim #nopaste #paste #pastetoggle
How do you delete all text above a certain line?

dgg

Will delete everything from your current line to the top of the file.

#vim #delete #dgg
How to disable visual block in VIM?

There is a feature in vim that as you select a text inside of vim, it turns the mode into VISUAL BLOCK. This is annoying for me in case you want to disable it put the below code in ~/.vimrc:

set mouse-=a

#vim #visual_block #mouse #set #vimrc
How to add comma to end of multiple lines in VIM? Yeah, that's tricky boy :))))

1- First go to Visual Block mode by pressing ^v (CTRL+V)

2- Now select your mutiple lines by going down using down arrow button.

3- Go to end of line by pressing end command in your keyboard in linux and windows or if you're using MAC by pressing fn+right arrow.

4- Now press shift+A (It worked in MAC in linux we needn't that)

5- type comma

6- press ESC (wait one second or so)

Voila! We're done.

#vim #tricks #VB #visual_block