Last active
March 6, 2023 19:15
-
-
Save cyberang3l/ba53f569d33d66c246add0f5e7d5d0a4 to your computer and use it in GitHub Desktop.
My .vimrc file
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
" Install vim-plug if we don't already have it and try to install all the | |
" plugins | |
if empty(glob('~/.vim/autoload/plug.vim')) | |
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs | |
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim | |
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | |
endif | |
function! BuildYCM(info) | |
" info is a dictionary with 3 fields | |
" - name: name of the plugin | |
" - status: 'installed', 'updated', or 'unchanged' | |
" - force: set on PlugInstall! or PlugUpdate! | |
if a:info.status == 'installed' || a:info.force | |
!./install.py --clang-completer --ts-completer --go-completer --rust-completer | |
endif | |
endfunction | |
call plug#begin() | |
" YouCompleteMe needs some additional components to be compiled. Ensure that | |
" you have all the necessary components installed: | |
" cargo provides rust support | |
" mono-devel provides C# support | |
" $ sudo apt-get -y install build-essential cmake cargo mono-devel python-dev | |
" | |
" For nodejs https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions: | |
" $ curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash - | |
" $ sudo apt-get install -y nodejs | |
" $ sudo npm install -g typescript | |
" For the java-completer and go-completer make sure that you have installed | |
" the necessary tools first (JDK8 ang golang) | |
" https://golang.org/dl/ | |
" https://launchpad.net/~webupd8team/+archive/ubuntu/java | |
Plug 'Valloric/YouCompleteMe', { 'do': function('BuildYCM') } | |
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py' | |
" Plugins | |
Plug 'tpope/vim-sensible' | |
Plug 'jeetsukumaran/vim-filebeagle' | |
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } | |
Plug 'tpope/vim-git', { 'for': 'git' } | |
Plug 'tpope/vim-fugitive' | |
Plug 'tpope/vim-rhubarb', { 'do': 'sudo apt-get -y install curl' } | |
Plug 'MobiusHorizons/fugitive-stash.vim' | |
Plug 'airblade/vim-gitgutter' | |
Plug 'rodjek/vim-puppet' | |
Plug 'fatih/vim-go', { 'for': 'go', 'do': ':GoUpdateBinaries' } | |
Plug 'w0rp/ale' | |
Plug 'majutsushi/tagbar', { 'do': 'sudo apt-get -y install exuberant-ctags' } | |
Plug 'tpope/vim-surround' | |
Plug 'tpope/vim-ragtag' | |
Plug 'pearofducks/ansible-vim', { 'do': 'cd ./UltiSnips; python2 generate.py' } | |
Plug 'chazy/cscope_maps' | |
Plug 'vim-airline/vim-airline', { 'do': 'sudo apt-get -y install fonts-powerline' } | |
Plug 'vim-airline/vim-airline-themes' | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
Plug 'tomasr/molokai', { 'as': 'molokai-tomasr', | |
\ 'do': 'cd colors; ln -sf molokai.vim molokai-tomasr.vim' } | |
Plug 'sickill/vim-monokai', {'as': 'monokai-sickill', | |
\ 'do': 'cd colors; ln -sf monokai.vim monokai-sickill.vim' } | |
Plug 'crusoexia/vim-monokai', {'as': 'monokai-crusoexia', | |
\ 'do': 'cd colors; ln -sf monokai.vim monokai-crusoexia.vim' } | |
" All of your Plugins must be added before the following line | |
call plug#end() | |
if &term =~ '^screen' | |
" tmux will send xterm-style keys when its xterm-keys option is on | |
execute "set <xUp>=\e[1;*A" | |
execute "set <xDown>=\e[1;*B" | |
execute "set <xRight>=\e[1;*C" | |
execute "set <xLeft>=\e[1;*D" | |
map <Esc>OM <CR> | |
map! <Esc>OM <CR> | |
map <Esc>OH <Home> | |
map! <Esc>OH <Home> | |
map <Esc>OF <End> | |
map! <Esc>OF <End> | |
endif | |
" fzf quick mappings for searching different contexts | |
noremap <C-G> :GFiles<CR> | |
noremap <C-B> :Buffers<CR> | |
noremap <C-F> :Files<CR> | |
noremap <C-S><C-S> :RGU<CR> | |
noremap <C-S> :RG<CR> | |
inoremap <C-G> <C-O>:GFiles<CR> | |
inoremap <C-B> <C-O>:Buffers<CR> | |
inoremap <C-F> <C-O>:Files<CR> | |
inoremap <C-S><C-S> <C-O>:RGU<CR> | |
inoremap <C-S> <C-O>:RG<CR> | |
" In the default implementation of Rg, ripgrep process starts only once with | |
" the initial query (e.g. :Rg foo) and fzf filters the output of the process. | |
" | |
" This is okay in most cases because fzf is quite performant even with | |
" millions of lines, but we can make fzf completely delegate its search | |
" responsibliity to ripgrep process by making it restart ripgrep whenever the | |
" query string is updated. In this scenario, fzf becomes a simple selector | |
" interface rather than a "fuzzy finder". | |
function! RipgrepFzf(query, fullscreen) | |
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case -- %s || true' | |
let initial_command = printf(command_fmt, shellescape(a:query)) | |
let reload_command = printf(command_fmt, '{q}') | |
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} | |
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) | |
endfunction | |
" We name this command RG | |
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0) | |
" Make a ripgrep command that will search unrestricted without respecting the | |
" .gitignore file when operating under a git repo. This is the same as | |
" RipgrepFzf function, but with the additional --unrestricted flag passed to | |
" the ripgrep command. | |
function! RipgrepFzfUnrestricted(query, fullscreen) | |
let command_fmt = 'rg --unrestricted --column --line-number --no-heading --color=always --smart-case -- %s || true' | |
let initial_command = printf(command_fmt, shellescape(a:query)) | |
let reload_command = printf(command_fmt, '{q}') | |
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]} | |
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen) | |
endfunction | |
" We name this command RGU | |
command! -nargs=* -bang RGU call RipgrepFzfUnrestricted(<q-args>, <bang>0) | |
" Tagbar | |
nnoremap <F8> :TagbarToggle<CR> | |
" Go to next/previous buffer with Ctrl+N/Ctrl+P kbd shortcuts | |
nnoremap <C-N> :bnext<CR> | |
nnoremap <C-P> :bprevious<CR> | |
" Move between split windows with a single shortcut (No need to press Ctrl+W | |
" first) | |
nnoremap <C-J> <C-W><C-J> | |
nnoremap <C-K> <C-W><C-K> | |
nnoremap <C-L> <C-W><C-L> | |
nnoremap <C-H> <C-W><C-H> | |
nnoremap <C-\> :YcmCompleter GoTo<CR> | |
nnoremap <F11> :YcmCompleter FixIt<CR> | |
nmap <silent> <F9> <Plug>(ale_previous_wrap) | |
nmap <silent> <F10> <Plug>(ale_next_wrap) | |
nmap <silent> <F12> <Plug>(ale_fix) | |
" Ctrl+Up / Ctrl+Down move the cursor 5 lines up/down | |
noremap <C-Up> 5k | |
noremap <C-Down> 5j | |
" <C-O> issues a normal-mode command in insert mode | |
inoremap <C-Up> <C-O>5k | |
inoremap <C-Down> <C-O>5j | |
set encoding=utf8 | |
set number | |
set cursorline | |
set pastetoggle=<F2> | |
" http://vim.wikia.com/wiki/Vim_buffer_FAQ#hidden | |
set hidden | |
filetype plugin indent on | |
set tabstop=4 " show existing tab with 4 spaces width | |
set shiftwidth=4 " when indenting with '>', use 4 spaces width | |
"set expandtab " On pressing tab, insert 4 spaces | |
colorscheme monokai-crusoexia | |
let g:netrw_winsize = 16 | |
" Configure vim-airline | |
let g:airline_theme='dark' | |
" Enable the buffer list on top | |
let g:airline#extensions#tabline#enabled = 1 | |
let g:airline#extensions#tabline#formatter = 'unique_tail' | |
" Configure the ailine symbols | |
if !exists('g:airline_symbols') | |
let g:airline_symbols = {} | |
endif | |
" unicode symbols | |
let g:airline_left_sep = '»' | |
let g:airline_left_sep = '▶' | |
let g:airline_right_sep = '«' | |
let g:airline_right_sep = '◀' | |
let g:airline_symbols.crypt = '' | |
let g:airline_symbols.linenr = '¶' | |
let g:airline_symbols.maxlinenr = '㏑' | |
let g:airline_symbols.branch = '⎇' | |
let g:airline_symbols.paste = '∥' | |
let g:airline_symbols.paste = '-> PASTE' | |
let g:airline_symbols.spell = 'Ꞩ' | |
let g:airline_symbols.notexists = '∄' | |
let g:airline_symbols.whitespace = 'Ξ' | |
" ALE config | |
let g:ale_open_list = 0 | |
"let g:ale_list_window_size = 5 | |
"let g:ale_completion_enabled = 1 | |
let g:ale_sign_column_always = 1 | |
let g:ale_puppet_puppetlint_options = '--no-autoloader_layout-check --no-140chars-check --no-documentation-check' | |
let g:ale_python_pylint_options = '--disable=invalid-name,missing-docstring' | |
let g:ale_python_flake8_options = '--ignore=E501' | |
let g:ale_linters = { | |
\ 'python': ['flake8'], | |
\ 'go': ['gofmt', 'golint', 'govet', 'golangci-lint', 'gotype', 'staticcheck'] | |
\ } | |
let g:ale_echo_msg_format = '%linter%: %s' | |
let g:ale_fixers = { | |
\ '*': ['remove_trailing_lines', 'trim_whitespace'], | |
\ 'python': ['autopep8'], | |
\ 'cpp': ['clang-format', 'uncrustify'], | |
\ 'sh': ['shfmt'], | |
\ 'rust': ['rustfmt'], | |
\ 'go': ['gofmt', 'goimports'] | |
\ } | |
let g:ale_go_gofmt_options = '-s' | |
let g:ale_cpp_clangformat_options = '--style=llvm' | |
function! AutodetectPythonLinter() | |
" Check shebang and if python3 is found, use a python3 linter. | |
" Otherwise fallback to python2. | |
if getline(1) =~ "^#!.*python3" | |
let g:ycm_python_interpreter_path = '/usr/bin/python3' | |
let g:ycm_python_binary_path = '/usr/bin/python3' | |
else | |
let g:ycm_python_interpreter_path = '/usr/bin/python' | |
let g:ycm_python_binary_path = '/usr/bin/python' | |
endif | |
endfunction | |
autocmd BufNewFile,BufRead,BufWrite * call AutodetectPythonLinter() | |
" VIM Markdown | |
let g:vim_markdown_folding_disabled = 1 | |
let g:vim_markdown_frontmatter = 1 | |
" ansible-vim | |
let g:ansible_unindent_after_newline = 1 | |
let g:ansible_template_syntaxes = { '*.sh.j2': 'sh' } | |
" https://vim.fandom.com/wiki/Fix_syntax_highlighting | |
autocmd BufEnter * :syntax sync minlines=200 | |
" For fugitive: https://github.com/tpope/vim-fugitive/issues/426 | |
setglobal tags^=./.git/tags | |
" Run goimports on save: https://github.com/fatih/vim-go/issues/207 | |
let g:go_fmt_command = "goimports" | |
" Put sensitive github configuration in the file ${HOME}/.vimrc-sensitive | |
" E.g. I put my github enterprise rhubarb urls in this file. | |
silent !touch ${HOME}/.vimrc-sensitive | |
source ${HOME}/.vimrc-sensitive |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment