Skip to content

Instantly share code, notes, and snippets.

@WuStangDan
Created March 4, 2022 08:26
Show Gist options
  • Save WuStangDan/95174188f51594471737e2d6c0bf62b3 to your computer and use it in GitHub Desktop.
Save WuStangDan/95174188f51594471737e2d6c0bf62b3 to your computer and use it in GitHub Desktop.
Vimrc with nice settings
" must be first, changes behaviour of other settings
set nocompatible
" 256 colors
set t_Co=256
" sane text files
set fileformat=unix
set encoding=utf-8
" sane tabs
set tabstop=4
set shiftwidth=4
set softtabstop=4
" convert all typed tabs to spaces
set expandtab
" syntax highlighting
syntax on
color koehler
"make sure highlighting works all the way down long files
autocmd BufEnter * :syntax sync fromstart
" allow cursor to be positioned one char past end of line
" and apply operations to all of selection including last char
set selection=exclusive
" allow backgrounding buffers without writing them
" and remember marks/undo for backgrounded buffers
set hidden
" Keep more context when scrolling off the end of a buffer
set scrolloff=3
" allow cursor keys to go right off end of one line, onto start of next
set whichwrap+=<,>,[,]
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" no line wrapping
set nowrap
" line numbers
set number
" when joining lines, don't insert two spaces after punctuation
set nojoinspaces
" Make searches case-sensitive only if they contain upper-case characters
set ignorecase
set smartcase
" show search matches as the search pattern is typed
set incsearch
" search-next wraps back to start of file
set wrapscan
" highlight last search matches
set hlsearch
" map key to dismiss search highlightedness
map <bs> :noh<CR>
" grep for word under cursor
noremap <Leader>g :grep -rw '<C-r><C-w>' .<CR>
" aliases for window switching (browser captures ctrl-w)
noremap <C-l> <C-w>l
noremap <C-h> <C-w>h
noremap <C-k> <C-w>k
noremap <C-j> <C-w>j
" similarly ctrl-q doesnt work, so use leader-q for block visual mode
nnoremap <leader>q <C-Q>
" make tab completion for files/buffers act like bash
set wildmenu
" display cursor co-ords at all times
set ruler
set cursorline
" display number of selected chars, lines, or size of blocks.
set showcmd
" show matching brackets, etc, for 1/10th of a second
set showmatch
set matchtime=1
" enables filetype specific plugins
filetype plugin on
" enables filetype detection
filetype on
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
else
" if old vim, set vanilla autoindenting on
set autoindent
endif " has("autocmd")
" enable automatic yanking to and pasting from the selection
set clipboard+=unnamed
" places to look for tags files:
set tags=./tags,tags
" recursively search file's parent dirs for tags file
" set tags+=./tags;/
" recursively search cwd's parent dirs for tags file
set tags+=tags;/
"autocompletion
inoremap <c-space> <c-n>
inoremap <c-s-space> <c-p>
" =====STATUS LINE OF DEATH!!=====
set statusline=
" filename, relative to cwd
set statusline+=%f
" separator
set statusline+=\
" modified flag
set statusline+=%#wildmenu#
set statusline+=%m
set statusline+=%*
"Display a warning if file encoding isnt utf-8
set statusline+=%#question#
set statusline+=%{(&fenc!='utf-8'&&&fenc!='')?'['.&fenc.']':''}
set statusline+=%*
"display a warning if fileformat isnt unix
set statusline+=%#directory#
set statusline+=%{&ff!='unix'?'['.&ff.']':''}
set statusline+=%*
"display a warning if files contains tab chars
set statusline+=%#warningmsg#
set statusline+=%{StatuslineTabWarning()}
set statusline+=%*
" read-only
set statusline+=%r
set statusline+=%*
" right-align
set statusline+=%=
" filetype
set statusline+=%{strlen(&ft)?&ft:'none'}
" separator
set statusline+=\
" current char
set statusline+=%3b,0x%02B
" separator
set statusline+=\
" column,
set statusline+=%2c,
" current line / lines in file
set statusline+=%l/%L
" always show status line
set laststatus=2
" return '[tabs]' if tab chars in file, or empty string
function! StatuslineTabWarning()
if !exists("b:statusline_tab_warning")
let tabs = search('^\t', 'nw') != 0
if tabs
let b:statusline_tab_warning = '[tabs]'
else
let b:statusline_tab_warning = ''
endif
endif
return b:statusline_tab_warning
endfunction
"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment