Skip to content

Instantly share code, notes, and snippets.

@G36maid
Created September 21, 2023 17:28
Show Gist options
  • Select an option

  • Save G36maid/1822c35500f247ca053f9a205bd40d76 to your computer and use it in GitHub Desktop.

Select an option

Save G36maid/1822c35500f247ca053f9a205bd40d76 to your computer and use it in GitHub Desktop.
"################### Magic vimrc ###################
" ctrl+n Enable/disable mouse
" ctrl+b Switch to text/binary
" ctrl+j To utf-8 file
" ctrl+t Convert tab to spaces
" ctrl+l Toggle line breaking
" ctrl+f Switch to full/simple
"#######################################################
set nocompatible
"#######################################################
syntax enable
set number
set noruler
set ignorecase
set smartcase
set incsearch
set cindent
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
set smarttab
set confirm
set backspace=indent,eol,start
set history=500
set showcmd
set showmode
set nowrap
set autowrite
set mouse=a
"#######################################################
" Color
set t_Co=256
colo torte
set cursorline
set cursorcolumn
set hlsearch
hi CursorLine cterm=none ctermbg=DarkMagenta ctermfg=White
hi CursorColumn cterm=none ctermbg=DarkMagenta ctermfg=White
hi Search cterm=reverse ctermbg=none ctermfg=none
"#######################################################
" statusline
set laststatus=2
set statusline=%#filepath#[%{expand('%:p')}]%#filetype#[%{strlen(&fenc)?&fenc:&enc},\ %{&ff},\ %{strlen(&filetype)?&filetype:'plain'}]%#filesize#%{FileSize()}%{IsBinary()}%=%#position#%c,%l/%L\ [%3p%%]
hi filepath cterm=none ctermbg=238 ctermfg=40
hi filetype cterm=none ctermbg=238 ctermfg=45
hi filesize cterm=none ctermbg=238 ctermfg=225
hi position cterm=none ctermbg=238 ctermfg=228
function IsBinary()
if (&binary == 0)
return ""
else
return "[Binary]"
endif
endfunction
function FileSize()
let bytes = getfsize(expand("%:p"))
if bytes <= 0
return "[Empty]"
endif
if bytes < 1024
return "[" . bytes . "B]"
elseif bytes < 1048576
return "[" . (bytes / 1024) . "KB]"
else
return "[" . (bytes / 1048576) . "MB]"
endif
endfunction
"#######################################################
" encode
if has("multi_byte")
set fileencodings=utf-8,utf-16,big5,gb2312,gbk,gb18030,euc-jp,euc-kr,latin1
else
echoerr "If +multi_byte is not included, you should compile Vim with big features."
endif
"#######################################################
" shortcut
" Toggle mouse
map <C-n> :call SwitchMouseMode()<CR>
map! <C-n> <Esc>:call SwitchMouseMode()<CR>
function SwitchMouseMode()
if (&mouse == "a")
let &mouse = ""
echo "Mouse is disabled."
else
let &mouse = "a"
echo "Mouse is enabled."
endif
endfunction
" Toggle text/binary
map <C-b> :call SwitchTextBinaryMode()<CR>
map! <C-b> <Esc>:call SwitchTextBinaryMode()<CR>
function SwitchTextBinaryMode()
if (&binary == 0)
set binary
set noeol
echo "Switch to binary mode."
else
set nobinary
set eol
echo "Switch to text mode."
endif
endfunction
" To utf-8 file
map <C-j> :call ToUTF8()<CR>
map! <C-j> <Esc>:call ToUTF8()<CR>
function ToUTF8()
if (&fileencoding == "utf-8")
echo "It is already UTF-8."
else
let &fileencoding="utf-8"
echo "Convert to UTF-8."
endif
let &ff="unix"
endfunction
" Convert tab to spaces
map <C-t> :call TabToSpaces()<CR>
map! <C-t> <Esc>:call TabToSpaces()<CR>
function TabToSpaces()
retab
echo "Convert tab to spaces."
endfunction
" Toggle line breaking
map <C-l> :call SwitchLineBreakingMode()<CR>
map! <C-l> <Esc>:call SwitchLineBreakingMode()<CR>
function SwitchLineBreakingMode()
if (&wrap == 0)
set wrap
echo "Switch to line breaking mode."
else
set nowrap
echo "Switch to one line mode."
endif
endfunction
" Switch to full/simple
map <C-f> :call SwitchFullSimpleMode()<CR>
map! <C-f> <Esc>:call SwitchFullSimpleMode()<CR>
function SwitchFullSimpleMode()
if (&mouse == "a")
let &mouse = ""
set nocindent
set nonumber
set wrap
echo "Switch to simple mode.(nomouse, nonumber, nocindent, wrap)"
else
let &mouse = "a"
set cindent
set number
set nowrap
echo "Switch to full mode.(mouse, number, cindent, nowrap)"
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment