Vim tips for File name completion

Source: Internet
Author: User

Well, these two days in the "Concise Python tutorial," the author suggests writing code when the previous comment write the file name, write the call interpreter, such as:

Well, then of course I can not create a new file every time, it is necessary to write a large list of things, vim such an artifact must have a simple way ah, I modified my vimrc file, add the following code:

1Autocmd bufnewfile *.py exec": Call Settitle ()" 2 func settitle ()3     if&filetype = ="python"4Call Setline (1,"#!/usr/bin/env python")5Call Setline (2,"#-*-coding:utf-8-*-")6Call Setline (3,"#Filename:")7 endif8Endfunc

This code is very simple, that is, when Vim creates a new file, check the file type (through the suffix name), and then if the file type is a python file, then call the Settitle function, then this function is added to the first three lines of the new file as follows:

  

(The comment on the second line sets the encoding of the current code to UTF-8 so that the Python code can write in Chinese ^ o ^)!

Well, in theory, VIM should have a variable to store the file name, and then you can directly in the Setline statement (6 lines) to set the file name, but I have not found, if who knows, but also look at the liberal enlighten!

So, now that we've created a new file, but the file name is empty after the filename comment, how do I add it? Originally I do not know how to quickly add, has always been their own knock, and then always feel that this is not the feeling of vim Ah! Then today only weakly weak to find the original vim automatic completion of the file name and complete the shortcut key, and then really unsanitary environment Ah!

That's a little nonsense.

<C-x><C-f>

The above line means to press ctrl+x first, then press CTRL+F, which will pop up the file name drop-down list (that is, all the file names under the current working directory), such as this:

I have two files in the current directory, hello.py and world.py, and then I go into insert mode in hello.py, this happens after I press <C-x><C-f>:

And then I'll go through the two buttons.

<C-p>    //ctrl+p, select previous <C-n>    //CTRL + N, select Next

So you can quickly write the file name! ^ _ ^

Vim tips for File name completion

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.