diff options
| author | jdhao <jdhao@hotmail.com> | 2019-09-26 23:18:19 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2019-09-26 23:18:19 +0800 |
| commit | 460ec98052e07bbf16d8143d8f242280662582a6 (patch) | |
| tree | d258f1fcbcd326fb1c4091ca00326f4d08ec66f7 /autocommands.vim | |
| parent | 08c5c49f181fbadf4a2f518155819a916e351a1a (diff) | |
Split large nvim config into several files for easier management
Diffstat (limited to 'autocommands.vim')
| -rw-r--r-- | autocommands.vim | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/autocommands.vim b/autocommands.vim new file mode 100644 index 0000000..c400791 --- /dev/null +++ b/autocommands.vim @@ -0,0 +1,61 @@ +"{ Auto commands +" Do not use smart case in command line mode, +" extracted from https://goo.gl/vCTYdK +augroup dynamic_smartcase + autocmd! + autocmd CmdLineEnter : set nosmartcase + autocmd CmdLineLeave : set smartcase +augroup END + +" Set textwidth for text file types +augroup text_file_width + autocmd! + " Sometimes, automatic filetype detection is not right, so we need to + " detect the filetype based on the file extensions + autocmd BufNewFile,BufRead *.md,*.MD,*.markdown setlocal textwidth=79 +augroup END + +augroup term_settings + autocmd! + " Do not use number and relative number for terminal inside nvim + autocmd TermOpen * setlocal norelativenumber nonumber + " Go to insert mode by default to start typing command + autocmd TermOpen * startinsert +augroup END + +" More accurate syntax highlighting? (see `:h syn-sync`) +augroup accurate_syn_highlight + autocmd! + autocmd BufEnter * :syntax sync fromstart +augroup END + +" Return to last edit position when opening a file +augroup resume_edit_position + autocmd! + autocmd BufReadPost * + \ if line("'\"") > 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | execute "normal! g`\"zvzz" + \ | endif +augroup END + +" Display a message when the current file is not in utf-8 format. +" Note that we need to use `unsilent` command here because of this issue: +" https://github.com/vim/vim/issues/4379 +augroup non_utf8_file_warn + autocmd! + autocmd BufRead * if &fileencoding != 'utf-8' + \ | unsilent echomsg 'File not in UTF-8 format!' | endif +augroup END + +" Automatically reload the file if it is changed outside of Nvim, see +" https://unix.stackexchange.com/a/383044/221410. It seems that `checktime` +" command does not work in command line. We need to check if we are in command +" line before executing this command. See also http://tinyurl.com/y6av4sy9. +augroup auto_read + autocmd! + autocmd FocusGained,BufEnter,CursorHold,CursorHoldI * + \ if mode() == 'n' && getcmdwintype() == '' | checktime | endif + autocmd FileChangedShellPost * echohl WarningMsg + \ | echo "File changed on disk. Buffer reloaded!" | echohl None +augroup END +"} |
