# What's in your .vimrc file?

**URL:** <https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007>\
**Category:** Code Editors\
**Tags:** vim, onivim\
**Created:** [12 December 2020 21:22 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007 "2020-12-12T21:22:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [12 December 2020 21:22 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/1 "2020-12-12T21:22:04Z")

</div>

Inspired by some of the comments in our [Your Vim Tips!](https://forum.devtalk.com/t/your-vim-tips/4748) (in particular those by [Mafinar](https://forum.devtalk.com/t/your-vim-tips/4748/19) and [Hallski](https://forum.devtalk.com/t/your-vim-tips/4748/21)) …what’s in your `.vimrc`?

\*If you’re using something like [Janus](https://github.com/carlhuda/janus), you’ll probably want to look in `.gvimrc.after`

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [12 December 2020 21:22 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/2 "2020-12-12T21:22:52Z")

</div>

Here’s mine:

```auto
color Elixify
set guifont=Menlo:h12
set linespace=2
let g:NERDTreeWinPos = "right"
autocmd BufWinEnter * NERDTreeMirror
set guioptions-=T " Removes top toolbar
set guioptions-=r " Removes right hand scroll bar
set go-=L " Removes left hand scroll bar
autocmd User Rails let b:surround_{char2nr('-')} = "<% \r %>" " displays <% %> correctly
set cpoptions+=$ " puts a $ marker for the end of words/lines in cw/c$ commands
let mapleader="," " Change mapleader from \ to ,
"autocmd BufWritePre *.rb :%s/\s\+$//e
autocmd BufWritePre * :%s/\s\+$//e
set shortmess+=A " removes swap file warnings

"Better window navigation
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l

set splitbelow
set splitright

inoremap jk <esc>

```

---

<div class="post-metadata">

**Author:** ![mafinar](https://forum.devtalk.com/user_avatar/forum.devtalk.com/mafinar/32/723_2.png) [@mafinar](https://forum.devtalk.com/u/mafinar)\
**Post date:** [13 December 2020 03:38 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/4 "2020-12-13T03:38:09Z")

</div>

> **[code-shoily/code-shoily-vimrc](https://github.com/code-shoily/code-shoily-vimrc)**
>
> The VIMRC I've been using. Cleaned up a little from https://github.com/code-shoily/vimrc

I haven’t touched it for like forever. Not a good example either, but it is well attuned to my muscle memory.

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [14 December 2020 02:31 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/5 "2020-12-14T02:31:25Z")

</div>

This just showed up in a [News Alert](https://forum.devtalk.com/t/hacker-news-front-page-18-new-links-sunday-13-december-2020-22-00/5045) thread - think I might use a few of them 😆

```nohighlight
set hlsearch " highlight all search results
set ignorecase " do case insensitive search 
set incsearch " show incremental search results as you type
set number " display line number
set noswapfile " disable swap file

```

---

<div class="post-metadata">

**Author:** ![herminiotorres](https://forum.devtalk.com/user_avatar/forum.devtalk.com/herminiotorres/32/570_2.png) [@herminiotorres](https://forum.devtalk.com/u/herminiotorres)\
**Post date:** [14 December 2020 10:11 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/6 "2020-12-14T10:11:41Z")

</div>

I’m in the middle of the process of changing my editor for VIM, and it’s a good choice? Yes, for sure… and I will sneak around other .vimrc in this post to get some ideas to complete my .vimrc!

---

<div class="post-metadata">

**Author:** ![AstonJ](https://forum.devtalk.com/user_avatar/forum.devtalk.com/astonj/32/7_2.png) [@AstonJ](https://forum.devtalk.com/u/AstonJ)\
**Post date:** [14 December 2020 18:29 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/7 "2020-12-14T18:29:58Z")

</div>

> [@herminiotorres](#):
>
> I’m in the middle of the process of changing my editor for VIM, and it’s a good choice?

I started off with (and still use) [Janus](https://github.com/carlhuda/janus) however some people are [not keen on the idea](https://forum.devtalk.com/t/spacevim-vs-spacemacs/1323/13). Personally I think if you’re just starting out they can be a great way to get into Vim 😃

---

<div class="post-metadata">

**Author:** ![Hallski](https://forum.devtalk.com/user_avatar/forum.devtalk.com/hallski/32/610_2.png) [@Hallski](https://forum.devtalk.com/u/Hallski)\
**Post date:** [15 December 2020 23:23 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/8 "2020-12-15T23:23:49Z")

</div>

This is a plugin found after stumbling over the feature in Doom Emacs and wanted to have the same functionality in Vim.

> **[machakann/vim-highlightedyank](https://github.com/machakann/vim-highlightedyank)**
>
> Make the yanked region apparent! Contribute to machakann/vim-highlightedyank development by creating an account on GitHub.

It gives a visual feedback to what you just yanked so that you can verify that you got it correctly.

---

<div class="post-metadata">

**Author:** ![foxtrottwist](https://forum.devtalk.com/user_avatar/forum.devtalk.com/foxtrottwist/32/1213_2.png) [@foxtrottwist](https://forum.devtalk.com/u/foxtrottwist)\
**Post date:** [28 May 2021 21:30 UTC](https://forum.devtalk.com/t/whats-in-your-vimrc-file/5007/9 "2021-05-28T21:30:56Z")

</div>

I use Neovim. Here’s the stuff not specific to Neovim or plugins.

```auto
" Enable 24bit true color
set termguicolors

" Enable the theme
syntax enable
colorscheme rigel
set noshowmode
set cursorline

" Setup code folding
set foldmethod=indent
set foldlevel=99
set foldcolumn=1

" A little mourse never hurt anyone
set mouse=a

" Display relative line numbers, with absolute line number for current line
set number
set numberwidth=5
set relativenumber

" Open new split panes to right and below
set splitright
set splitbelow

" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l

set ignorecase " Ignore case when searching
set smartcase " When searching try to be smart about cases
set hlsearch " Highlight search results
set incsearch " Makes search act like search in modern browsers
set lazyredraw " Don't redraw while executing macros (good performance config)
set magic " For regular expressions turn magic on
set expandtab " Use spaces instead of tabs
set smarttab " Be smart when using tabs ;)

" 1 tab == 2 spaces
set shiftwidth=2
set tabstop=2

" Linebreak on 500 characters
set lbr
set tw=500

set ai " Auto indent
set si " Smart indent
set wrap " Wrap lines

set history=500 " Sets how many lines of history VIM has to remember
set hidden

" Enable filetype plugins
filetype plugin on
filetype indent on

" Set to auto read when a file is changed from the outside
set autoread
au FocusGained,BufEnter * checktime

" Map leader to comma
let mapleader = ","

" Fast saving
nmap <leader>w :w!<cr>

" Map Esc to tn
inoremap tn <Esc>

" Useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove<cr>
map <leader>t<leader> :tabnext<cr>

" Let 'tl' toggle between this and the last accessed tab
let g:lasttab = 1
nmap <Leader>pp :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()

" Turn terminal to normal mode with escape
tnoremap tn <C-\><C-n>

" Moving lines
nnoremap <A-Down> :m .+1<CR>==
nnoremap <A-Up> :m .-2<CR>==
inoremap <A-Down> <Esc>:m .+1<CR>==gi
inoremap <A-Up> <Esc>:m .-2<CR>==gi
vnoremap <A-Down> :m '>+1<CR>gv=gv
vnoremap <A-Up> :m '<-2<CR>gv=gv

" 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>

function! CmdLine(str)
    call feedkeys(":" . a:str)
endfunction

function! VisualSelection(direction, extra_filter) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", "\\/.*'$^~[]")
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'gv'
        call CmdLine("Ack '" . l:pattern . "' " )
    elseif a:direction == 'replace'
        call CmdLine("%s" . '/'. l:pattern . '/')
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction

" Press Space to turn off highlighting and clear any message already displayed.
:nnoremap <silent> <Space> :nohlsearch<Bar>:echo<CR>

" Elixir preferences
let g:mix_format_on_save = 1

" Keep syntax highlighting in sync in larger React files
autocmd BufEnter *.{js,jsx,ts,tsx} :syntax sync fromstart
autocmd BufLeave *.{js,jsx,ts,tsx} :syntax sync clea

```
