Blog


My .vimrc

Jul 16, 2018 | 3 minutes read

Tags: dotfiles, vim, vimrc, python

Here is my .vimrc. It’s mostly a collection of shortcuts and things that generally make my life in vim easier. If you’re looking for an entire file to copy and paste, see the last code block at the bottom.

hitting j then k while in insert mode is the equivalent of hitting escape

inoremap jk <Esc>

anywhere you see after the line below, it’s means to type a comma

let mapleader = ","

comma followed by a ‘w’ writes and quits your file

nnoremap <leader>w :wq!<Enter>

similar here, comma followed by a ‘q’ quits without saving

nnoremap <leader>q :q!<Enter>

single ‘quote’ a word

nnoremap <leader>' :silent! normal mpea'<Esc>bi'<Esc>`pl

double “quote” a word

nnoremap dq :silent! normal mpeld bhd `ph<CR>

turn on syntax highlighting

syntax on

file formatting for python

filetype indent plugin on
set tabstop=8 expandtab shiftwidth=4 softtabstop=4

my preference for background

set background=dark

python debugger shortcut, while in insert mode, type p then d then b and then tab, it will auto insert the call to set_trace()

inoremap pdb<tab> import pdb; pdb.set_trace()

when working with split windows, ctrl+ either j,k,h, or l moves in that direction to change windows

nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>

when writing C / C++, while in insert mode, type { then { and it produces a code block

inoremap {{ {<Enter><Enter>}<Up><Tab>

is carriage return, while in normal mode, when you hit enter, it clears your search buffer (when you search in vim, the search stays til you clear it)

nnoremap <CR> :noh<CR><CR>

comma then r, writes your current file, and runs python3 , hit enter again after script completes to drop back into vim

nnoremap <leader>r :w<CR>:! python3 %<CR>

The Entire file

" hitting j then k while in insert mode is the equivalent of hitting escape
inoremap jk <Esc>

" anywhere you see <leader> after the line below, it's a comma
let mapleader = ","

" so for these, comma then w writes and quits your file
nnoremap <leader>w :wq!<Enter>
" similar here, comma then q quits without saving
nnoremap <leader>q :q!<Enter>

" 'quote' a word
nnoremap <leader>' :silent! normal mpea'<Esc>bi'<Esc>`pl
" " double "quote" a word
nnoremap <leader>" :silent! normal mpea"<Esc>bi"<Esc>`pl
" " remove quotes from a word
nnoremap dq :silent! normal mpeld bhd `ph<CR>

" syntax highlighting
syntax on

" file formatting for python
filetype indent plugin on
set tabstop=8 expandtab shiftwidth=4 softtabstop=4

" my preference for background
set background=dark

" python debugger shortcut, while in insert mode, type p then d then b and
" then tab, it will auto insert the call to set_trace()
inoremap pdb<tab> import pdb; pdb.set_trace()

" when working with split windows, ctrl+ either j,k,h, or l moves in that
" direction to change windows
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>

" when writing C / C++, while in insert mode, type { then { and it produces a
" code block
inoremap {{ {<Enter><Enter>}<Up><Tab>

" <CR> is carriage return, while in normal mode, when you hit enter, it clears
" your search buffer (when you search in vim, the search stays til you clear
" it)
nnoremap <CR> :noh<CR><CR>

" comma then r, writes your current file, and runs python3 <name of file>, hit
" enter again after script completes to drop back into vim
nnoremap <leader>r :w<CR>:! python3 %<CR>

comments powered by Disqus