Introduction#
GitHub shows basic thigns with vim
- vimrc without plugin
- vimrc with basic plugins
- vim basic commands
- nvim and lua also available here
This is my vim environment
Basic Vimrc#
" tab widthset tabstop=2set shiftwidth=2set softtabstop=2set expandtabset cindentset autoindentset smartindentset mouse=aset hlsearchset showcmdset titleset expandtabset incsearch" line numberset numberhi CursorLineNr cterm=None" highlight current lineset cursorlinehi CursorLine cterm=NONE ctermbg=23 guibg=Grey40" change cursor between modeslet &t_SI = "\e[6 q"let &t_EI = "\e[2 q"" netrw wsizelet g:netrw_liststyle=3let g:netrw_keepdir=0let g:netrw_winsize=30map <C-a> : Lexplore<CR>" per default, netrw leaves unmodified buffers open. This autocommand" deletes netrw's buffer once it's hidden (using ':q;, for example)autocmd FileType netrw setl bufhidden=delete " or use :qa!" these next three lines are for the fuzzy search:set nocompatible "Limit search to your projectset path+=** "Search all subdirectories and recursivelyset wildmenu "Shows multiple matches on one line" highlight syntaxset re=0syntax on" colorschemecolorscheme desert
Add Plugins#
first we need to install vim plug
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
use vimplug to install some plugins
call plug#begin()Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }Plug 'junegunn/fzf.vim'Plug 'prettier/vim-prettier', { 'do': 'yarn install --frozen-lockfile --production' }Plug 'neoclide/coc.nvim', {'branch': 'release'}Plug 'jiangmiao/auto-pairs'Plug 'rakr/vim-one'Plug 'psf/black', {'branch':'stable'}Plug 'sbdchd/neoformat'Plug 'navarasu/onedark.nvim'call plug#end()
Simple Theme#
colorscheme and modification
let g:airline_theme='one'colorscheme oneset background=dark:highlight Normal ctermbg=236:highlight clear LineNr:highlight clear SignColumn:highlight clear CursorLineNr:highlight clear VertSplit:highlight StatusLine cterm=reverse term=reverse ctermfg=59
paste from clipboard inside tmux
if &term =~ "screen"let &t_BE = "\e[?2004h"let &t_BD = "\e[?2004l"exec "set t_PS=\e[200~"exec "set t_PE=\e[201~"endif
modify cursorline
cursorlineset numberhi CursorLineNr cterm=Noneset cursorlinehi CursorLine cterm=None ctermbg=238 guibg=Grey40let &t_SI = "\e[6 q"let &t_EI = "\e[2 q"set ttimeoutset ttimeoutlen=1set ttyfast
OneDark Theme#
First, install onedark theme using vimplug
" Using Vim-PlugPlug 'navarasu/onedark.nvim'
Update the ~/.vimrc
let g:onedark_config = {\ 'style': 'deep',\ 'toggle_style_key': '<leader>ts',\ 'ending_tildes': v:true,\ 'diagnostics': {\ 'darker': v:false,\ 'background': v:false,\ },\ }colorscheme onedark
Second copy the theme into vim manually
https://github.com/joshdick/onedark.vimcopy -r onedark.vim/colors/ ~/.vim/colors/copy -r autoload/onedark.vim ~/.vim/autoload
Coc-Vim#
coc highlight
:highlight CocHighlightText ctermfg='white':highlight CocFloating ctermbg='white' ctermfg='black':highlight CocMenuSel ctermbg=7:highlight Visual ctermbg=59let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.5, 'yoffset': 1}}
coc install language server
:CocInstall coc-pyright
configure fix on save prettier
:CocConfig
and add to the coc-setting.json
{"coc.preferences.formatOnSaveFiletypes": ["css","markdown","typescript","javascript","json","python"],"python.pythonPath": "/usr/bin/python3"}
Basic Vim#
create a new file with netrw
%
create a new file with vim
:edit newfile
mark a target directory
mt
mark a file
mf
move the marked file
mm mc
find files in vime then tab to select the matches
find src/filename
setpath before find a file
set nocompatible "Limit search to your projectset path+=** "Search all subdirectories and recursivelyset wildmenu "Shows multiple matches on one line
find files with fuzzy finder
:Files
window split
<C-w> v # split vertically<C-w> s # spit horizontally<C-w> h # move to right<C-w> l # move to the left<C-w> c # close current window
tab navigation
:tabedit filename-1:tabedit filename-2
navigate between tab files
gt #: nextGt #: previous
search and replace words
Basic Commands#
hide and show status bar
:set -g status off:set -g status on
new session
:new-session
kill session
:kill-session(#session number)
vim show path of an openning file
1 and ctr+g
Tips#
- 256 color cheat sheet link
- use the command :hi to find the colors you want
- regular expression to find and replace empty lines
^\s*$
cursor and cursorline setting
set cursorlinehi CursorLineNr cterm=NONEhi CursorLine cterm=None ctermbg=254hi Search ctermbg=Black ctermfg=White
Mount Volume EC2#
list device
lsblk
look at the volume of ec2 in aws console as below picture
run this command to check an file system already exist on the device and parition or not
sudo file -s /dev/sdf1
if an file system already exist, let create a new directory
sudo mkdir /data
then mount
sudo mount /dev/sdf1 /data
configure auto mount on startup
sudo cp /etc/fstab /etc/fstab.orig
check the UUID
sudo blkid
take note the UUID
f33e7d3b-6786-4f40-875a-90f0f7e6b9a8
update the /etc/fstab file by appending this line to the end
UUID=aebf131c-6957-451e-8d34-ec978d9581ae /data xfs defaults,nofail 0 2
verify that mount working
sudo umount /datasudo mount -a
User Data#
#!/bin/bashcd ~wget -O ~/.vimrc https://raw.githubusercontent.com/cdk-entest/basic-vim/main/.vimrcwget https://github.com/cdk-entest/flask-tailwind-polly/archive/refs/heads/master.zipunzip master.zipcd flask-tailwind-polly-masterpython3 -m ensurepip --upgradepython3 -m pip install -r requirements.txtcd appexport BUCKET_NAME="vpb-polly-demo-10072023"export REGION="ap-southeast-1"python3 -m app
Modify Volume#
- Grow parition
- Extend file system
First grow parition
sudo growpart /dev/nvme0n1 1
Then extend file system and the command depends on type of file system
sudo resize2fs /dev/nvme0n1p1
Basic Command#
For web development, we can run a webserver (nextjs) on ec2 and use portforwarding so local machine can access i
ssh -L 3000:localhost:3000 ec2-user@cloud9