Last active
March 4, 2018 20:15
-
-
Save lovromazgon/01db3994165df740a72cd6dfdc6fbe61 to your computer and use it in GitHub Desktop.
My vimrc
This file contains 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => General | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Sets how many lines of history VIM has to remember | |
set history=500 | |
" Enable filetype plugins | |
filetype plugin on | |
filetype indent on | |
" Set to auto read when a file is changed from the outside | |
set autoread | |
" With a map leader it's possible to do extra key combinations | |
" like <leader>w saves the current file | |
let mapleader = "," | |
let g:mapleader = "," | |
" Fast saving | |
nmap <leader>w :w!<cr> | |
nmap <leader>q :q<cr> | |
" :W sudo saves the file | |
" (useful for handling the permission-denied error) | |
command W w !sudo tee % > /dev/null | |
" Paste mode toggle | |
set pastetoggle=<leader>p | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => VIM user interface | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Set 7 lines to the cursor - when moving vertically using j/k | |
set so=7 | |
" Turn on the WiLd menu | |
set wildmenu | |
"Always show current position | |
set ruler | |
" Height of the command bar | |
set cmdheight=2 | |
" A buffer becomes hidden when it is abandoned | |
set hid | |
" Configure backspace so it acts as it should act | |
set backspace=eol,start,indent | |
set whichwrap+=<,>,h,l" | |
" Ignore case when searching | |
set ignorecase | |
" When searching try to be smart about cases | |
set smartcase | |
" Highlight search results | |
set hlsearch | |
" Makes search act like search in modern browsers | |
set incsearch | |
" Don't redraw while executing macros (good performance config) | |
set lazyredraw | |
" For regular expressions turn magic on | |
set magic | |
" Show matching brackets when text indicator is over them | |
set showmatch | |
" How many tenths of a second to blink when matching brackets | |
set mat=2 | |
" Add a bit extra margin to the left | |
set foldcolumn=1 | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Colors and Fonts | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Enable syntax highlighting | |
syntax enable | |
" | |
try | |
colorscheme desert | |
catch | |
endtry | |
set background=dark | |
" Set utf8 as standard encoding and en_US as the standard language | |
set encoding=utf8 | |
" Use Unix as the standard file type | |
set ffs=unix,dos,mac | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Files, backups and undo | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Turn backup off, since most stuff is in SVN, git et.c anyway... | |
set nobackup | |
set nowb | |
set noswapfile | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Text, tab and indent related | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Use spaces instead of tabs | |
set expandtab | |
" Be smart when using tabs ;) | |
set smarttab | |
" 1 tab == 4 spaces | |
set shiftwidth=4 | |
set tabstop=4 | |
" Linebreak on 500 characters | |
set lbr | |
set tw=500 | |
set ai "Auto indent | |
set si "Smart indent | |
set wrap "Wrap lines | |
"""""""""""""""""""""""""""""" | |
" => Visual mode related | |
"""""""""""""""""""""""""""""" | |
" Visual mode pressing * or # searches for the current selection | |
" Super useful! From an idea by Michael Naumann | |
vnoremap <silent> * :<C-u>call VisualSelection(', ')<CR>/<C-R>=@/<CR><CR> | |
vnoremap <silent> # :<C-u>call VisualSelection(', ')<CR>?<C-R>=@/<CR><CR> | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Moving around, tabs, windows and buffers | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search) | |
map <space> / | |
map <c-space> ? | |
" Disable highlight when <leader><cr> is pressed | |
map <silent> <leader><cr> :noh<cr> | |
" Smart way to move between windows | |
map <C-j> <C-W>j | |
map <C-k> <C-W>k | |
map <C-h> <C-W>h | |
map <C-l> <C-W>l | |
" Close the current buffer | |
map <leader>bd :Bclose<cr>:tabclose<cr>gT | |
" Close all the buffers | |
map <leader>ba :bufdo bd<cr> | |
map <leader>l :bnext<cr> | |
map <leader>h :bprevious<cr> | |
" Useful mappings for managing tabs | |
map <leader>tn :tabnew<cr> | |
map <leader>to :tabonly<cr> | |
map <leader>tc :tabclose<cr> | |
map <leader>tm :tabmove | |
map <leader>t<leader> :tabnext | |
" Let 'tl' toggle between this and the last accessed tab | |
let g:lasttab = 1 | |
nmap <Leader>tl :exe "tabn ".g:lasttab<CR> | |
au TabLeave * let g:lasttab = tabpagenr() | |
" Switch CWD to the directory of the open buffer | |
map <leader>cd :cd %:p:h<cr>:pwd<cr> | |
"""""""""""""""""""""""""""""" | |
" => Status line | |
"""""""""""""""""""""""""""""" | |
" Always show the status line | |
set laststatus=2 | |
" Format the status line | |
set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l\ \ Column:\ %c | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Helper functions | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
function! CmdLine(str) | |
exe "menu Foo.Bar :" . a:str | |
emenu Foo.Bar | |
unmenu Foo | |
endfunction | |
function! VisualSelection(direction) range | |
let l:saved_reg = @" | |
execute "normal! vgvy" | |
let l:pattern = escape(@", '\\/.*$^~[]') | |
let l:pattern = substitute(l:pattern, "\n$", "", "") | |
if a:direction == 'b' | |
execute "normal ?" . l:pattern . "^M" | |
elseif a:direction == 'gv' | |
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.') | |
elseif a:direction == 'replace' | |
call CmdLine("%s" . '/'. l:pattern . '/') | |
elseif a:direction == 'f' | |
execute "normal /" . l:pattern . "^M" | |
endif | |
let @/ = l:pattern | |
let @" = l:saved_reg | |
endfunction | |
" Returns true if paste mode is enabled | |
function! HasPaste() | |
if &paste | |
return 'PASTE MODE ' | |
en | |
return '' | |
endfunction | |
" Don't close window, when deleting a buffer | |
command! Bclose call <SID>BufcloseCloseIt() | |
function! <SID>BufcloseCloseIt() | |
let l:currentBufNum = bufnr("%") | |
let l:alternateBufNum = bufnr("#") | |
if buflisted(l:alternateBufNum) | |
buffer # | |
else | |
bnext | |
endif | |
if bufnr("%") == l:currentBufNum | |
new | |
endif | |
if buflisted(l:currentBufNum) | |
execute("bdelete! ".l:currentBufNum) | |
endif | |
endfunction | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Nerd Tree | |
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
let g:NERDTreeWinPos = "left" | |
let NERDTreeShowHidden=0 | |
let NERDTreeIgnore = ['\.pyc$', '__pycache__'] | |
let g:NERDTreeWinSize=35 | |
map <leader>nn :NERDTreeToggle<cr> | |
map <leader>nb :NERDTreeFromBookmark | |
map <leader>nf :NERDTreeFind<cr> | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => Custom | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
execute pathogen#infect() | |
set number | |
set shell=bash | |
set showtabline=2 | |
xnoremap p pgvy | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
" => GO | |
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" | |
let g:go_disable_autoinstall = 0 | |
" Highlight | |
let g:go_fmt_command = "goimports" | |
let g:go_highlight_functions = 1 | |
let g:go_highlight_methods = 1 | |
let g:go_highlight_structs = 1 | |
let g:go_highlight_operators = 1 | |
let g:go_highlight_build_constraints = 1 | |
map <leader>gb :GoBuild<cr> | |
map <leader>gd :GoDoc<cr> | |
map <leader>gc :GoCallers<cr> | |
map <leader>gi :GoImports<cr> | |
nmap <F8> :TagbarToggle<CR> | |
let g:tagbar_type_go = { | |
\ 'ctagstype' : 'go', | |
\ 'kinds' : [ | |
\ 'p:package', | |
\ 'i:imports:1', | |
\ 'c:constants', | |
\ 'v:variables', | |
\ 't:types', | |
\ 'n:interfaces', | |
\ 'w:fields', | |
\ 'e:embedded', | |
\ 'm:methods', | |
\ 'r:constructor', | |
\ 'f:functions' | |
\ ], | |
\ 'sro' : '.', | |
\ 'kind2scope' : { | |
\ 't' : 'ctype', | |
\ 'n' : 'ntype' | |
\ }, | |
\ 'scope2kind' : { | |
\ 'ctype' : 't', | |
\ 'ntype' : 'n' | |
\ }, | |
\ 'ctagsbin' : 'gotags', | |
\ 'ctagsargs' : '-sort -silent' | |
\ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment