My first steps when working on a new machine / environment
Bash
First and foremost, we want to add a few things in our .bashrc
set -o vi
for a more vim-like experience
Aliases
Additionally, here’s a group of clever aliases you can copy-pate.
|
|
I’m a big fan of colors, so let’s add those as well.
|
|
Vim
After configuring the most important program, the shell, we configure the second, vim. Below are a list of useful configs and mappings.
- Syntax highlighting in vim
- Add
syntax on
to your.vimrc
- Add
- Show line numbers, and relative line numbers
set number relativenumber
- Enable auto-complete
set wildmode=longest,list,full
- Search and replace easily by hitting
S
in normal modennoremap S :%s//g<Left><Left>
- Search and replace syntax is as follows:
:%s/find/replace/g
- It’s also responsive to RegEx, which I will elaborate upon in my upcoming RegEx tutorial
- Save screen real-estate with smaller tabs
set shiftwidth=4
set tabstop=4
- Aliases for fast fingers
command WQ wq
command Wq wq
command W w
command Q q
- These make it such that if you enter any variation of
:wq
, it’ll know what you want
- These commands and bindings make it easy to open terminals
command Vterm :vsp | :terminal
command Hterm :sp | :terminal
map <C-t> :Vterm<CR>i
map <C-g> :Hterm<CR>i
Split Screen
Split screening in vim allows you to edit multiple files at once. You can open a horizontal split with CTRL-W s
(That means hitting control and w
at the same time, then s
) or a vertical slip with CTRL-W v
Navigating between splits in vim involves hitting CTRL-W
plus a movement key (h
, j
, k
, or l
), but we are going to simplify it with the following bindings
|
|
This allows you to navigate between splits with CTRL-H
, CTRL-J
, CTRL-K
, and CTRL-L
, which move you left, down, up, and right respectively.
Folding
Folding allows you to collapse sections of code based off of syntax. This is something I recently discovered and I’m a big fan of it.
|
|
To use folding, you can always open up the help menu with :help fold-commands
but below is a summary of key bindings in normal mode.
zo
: Open fold under cursorzc
: Close fold under cursorzR
: Open all foldszM
: Close all foldszX
: Reset folds