Inspired by some of the comments in our Your Vim Tips! (in particular those by Mafinar and Hallski) …what’s in your .vimrc
?
*If you’re using something like Janus, you’ll probably want to look in .gvimrc.after
Inspired by some of the comments in our Your Vim Tips! (in particular those by Mafinar and Hallski) …what’s in your .vimrc
?
*If you’re using something like Janus, you’ll probably want to look in .gvimrc.after
Here’s mine:
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>
Corresponding tweet for this thread:
https://twitter.com/dev_talk/status/1337873626201288705
Share link for this tweet.
Related portals:
I haven’t touched it for like forever. Not a good example either, but it is well attuned to my muscle memory.
This just showed up in a News Alert thread - think I might use a few of them
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
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!
I started off with (and still use) Janus however some people are not keen on the idea. Personally I think if you’re just starting out they can be a great way to get into Vim
This is a plugin found after stumbling over the feature in Doom Emacs and wanted to have the same functionality in Vim.
It gives a visual feedback to what you just yanked so that you can verify that you got it correctly.
I use Neovim. Here’s the stuff not specific to Neovim or plugins.
" 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