TODO
Use sh script to initialize automatically
In this article I will introduce:
- Backup and share your Linux config, known as
dotfiles
on GitHub. - Initialize terminal with
zsh
andvim
with dotfiles.
1. dotfiles
Basically speaking, Linux config files are start with .
, like .zshrc
for oh-my-zsh and .vim
for vim.
People share their customized config on GitHub http://dotfiles.github.io/. You can easily get and learn how others setup their OS and softwares.
You can also backup and sync through GitHub, as easily as create a repo and upload your dotfiles into it, Here is mine pin-dotfiles.
Warning
You shouldn’t upload your files with secrets like passwords or other sensitive information to a public repo!
2. Initialize terminal with dotfiles
It is intelligent to use sh scripts to do duplicated jobs like initialization every time you hand on a new system. But, today let’s manually download dotfiles and make things work.
Before it, think about what softwares you mostly use to dev. It’s safe to say shell and vim. Here, I’ll use my dotfiles to demonstarte. And I’ll introduce what I customized in 3. My zsh and zsh customization.
2.1 Install vim and zsh
Vim is usually installed with the system. Run vi
to check. If not, I suggest install neovim
instead, which is a reconstructed vim and compatibale with vim configurations.
cat /etc/shells
to check whether zsh is installed. If not, find how in zsh wiki.
oh-my-zsh is a framework to help manage zsh configuration.
# install zsh on Ubuntu
apt install zsh
# change current shell to zsh
chsh -s $(which zsh)
# install oh-my-zsh
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
2.2 Plant dotfiles
# prepare dotfiles
git clone https://github.com/pinchenjohnny/pin-dotfiles.git
cd pin-dotfiles
cp -t ~/ .vim .zshrc
zsh-autosuggestions is a commands prompt based on input history.
autojump: jump to visted directory arbitrarily using command j <visited dir>
.
# make zsh work
cd ~
# install zsh-autosuggestions
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
# install autojump
git clone git://github.com/wting/autojump.git
cd autojump
python ./install.py
cd ~
# REMEMBER to change /home/pinchen to your home dir in .zshrc
source .zshrc
vim-plug is a vim plugins manager.
# make vim work
# for neovim, this is slightly different
# check neovim github for details
cd ~
# install vim-plug
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
cd ~/.vim
vi vimrc
To install vim plugins via vim-plug, in vim command line mode of vimrc
, input PlugInstall
.
3. My zsh and zsh customization
In this part, I’ll simply introduce features of my customization and some frequently used operations. Check .zshrc
and .vim/vimrc
for more information.
3.1 zsh
Double hit Esc
to add sudo
to current command.
Alias like:
alias la='ls -a'
alias ll='ls -al'
alias gc='git clone'
alias ga='git add -A'
alias gcm='git commit -m'
alias gp='git push'
Use j <visited dir>
to jump to visited dir from anywhere.
3.2 vim
I adjust my vim config from theniceboy/.vim. Go and check his if you are a colemak
keyboard layout user.
My vim leader key is Space
.
Some key maps:
" Save & quit
map Q :q<CR>
map W :w<CR>
map <LEADER>q :q!<CR>
map <LEADER>w :w !sudo tee %<CR>
" Search
map <LEADER><CR> :nohlsearch<CR>
noremap = nzz
noremap - Nzz
" Cursor Movement
noremap J 5j
noremap K 5k
noremap H 5b
noremap L 5w
noremap <C-h> 0
noremap <C-l> $
続きを読む…