Tag: trick

Project-Specific Vim Configuration

Usually, we have our own vim configuration in the file ~/.vimrc
What if we want one for our project?
For example, we are working on certain project which needs to read in a tags file.
Well, here is a possible solution.

You put a line at then end of your ~/.vimrc file

source ./.project.vim

Then for each project, put your project-specific stuff in a the file “.project.vim”.

If you don’t want the error message says vim cannot find the file “.project.vim”,
wrap the line above with an if statement:

if filereadable("./.project.vim")
    source ./.project.vim
endif

:]

tail -n

Quite useful trick, when you want to get rid of the first certain lines of the output/file.

$tail -n +2

tail prints out the result starts from the 2nd line.

When you use the “find” command to generate a file list under certain folder, this is quite easy to eliminate the folder path at the beginning of the output.

Learned this from SO How can I remove the first line of a text file using bash/sed script?

一个初始化结构体的用法

近来敲代码的时候,由于技术含量不高,所以就格外注重“代码好不好看”这个问题。
在无聊的Coding中看到一个没有用过的语法还是小有惊喜的。
记在这里:

主要是这段

    DemoStruct demos[4] = {
        {.val = 1, .point = &a},
        {.val = 2},        
        {.point = &b},
        {.val = 3, .point = &c},
    };

对于结构复杂一点的struct,这么写是不是挺好看的 :]