Changing Vim indentation behavior by file type

You can add .vim files to be executed whenever vim switches to a particular filetype. For example, I have a file ~/.vim/after/ftplugin/html.vim with this contents: setlocal shiftwidth=2 setlocal tabstop=2 Which causes vim to use tabs with a width of 2 characters for indenting (the noexpandtab option is set globally elsewhere in my configuration). This is … Read more

How to check if a file exists in Go?

To check if a file doesn’t exist, equivalent to Python’s if not os.path.exists(filename): if _, err := os.Stat(“/path/to/whatever”); errors.Is(err, os.ErrNotExist) { // path/to/whatever does not exist } To check if a file exists, equivalent to Python’s if os.path.exists(filename): Edited: per recent comments if _, err := os.Stat(“/path/to/whatever”); err == nil { // path/to/whatever exists } … Read more

Why should text files end with a newline?

Because that’s how the POSIX standard defines a line: 3.206 Line A sequence of zero or more non- <newline> characters plus a terminating <newline> character. Therefore, lines not ending in a newline character aren’t considered actual lines. That’s why some programs have problems processing the last line of a file if it isn’t newline terminated. … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)