What's in your vimrc?

Post your OS and .vimrc to this thread. Curious what people are using and why.

Home OS is Ubuntu MATE, at work I use CentOS and RHEL exclusively.

For my vimrc, I use a couple of plugins, gruvbox cause it’s awesome, fugitive cause it makes handling git in a standard terminal a lot easier, and most of my job and hobbies involve doing that. I like airline a lot, it’s basically powerline with a couple less features, but it’s implemented entirely in vim, so I can set it up through my vimrc and not have to worry about all the python stuff that is involved with installing powerline.

Outside of that, I think my vimrc is a pretty standard affair. I prefer spaces over tabs, so I set that up in the vimrc, and I like relative line numbers, I feel like it makes bouncing up and down files a lot easier. I set my leader to , as I find that

, + space

is a pretty easy key combo to hit to for nohlsearch.

In addition, I made a couple of shell scripts that will set up my vimrc and bashrc automatically, and stored those as a git repo on GitHub.

https://github.com/TheFlemoid/personal_app_configs

Since I’m frequently spinning VMs up and down, this allows me to git clone the repo and run the scripts on a new VM, and have everything setup without having to do much.

vimrc:

let mapleader=","

set tabstop=4
set shiftwidth=4
set expandtab
set number
set relativenumber
syntax enable
set showcmd
set lazyredraw
set wildmenu
set showmatch
set smartindent
set noswapfile

set hlsearch
set incsearch
noremap <leader><space> :nohlsearch<CR>
nmap <leader>gs :G<CR>

call plug#begin('~/.vim/plugged')
Plug 'mohertz/gruvbox'
Plug 'tpope/vim-fugitive'
Plug 'vim-airline/vim-airline'
call plug#end()

se t_Co=256
colorscheme gruvbox
set background=dark
2 Likes

I use Arch, and do most of my work in Python. So my .vimrc is geared towards that for the most part.

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

call plug#begin(expand('~/.vim/plugged'))
"Plug 'arcticicestudio/nord-vim'
Plug 'dracula/vim', {'as': 'dracula'}
Plug 'scrooloose/syntastic'
Plug 'airblade/vim-gitgutter'
Plug 'davidhalter/jedi-vim'
call plug#end()

" Syntastic settings
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
" End Syntastic settings
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"

" automagically go into paste mode when pasting with the mouse
inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()

function! XTermPasteBegin()
  set pastetoggle=<Esc>[201~
  set paste
  return ""
endfunction

"colorscheme nord
colorscheme dracula
syntax on
filetype indent plugin on
:set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
set list
:set spell spelllang=en_us

" Remap split stuff
set splitbelow splitright

nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

" C-W w switch pane
"
" Highlight trailing whitespace with different bg color
:highlight ExtraWhitespace ctermbg=red guibg=red
:match ExtraWhitespace /\s\+$/

Wrote a post on the various sections if you need some clarification on what stuff does: My .vimrc - Dev Oops

I tend to think that the OP isn’t aware of how long a .vimrc can get…

Mine has evolved since the 90s, but gets tweaked all the time. I use it on Kubuntu mostly now, but have had long periods on Windows and Windows/cygwin, and presently on Centos occasionally.

A couple of things someone might find vaguely useful:

  1. Bill Joy wrote the original vi using a Lear Siegler ADM-3A terminal, which has the “:”, colon, as an unshifted key. It gets used a lot, and for me often when taking a hand from the mouse, so I use

    map ; :
    ounmap ;

I lose the normal ;, but can still do d; or c; and the like.

  1. I copied this from somewhere way back and I’ve never looked at how it works, but it has always worked, and is indispensable:

    " search for the visual selection
    vnoremap * :
    \let old_reg=getreg(’"’)
    \let old_regmode=getregtype(’"’)
    \gvy/=substitute(substitute(
    \escape(@", ‘\/.$^~[]’ ), “\n$”, “”, “”),
    “\n”, ‘\_[[:return:]]’, “g”)
    :call setreg(’"’, old_reg, old_regmode)
    vnoremap # :
    \let old_reg=getreg(’"’)
    \let old_regmode=getregtype(’"’)
    \gvy?=substitute(substitute(
    \escape(@", '\/.
    $^~[]’ ), “\n$”, “”, “”),
    “\n”, ‘\_[[:return:]]’, “g”)
    :call setreg(’"’, old_reg, old_regmode)

1 Like

How long is your .vimrc? :sweat_smile:

I recently made the switch to init.lua so there isn’t a whole lot in it yet but I find lua much more approachable than vimscript.

Plain ol’ vi (ex-vi @ sourceforge, or nvi on the *BSDs), no vim in use anywhere.

Linux Mint 20.1. I don’t do a ton of scripting/programming, so it’s very simple. :slight_smile:

colo desert
set hlsearch
set tabstop=4
set autoindent
1 Like

Mines fairly extensive as well. Hang tight, when I get back to my rig, I’ll share it.

2 Likes

Nice and simple indeed

For some reason, I’m oddly looking forward to this post

1 Like

~300 lines, with comments. Some of those are platform-specific, commented out. Some just invokes packages and other plugins.

Mine’s only got 16 lines…

set tabstop=4
set softtabstop=4
set shiftwidth=4

set expandtab
set number
set ruler

set showcmd
set hlsearch

set term=xterm
set background=dark
set mouse=a
syntax on
hi Comment ctermfg=240
autocmd FileType yaml setlocal ai ts=2 sw=2 et
1 Like

Alright, finally got around to my PC:

let mapleader = ","
if ! filereadable(system('echo -n "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim"'))
    echo "Downloading vim-plug from github"
    silent !mkdir -p ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/
    silent !curl "https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" > ${XDG_CONFIG_HOME:-$HOME/.config}/nvim/autoload/plug.vim
    autocmd VimEnter * PlugInstall
endif
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'airblade/vim-gitgutter'
Plug 'ryanoasis/vim-devicons'
Plug 'altercation/vim-colors-solarized'
Plug 'vim-airline/vim-airline'
Plug 'andrewstuart/vim-kubernetes'
Plug 'junegunn/fzf', { 'do': { ->fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'stsewd/fzf-checkout.vim'
Plug 'airblade/vim-rooter'
Plug 'scrooloose/nerdcommenter'
Plug 'ms-jpq/chadtree', {'branch': 'chad', 'do': ':UpdateRemotePlugins'}
Plug 'christoomey/vim-tmux-navigator'
Plug 'morhetz/gruvbox'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
Plug 'Glench/Vim-Jinja2-Syntax'
Plug 'vimwiki/vimwiki'
call plug#end()

set encoding=UTF-8

filetype plugin on
inoremap jk <ESC>
inoremap kk <ESC>k
inoremap jj <ESC>j

vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle

nmap <silent> <leader>h :bp<CR>
nmap <silent> <leader>l :bn<CR>

nmap <silent> <a-h> :tabp<CR>
nmap <silent> <a-l> :tabn<CR>


"resize binds

nmap <silent> <c-y> :res +2<CR>
nmap <silent> <c-m> :res -2<CR>


"set timeoutlen=500
set relativenumber
set number
set cindent
set tabstop=4
set shiftwidth=4
set cmdheight=2
set updatetime=300
set shortmess+=c
set expandtab
set smarttab
set go=a
set mouse=a
colorscheme gruvbox

inoremap {<CR> {<CR>}<C-o>O


let g:airline#extensions#tabline#enabled = 1
let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
let g:NERDTreeGitStatusUseNerdFonts = 1
let g:webdevicons_enable_airline_tabline = 1
let g:webdevicons_enable_airline_statusline = 1
let g:webdevicons_enable_nerdtree = 1
let g:WebDevIconsNerdTreeAfterGlyphPadding = '  '
let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
let g:WebDevIconsUnicodeGlyphDoubleWidth = 1


let g:go_fmt_command = "goimports"
let g:go_auto_type_info = 1
let g:airline_powerline_fonts = 1

nmap <silent> <C-n> :CHADopen<CR>
vmap ++ <plug>NERDCommenterToggle
nmap ++ <plug>NERDCommenterToggle


map <C-O> :FzfBuffers<CR>
map <C-P> :FzfFiles<CR>
inoremap <C-O> <ESC>:FzfBuffers<CR>
inoremap <C-P> <esc>:FzfFiles<CR>


augroup goconfigs
    autocmd!
    autocmd Filetype go nmap <C-B> :w<CR>:GoBuild<CR>
augroup end



augroup vimconfigs
    autocmd!
    autocmd Filetype vim nmap <C-G> :source %<CR>
augroup end



let g:vimwiki_list = [{'path': '~/vimwiki/', 'template_path': '~/vimwiki/templates/',
                      \ 'template_default': 'default', 'syntax': 'markdown', 'ext': '.md',
                      \ 'path_html': '~/vimwiki/site_html/', 'custom_wiki2html': 'vimwiki_markdown',
                      \ 'html_filename_parameterization': 1,
                      \ 'template_ext': '.tpl'}]


"command! -nargs=0 Prettier: CocCommand prettier.formatFile

let g:fzf_command_prefix = 'Fzf'
let g:fzf_buffers_jump = 1
let g:fzf_commits_log_options = '--graph --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr"'
let g:fzf_tags_command = 'ctags -R'
let g:fzf_commands_expect = 'alt-enter,ctrl-x'
"let g:fzf_preview_window = 'center:40%'

let g:coc_global_extensions = [
	\'coc-snippets',
	\'coc-pairs',
	\'coc-tsserver',
	\'coc-eslint',
	\'coc-prettier',
	\'coc-json'
	\]

set hidden

set shortmess+=c

set signcolumn=yes

inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
    let col = col('.') - 1
    return !col || getline('.')[col - 1]  =~# '\s'
endfunction

inoremap <silent><expr> <c-space> coc#refresh()

inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"

nnoremap S :%s//g<Left><Left>
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)

nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)

function! OpenCommitDiff() 
    normal! 0w"ayiw
    let commitid=@a
    let log=system('git log --oneline --decorate --color=never | grep --color=never ' . commitid)
    let patch=system('git diff ' . commitid . '~ ' . commitid)
    :new
    :set buftype=nofile
    :set filetype=diff
    :put =log
    :put =patch
    normal! gg
endfunction


augroup interactive_rebase
  autocmd!
  let b:rebase_commands="^(pick|reword|edit|squash|fixup|exec|drop)"
  autocmd FileType gitrebase nnoremap <buffer> <silent> I :s/\v<c-r>=b:rebase_commands<cr>/pick/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> R :s/\v<c-r>=b:rebase_commands<cr>/reword/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> E :s/\v<c-r>=b:rebase_commands<cr>/edit/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> S :s/\v<c-r>=b:rebase_commands<cr>/squash/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> F :s/\v<c-r>=b:rebase_commands<cr>/fixup/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> X Oexec<space>
  autocmd FileType gitrebase nnoremap <buffer> <silent> D :s/\v<c-r>=b:rebase_commands<cr>/drop/<cr>:nohlsearch<cr>
  autocmd FileType gitrebase nnoremap <buffer> <silent> C :call OpenCommitDiff()<CR>
augroup END


nmap <silent> <leader>gj :diffget //3<CR>
nmap <silent> <leader>gf :diffget //2<CR>
nmap <silent> <leader>gs :G<CR>
nmap <silent> <leader>gc :FzfGBranches<CR>
nmap <silent> <leader>gu :Gpush<CR>
nmap <silent> <leader>gpo :Gpull origin<CR>
nmap <silent> <leader>gpu :Gpull upstream<CR>

"Git merging and rebasing
nmap <silent> <leader>gm :Git mergetool
nmap <silent> <leader>grr :Git rebase
nmap <silent> <leader>gri :Git rebase --interactive
nmap <silent> <leader>grc :Git rebase --continue<CR>
nmap <silent> <leader>gra :Git rebase --abort
"autocmd FileType gitrebase nnoremap <buffer> <silent> <leader>gd :call OpenCommitDiff()<CR>



nmap <silent> gcc :GoCoverage<cr>
nmap <silent> gcd :GoCoverageClear<cr>

nnoremap <silent> K :call <SID>show_documentation()<CR>

"function! s:show_documentation()
    "if (index(['vim','help'], &filetype) >= 0)
        "execute 'h '.expand('<cword>')
    "else
        "call CocAction('doHover')
    "endif
"endfunction

autocmd CursorHold * silent call CocActionAsync('highlight')

xmap <leader>f  <Plug>(coc-format-selected)
nmap <leader>f  <Plug>(coc-format-selected)

augroup mygroup
    autocmd!
    " Setup formatexpr specified filetype(s).
    autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
    " Update signature help on jump placeholder
    " autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end

Oh yeah, I’m using the objectively superior nvim.

2 Likes

same

pasted here also
" XDG Compliance """""""""""""""""""""""""""""""""""""""""""""""""""""""
set directory=$XDG_CACHE_HOME/nvim,~/,/tmp
set backupdir=$XDG_CACHE_HOME/nvim,~/,/tmp
set viminfo+=n$XDG_CACHE_HOME/nvim/viminfo

" Plugins via junegunn/vim-plug """"""""""""""""""""""""""""""""""""""""
call plug#begin(system('printf "${XDG_CONFIG_HOME:-$HOME/.config}/nvim/junegunn_vim-plugged"'))
  Plug 'tpope/vim-sensible'           " defaults
  Plug 'tpope/vim-surround'           " manipulate quotes, brackets, tags, etc
  Plug 'tpope/vim-repeat'             " extend . repeat functionality to plugins
  Plug 'tpope/vim-sleuth'             " auto-detect indentation
  Plug 'ervandew/supertab'            " tab completion
  Plug 'sheerun/vim-polyglot'         " extended syntax detection
  Plug 'darfink/vim-plist'            " plist encoding support
  Plug 'vim-airline/vim-airline'      " interface theming
  Plug 'ap/vim-css-color'             " overlay text representations of colors with the color
call plug#end()

" Basics """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set nocompatible    " don't try to be compatible with legacy vi
set encoding=utf-8
filetype plugin on  " detect file types

" Formatting """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on                   " enable syntax highlighting
if exists('+termguicolors') " use 24-bit color if possible
  let &t_8f="\<Esc>[38;2;%lu;%lu;%lum"
  let &t_8b="\<Esc>[48;2;%lu;%lu;%lum"
  set termguicolors
endif
colorscheme o0-o

"indenting defaults (does not override vim-sleuth's indenting detection)
if get(g:, '_has_set_default_indent_settings', 0) == 0
  set expandtab     " convert tabs to spaces
  set tabstop=2     " 2-space \t
  set softtabstop=2 " 2-space tab
  set shiftwidth=2  " 2-space indent
  let g:_has_set_default_indent_settings=1
endif
set showbreak=↪
set list lcs=space:·,trail:·,tab:•· " whitespace indicators

" Clipboard """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set clipboard+=unnamedplus  " use system clipboard
set go+=a                   " automatically copy visual selection to clipboard

" Interface """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set mouse=a               " enable mouse in all modes
set number relativenumber " relative line numbers and current line number
let &colorcolumn="73,80"
autocmd BufEnter * highlight PEPOver ctermbg=white guibg=#2A0415
autocmd BufEnter * match PEPOver /\%80v.*/
"status line
set laststatus=2          " always show the status line
set noshowmode  " airline handles this for us
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_tab_count = 0
let g:airline#extensions#tabline#tab_nr_type = 2 " splits and tab number
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline_symbols_ascii = 1
let g:airline_section_a = airline#section#create(['mode'])
let g:airline_section_b = airline#section#create(['%R'])
let g:airline_section_c = airline#section#create(['%F'])
"let g:airline_section_gutter = airline#section#create([''])
let g:airline_section_x = airline#section#create(['ffenc'])
let g:airline_section_y = airline#section#create(['%p%%[%L]'])
let g:airline_section_z = airline#section#create(['%Y'])

" Behaviors """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
set iskeyword-=_                " count underscore as word separator
set wildmode=longest,list,full  " autocompletion
"supertab tab completion
let g:SuperTabMappingForward = '<s-tab>'
let g:SuperTabMappingBackward = '<s-c-tab>'
"disable automatic commenting on newline
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
set splitbelow splitright " split open at the bottom and right
autocmd BufWritePre * %s/\s\+$//e   " delete trailing whitespace on save
autocmd BufWritePre * %s/\n\+\%$//e

colorscheme o0-o

:man_artist:


lol, I broke the airline theme trying to change the dracula scheme to o0-o (it is a custom theme, but I used dracula as a template and never changed the name)

1 Like

Ohhh, stealing this:

set iskeyword-=_                " count underscore as word separator
2 Likes

These are some very nice .vimrc files. Will have to look into what some of these plugins do too. Curious what @wendell has

1 Like

I don’t have most of this stuff, but I found an interesting talk yesterday with some nice ideas for what to put into vimrc:

Unfortunately the tarball he’s talking about seems to be offline, but I’m sure it can be found somewhere.
edit: link at the end of the presentation, it’s on GitHub (surprise)