Created
July 3, 2014 23:05
-
-
Save sergeylukin/bdd66197a79ef07b2bc2 to your computer and use it in GitHub Desktop.
Minimal vim configuration for root user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" This is my minimal Vim configuration file I usually save as `/root/.vimrc` | |
" for the occasions when I'm logged in as root user and I need to edit files | |
" (this doesn't usually happen, but when it happens, I have vim configuration | |
" that makes sense). | |
" | |
" It doesn't require any plugins and aims to work with minimal Vim installation | |
" | |
" Forget compatibility with VI | |
set nocompatible | |
"----------------------" | |
" Encoding {{{ | |
"----------------------" | |
set encoding=utf-8 " encoding for editing a file | |
set fileencoding=utf-8 " encoding for writing to a file | |
" }}} | |
"----------------------" | |
" Filetype {{{ | |
"----------------------" | |
filetype off | |
filetype indent on | |
filetype plugin on | |
syntax on | |
" }}} | |
"-----------------------------" | |
" Abbreviations and Shortcuts {{{ | |
"-----------------------------" | |
" Override <leader> defaults | |
let mapleader = "," | |
let maplocalleader = "," | |
" Lower the timeout after typing the leader key + command | |
set timeoutlen=500 | |
" ABBREVIATIONS - commands typed in CLI (after colon) | |
" ------------------------------- | |
" Open current file in Firefox - syntax may differ from one OS to another | |
abbrev ff :!firefox % &<cr> | |
" IMAPS - Insert mode shortcuts | |
" ------------------------------- | |
" Shortcut for ESC | |
imap jj <esc> | |
" NMAPS - Normal Mode shortcuts | |
" ------------------------------- | |
" let semi-colon function as colon (switch to command mode) | |
nmap ; : | |
" fast .VIMRC edit | |
nmap <leader>ev :tabedit $MYVIMRC<cr> | |
" Quickly cancel highlighted selection | |
nmap <leader>h :nohlsearch<cr> | |
" Reload files | |
nmap <leader>r :checktime<cr> | |
" Disable arrow keys to improve moving around with h,j,k,l | |
" Taken from http://bit.ly/10Fvzgn | |
inoremap <Up> <NOP> | |
vnoremap <Up> <NOP> | |
inoremap <Down> <NOP> | |
vnoremap <Down> <NOP> | |
inoremap <Left> <NOP> | |
inoremap <Right> <NOP> | |
vnoremap <Left> <NOP> | |
vnoremap <Right> <NOP> | |
" B-A-<start> almost a Konami code:) | |
" Override read-only permissions with sudo password | |
cmap w!! %!sudo tee > /dev/null % | |
" Prevent from entering Ex mode | |
nnoremap Q <nop> | |
" }}} | |
"----------------------" | |
" Files & Buffers {{{ | |
"----------------------" | |
" Write the old file when switching between files | |
set autowrite | |
" Switch between buffers without saving | |
set hidden | |
" No swap files | |
set noswapfile | |
" File names auto-completion | |
" first TAB completes as much as possible | |
" second TAB provides a list | |
" third and subsequent will cycle through completion options | |
set wildmode=longest,list,full | |
set wildmenu | |
" Apply new configuration after .VIMRC is saved | |
autocmd! bufwritepost .vimrc source % | |
" Automatically change current directory to that of the file in the buffer | |
autocmd BufEnter * silent! lcd %:p:h " Better alternative to `autochdir` | |
" Custom Filetypes | |
au BufNewFile,BufRead *.less, set filetype=css " Recognize .less files as .css | |
au BufNewFile,BufRead *.scss set filetype=css " Recognize .scss files as .css | |
" Shortcut for deleting all buffers | |
nmap <silent> <leader>da :exec "1," . bufnr('$') . "bd"<cr> | |
" Force spell check when writing a git commit | |
" source: https://coderwall.com/p/kxps6g | |
if bufname("%")=="COMMIT_EDITMSG" | |
set spell | |
set spelllang=en | |
endif | |
" }}} | |
"----------------------" | |
" UI stuff {{{ | |
"----------------------" | |
set t_Co=256 " Enable 256 colors mode | |
" Select colorscheme from ~/.vim/colors/ | |
colorscheme desert | |
" Show lines numbers | |
set number | |
" show whitespace characters (tabs and line endings) | |
set list | |
" customize the way whitespace characters are shown | |
set listchars=tab:»\ ,eol:¶ | |
"set relativenumber " Relative line numbering, works in VIM version 7.3 and higher | |
set linespace=3 " Higher line height - works only in GUI mode, not in terminal.. | |
set laststatus=2 " Show status line | |
" Show additional helpful info (like number of selected lines) in the bottom right of the screen | |
set showcmd | |
" Keep current screen unmoved when creating new split screen | |
set splitbelow | |
set splitright | |
" Highlight the paired characters if one of them is under the cursor (like | |
" braces) | |
set showmatch | |
" Ignore case sensitivity when searching | |
set ignorecase | |
" Don't ignore case sensitivity when search pattern contains capital letters | |
set smartcase | |
" Add /g flag in search and replace by default | |
set gdefault | |
" Set incremental search - search when you type, very cool | |
set incsearch | |
" Highlight search - looks like it is enabled by default, but anyways | |
set hlsearch " use :nohlsearch to cancel highlighted selection | |
" Hide mouse when typing | |
set mousehide | |
" Flash screen instead of beeping | |
set visualbell | |
" Highlight current line | |
set cursorline | |
" Have some lines above/below the cursor when hitting the top or the bottom | |
" edge of the screen while scrolling | |
" source: https://coderwall.com/p/m6zz_w | |
set scrolloff=5 | |
" Set font for graphical vim | |
set guifont=Lucida_Console:h11 | |
" Remove all toolbars/scrollbars from GUI version | |
set guioptions=aAc | |
set guioptions-=Be | |
set guioptions-=T | |
" Non-blinking, block cursor | |
set guicursor=a:blinkwait0,a:block-cursor | |
" Resize windows when switching between them | |
set winwidth=84 | |
set winheight=5 | |
set winminheight=5 | |
set winheight=999 | |
" }}} | |
"----------------------" | |
" Indentation & Wrap {{{ | |
"----------------------" | |
set backspace=2 " make backspace work like most other apps | |
" make sure we can navigate very long lines as expected | |
nnoremap j gj | |
nnoremap k gk | |
" make sure we can indent blocks easily, enter Visual mode, select text block | |
" and press '>' and '<' as much as you need to indent it | |
vnoremap < <gv | |
vnoremap > >gv | |
" Hard-wrap paragraphs of text - very useful when pasting long lines | |
nnoremap <leader>q gqip | |
" Indentation | |
" Insert space characters whenever TAB pressed (use Ctrl-V<Tab> to insert real TAB) | |
set expandtab | |
set tabstop=2 " number of spaces when TAB pressed | |
set shiftwidth=2 | |
set softtabstop=2 | |
set expandtab | |
set smartindent | |
set autoindent | |
" Line wrapping | |
set wrap | |
set textwidth=79 | |
set formatoptions=cqtl | |
set wrapmargin=0 | |
set linebreak | |
" }}} | |
"----------------------" | |
" Folding {{{ | |
"----------------------" | |
set foldenable | |
" Use fold-marker method | |
set foldmethod=marker | |
set foldmarker={{{,}}} | |
set foldtext=getline(v:foldstart) | |
" Save only fold info in views | |
set viewoptions=folds | |
" Auto-save the folds when saving file | |
au BufWinLeave * silent! mkview | |
" Auto-load the fold when opening file | |
au BufWinEnter * silent! loadview | |
" Fold GPG entries by default | |
autocmd BufWinEnter,BufReadPre,FileReadPre *.gpg normal zM | |
" Don't screw up folds when inserting text that might affect them, until | |
" leaving insert mode. Foldmethod is local to the window. | |
autocmd InsertEnter * let w:last_fdm=&foldmethod | setlocal foldmethod=manual | |
autocmd InsertLeave * let &l:foldmethod=w:last_fdm | |
" }}} | |
"----------------------" | |
" Code completion {{{ | |
"----------------------" | |
imap <Tab> <C-n> | |
imap <S-Tab> <C-p> | |
" imap <leader><tab> <C-x><C-o> | |
" http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE | |
" set completeopt=longest,menuone | |
" inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" inoremap <expr> <C-n> pumvisible() ? '<C-n>' : | |
" \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>' | |
" inoremap <expr> <M-,> pumvisible() ? '<C-n>' : | |
" \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>' | |
" }}} | |
" Any local customizations should be made in .vimrc.local file | |
" you would most likely create .vimrc.local in the same dir with your $MYVIMRC file | |
let $VIMHOME=expand('<sfile>:p:h') | |
if filereadable(expand('$VIMHOME/.vimrc.local')) | |
source $VIMHOME/.vimrc.local | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment