Complete VIM tips: file name completion and vim tips completion

Source: Internet
Author: User

Complete VIM tips: file name completion and vim tips completion

Well, I 've been reading the "concise Python tutorial" These two days. The author suggested to write the file name and the interpreter of the call in the comments in front of the Code. For example:

Well, of course I can't create a file every time. I need to write a large string of things at the beginning. There must be a simple way to use vim-like artifacts. By modifying my vimrc file, the following code is added:

1 autocmd BufNewFile *.py exec ":call SetTitle()" 2 func SetTitle() 3     if &filetype == "python"4      call setline(1,"#!/usr/bin/env python")5      call setline(2,"# -* - coding: UTF-8 -* -")6      call setline(3,"#Filename:")7     endif8 endfunc 

This code is very simple, that is, check the file type (via suffix) when creating a file in vim. If the file type is a python file, call the SetTitle function, then, this function adds the following content to the first three lines of the new file:

  

(The comments in the second line set the encoding of the current Code to a UTF-8 so that this python code can write Chinese ^ o ^ )!

 

Well, in theory, vim should have a variable that stores the file name, and then you can directly set the file name in the setline Statement (6 rows), but I haven't found it yet. If anyone knows, I hope you will not be enlightened!

 

Now we have created a new file, but the file name is blank after the Filename comment. How can we add it? It turns out that I have never known how to quickly add it, but I have always tried it myself. Then I always feel that it is not vim! Today, we found that vim's Automatic completion and file name completion shortcuts were weak!

How can this problem be solved?

<C-x><C-f>

The above line means to press Ctrl + x first, and then press Ctrl + f, then the drop-down list of file names will pop up (that is, all file names in the current working directory ), for example:

My current directory has two files, hello. py and world. py, and then in hello. in py, enter the insert mode. After you press <C-x> <C-f>, this will happen:

Then let me use these two buttons.

<C-p> // Ctrl + p, select the previous <C-n> // Ctrl + n, and select the next

In this way, you can quickly write the file name! ^ _ ^

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.