vim Tips and tricks to boost productivity Using the path completion feature inside Vim


Example

This is very common, you memorize a path to a file or folder, you open up Vim and try to write what you've just memorized, but you are not 100% sure it's correct, so you close the editor and start over.

When you want the path completion feature, and you have a file /home/ubuntu/my_folder/my_file and you are editing another file referencing to the path of the previous one:

Enter insert mode: insert or do it the way you want. Next, write /h. When the cursor is under h, press Ctrlx and then Ctrlf so the editor will complete it to /home/ because the pattern /h is unique

Now, suppose you have two folders inside /home/ubuntu/ called my_folder_1 my_folder_2

and you want the path /home/ubuntu/my_folder_2

as usual:

Enter insert mode

write /h and press Ctrlx and then Ctrlf . Now you have /home/ Next add u after /home/ and press Ctrlx and then Ctrlf . Now, you have /home/ubuntu/ because that path is unique. Now, write my after /home/ubuntu/ and press Ctrlx and then Ctrlf . The editor will complete your word until my_folder_ and you will see the directory tree so use the arrow keys to choose the one you want.