" if without, nvim with no file will give error because it's not defined? let fenc_bef = 0 " https://github.com/junegunn/vim-plug call plug#begin() " https://github.com/junegunn/fzf.vim#commands " seems only need junegunn/fzf.vim, no need junegunn/fzf if already installed fzf with pacman "Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } "Plug 'junegunn/fzf.vim' "Plug 'vim-perl/vim-perl', { 'for': 'perl', 'do': 'make clean carp dancer highlight-all-pragmas moose test-more try-tiny' } if has('nvim') && executable('firefox') Plug 'glacambre/firenvim', { 'do': { _ -> firenvim#install(0) } } endif " tinted-theming/base16-vim has low contrast on fold title make it unreadable, but I customized it easily " chriskempson/base16-vim doesn't do bold/italic for markdown syntax, and not maintained " RRethy/base16-nvim does not highlight markdown codeblocks " tinted-theming/base16-vim and RRethy/base16-nvim seem both work, both support tree-sitter Plug 'tinted-theming/base16-vim' " nvim-treesitter seems support markdown highlight now, run `:TSEnable highlight`, more see vc notes " but very slow when editing large markdown files so I sitll don't enable it, maybe related: " https://github.com/nvim-treesitter/nvim-treesitter/issues/2206 "Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'} " We recommend updating the parsers on update " use latest vim-markdown "Plug 'tpope/vim-markdown' " alternatives: h-hg/fcitx.nvim, rlue/vim-barbaric, lilydjwg/fcitx.vim " h-hg/fcitx.nvim is the only one out of the three alternatives that does not " have this issue: after / search with chinese pingyin, then enter, then in " normal mode if I press one key, e.g., k, it will trying to use chinese " pingyin instead of using english if executable('fcitx5') Plug 'h-hg/fcitx.nvim' endif " alternatives: 'thinca/vim-ref' with 'eiiches/vim-ref-info', 'HiPhish/info.vim', 'alx741/vinfo' Plug 'https://gitlab.com/HiPhish/info.vim.git' " :h hexmode " other related doc: :h hex-editing, :h 23.3, :h edit-binary if executable('xxd') Plug 'fidian/hexmode' endif call plug#end() " next line must put below `Plug 'glacambre/firenvim'`, else if click github issue textarea, then click elsewhere, then click textarea, textarea will not be selected (no cursor in it), not sure why let g:firenvim_config = { 'localSettings': { '.*': { 'takeover': 'never' } } } let g:infoprg = '/usr/bin/info' " I use only one return for better readability function! Autocmd_set_fenc() abort " need to test &modifiable for gO if &modifiable && (&fileencoding != "utf-8") let l:fenc_bef = &fileencoding setlocal fileencoding=utf-8 unsilent echom ":w to rewrite as utf-8" return l:fenc_bef else return &fileencoding endif endfunction function! Md_toggle_fold() abort " &markdown_folding won't work because markdown_folding is not an option " two ways to check if g:markdown_folding variable exists and is true: " more see https://stackoverflow.com/q/15864164/9008720 "if exists('g:markdown_folding') && g:markdown_folding if get(g:, 'markdown_folding') let g:markdown_folding=0 " :e e else let g:markdown_folding=1 e endif endfunction " not fully understood augroup, recommanded in :help " https://www.youtube.com/watch?v=dBBUOO1PRIU augroup mycmd autocmd! " disable auto line break (tc) and insert comment (cro) autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o formatoptions-=t " auto rewrite as utf-8 if not when :w " if use FileType *, nvim can't recognize some file extensions, ex: .csv autocmd BufRead * let fenc_bef = Autocmd_set_fenc() " similar to filetype.vim code, use setfiletype " .csx seems not c# but c# script file, this works tho " set syntax=cs also works autocmd BufNewFile,BufRead *.csx setfiletype cs " https://stackoverflow.com/q/28310094 multi filetypes " for alerting me plain text email characters per line " neomutt auto set new email filetype as mail so this will work " /usr/share/nvim/runtime/ftplugin/mail.vim default textwidth 72 " https://stackoverflow.com/q/2290016 suggest gitcommit main body should be about 72 " https://useplaintext.email/ suggest 72 " https://mailformat.dan.info/body/linelength.html suggested 65 "" https://superuser.com/q/827647/1282809 " https://lkml.org shows Linus seems use 70 " https://lkml.org Hottest messages shows people use around 70-80 " https://en.wikipedia.org/wiki/Characters_per_line " related: textwidth " if want to do this only for some file extensions, see: "" https://stackoverflow.com/a/469576/9008720 "" don't forget to put in augroup: "" https://stackoverflow.com/a/60470085/9008720 "" also other ways: "" https://stackoverflow.com/q/158968/9008720 " or use setlocal cc= autocmd FileType mail,gitcommit setlocal colorcolumn=72 " open file readonly if it already been open " nvim seems change default from '' to 'e', but I prefer 'o' " :h w325 e325 SwapExists swapchoice default-autocmds " https://vi.stackexchange.com/questions/21784/vim-edit-anyway-without-prompting " https://github.com/neovim/neovim/pull/25336 " https://github.com/neovim/neovim/commit/29fe883aa9166bdbcae3f935523c75a8aa56fe45 " remove nvim.swapfile autocmd is more correct, without also works but I think it change to 'e' then to 'o' which is not ideal, also it will echo "W325: ..." which is not what I want autocmd! nvim.swapfile autocmd SwapExists * let v:swapchoice = 'o' augroup END " :h markdown, for vim default tpope/vim-markdown " enable markdown fold will make opening large files slower, so I don't enable it "let g:markdown_folding = 1 " g:markdown_minlines before nvim 0.8, 500 works well; version 0.8 makes even 400 noticeable slow when keep pressing gk let g:markdown_minlines = 350 "let g:markdown_fenced_languages = ['python', 'sh', 'vim', 'c', 'cpp'] " :h hexmode, fidian/hexmode plugin " imagemagick .gray file format let g:hexmode_patterns = '*.gray' map h :Hexmode "let g:hexmode_xxd_options = '-c 32' " netrw-p preview vertial split let g:netrw_preview = 1 let g:netrw_winsize = 20 " seems needs this for autocmd FileType * to work? filetype plugin on " fold is slow and buggy, at least for different kinds of vim-markdown, disable it, not sure if works or not "set nofoldenable language en_US set number relativenumber " need next line for base16 colorscheme to work? set termguicolors colorscheme base16-tomorrow-night " set dir to current editing file's dir set autochdir " Spaces & Tabs set tabstop=4 " number of visual spaces per TAB set softtabstop=4 " number of spaces in tab when editing set shiftwidth=4 " number of spaces to use for autoindent "set expandtab " tabs are space " https://www.zhihu.com/question/22363620/answer/21199296 " euc-cn=gb2312, cp936=gbk " it is recommended by `:h fileencodings` to put ucs-bom at first and latin1 at last " based on my experience, if put utf-16 in front of euc-cn, euc-cn will have mojibake " based on my experience, if put big5 in front of euc-cn and cp936, euc-cn will have mojibake " according to zhihu comment, if put gb18030 in front of big5 , big5 will have mojibake " according to wikipedia articles, euc-cn is preceded by cp936 which is preceded by gb18030, gb18030 is backward compatible with cp936 which seems is backward compatible with euc-cn set fileencodings=ucs-bom,utf-8,euc-cn,cp936,big5,gb18030,utf-16,latin1 " seems is default to neovim but not vim set encoding=utf-8 " some file on win10 display as unix but is dos if has('win32') set fileformats=dos " windows 10 bug, need this to change cursor back to vertical bar after leaving neovim " the number after ver seems no effects, maybe because neovim is exited " https://github.com/alacritty/alacritty/issues/2839#issuecomment-766421840 " use of ! after autocmd see youtube video above, not fully understood autocmd! VimLeave * set guicursor=a:ver25 endif " if don't want to generate swap file "set noswapfile " nvim backup file defualt off, see `:h nobackup` `:set backup?` " nvim undo file default off, see `:h noundofile` `:set undofile?` " gg=G work for .xml files now,:h matchit-activate " https://stackoverflow.com/questions/21408222/vim-indent-xml-file/28365920#28365920 packadd! matchit " search case sensitive only if have uppercase set ignorecase set smartcase " disable mouse support " :h disable-mouse set mouse= " map ctrl+h/j/k/l to move between split windows map h map j map k map l " moving in long line "nnoremap k gk "nnoremap j gj nnoremap o o nnoremap O O " maybe useful if use mapleader in the future: https://www.slant.co/topics/7423/~which-key-works-best-as-vim-leader " for searching command in manpages map - /^ *- map * /\*\*.*\*\* " toggle markdown folding and re-edit current file map m :call Md_toggle_fold() " default statusline:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P set statusline+=%< set statusline+=%f " %F or 1CTRL+G to show full path set statusline+=\ %m set statusline+=%= " https://stackoverflow.com/questions/5375240/a-more-useful-statusline-in-vim#comment84812779_10416234 " :h eol-and-eof " show if there's newline at end of file set statusline+=%{&eol?'':'noeol'} set statusline+=\ %y "set statusline+=\ %{&fileencoding?&fileencoding:&encoding} " below line doesn't work as expected, not sure why "set statusline+=\ %{fenc_bef?fenc_bef:&fileencoding} set statusline+=\ %{fenc_bef} set statusline+=\ \[%{&fileformat}\] set statusline+=\ %-10.(%l,%c%V%) set statusline+=\ %P