Skip to content

Instantly share code, notes, and snippets.

@NSLog0
Last active May 16, 2018 15:47
Show Gist options
  • Save NSLog0/c6135a7d56ee069467f8b0b8caf1c945 to your computer and use it in GitHub Desktop.
Save NSLog0/c6135a7d56ee069467f8b0b8caf1c945 to your computer and use it in GitHub Desktop.
Vim tutorials
var commend_helper = {
':w': 'บันทึกไฟล์',
':wq': 'บันทึกและออก',
':q': 'ออกแบบปกติ',
':q!': 'ออกแบบไม่บันทึก',
Esc: 'ออกจากโหมด insert, virtual, normal',
':': 'เรียกใช้คำสั่ง Plugin หรือคำสั่ง Buildin'
};
var editing_help = {
u: 'undo (ctrl-z)',
'.': 'ทำคำสั่งล่าสุดซ้ำ (จุด)',
yy: 'คัดลอกทั่งบรรทัด',
p: 'วาง',
dd: 'ลบทั่งบรรทัด จริงๆ มันคือการทำ cut text',
x: 'ลบตัวที่ cursor ชี้อยู่',
>: 'เลือน Indent เข้า',
<: 'เลือน Indent ออก',
};
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
var editing = {
s: 'ลบอักษรที่ cursor ชี้อยู่ 1 ตัวและเข้า insert mode',
cc: 'ลบทั่งบรรทัดออกแล้วเข้า insert mode',
i: 'เข้า insert mode',
J: 'รวมบรรทัดล่างกับบนเข้าด้วยกัน หรือเรียกว่า join ไม่เข้า insert mode แต่ถือว่าอยู่ในการ edit ไฟล์',
a: 'เข้า insert mode และขยับ cursor ไป 1 ช่อง'
};
sudo apt-get -y install vim
call plug#begin()
Plug 'mattn/emmet-vim'
Plug 'pangloss/vim-javascript'
Plug 'vim-ruby/vim-ruby'
Plug 'mxw/vim-jsx'
Plug 'isruslan/vim-es6'
Plug 'cakebaker/scss-syntax.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'altercation/vim-colors-solarized'
Plug 'scrooloose/nerdtree', { 'on': ['NERDTreeToggle', 'NERDTreeFind'] }
Plug 'airblade/vim-gitgutter'
Plug 'jelera/vim-javascript-syntax'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'tpope/vim-commentary'
call plug#end()
var cursor = {
h: 'เลือนซ้าย',
j: 'เลือนลง',
k: 'เลือนขึ้น',
l: 'เลือนขวา (อักษรแอลเล็ก)',
w: 'เลือนเป็นคำหรือประโยค เริ่มจากอักษรตัวแรกของคำ',
e: 'เลือนเป็นคำหรือประโยค เริ่มจากอักษรตัวหลังของคำ',
b: 'เลือนกลับที่ละคำหรือประโยค',
0: 'เลือนไปยังจุดเริ่มต้นบรรทัด',
$: 'เลือนไปยังท้ายสุดของบรรทัด',
G: 'เลือนไปท้ายไฟล์',
gg: 'เลือนไปบนสุดของไฟล์',
o: 'เพิ่มบรรทัดด้านล่างและเข้ามโหมด insert',
O: 'เพิ่มบรรทัดขึ้นข้างบนและเข้ามโหมด insert'
};
1. $ > vim path/file or filename
2. $ > vim .
set encoding=utf-8 " file encode
" The advantage of having the status line displayed always is, you can see the current mode, file name, file status, ruler, etc.
set laststatus=2
" fix backspace notworking
set backspace=indent,eol,start
" display status line/colmun number at buttom
set ruler
" display line number
set number
" open highlight syntax
syntax on
" set term=builtin_ansi
" set term=xterm-256color
" colorscheme basic-dark
" colorscheme mayansmoke
" set background=dark
" set theme
colorscheme petrel
let s:comment_map = {
\ "c": '\/\/',
\ "cpp": '\/\/',
\ "go": '\/\/',
\ "java": '\/\/',
\ "javascript": '\/\/',
\ "lua": '--',
\ "scala": '\/\/',
\ "php": '\/\/',
\ "python": '#',
\ "ruby": '#',
\ "rust": '\/\/',
\ "sh": '#',
\ "desktop": '#',
\ "fstab": '#',
\ "conf": '#',
\ "profile": '#',
\ "bashrc": '#',
\ "bash_profile": '#',
\ "mail": '>',
\ "eml": '>',
\ "bat": 'REM',
\ "ahk": ';',
\ "vim": '"',
\ "tex": '%',
\ }
function! ToggleComment()
if has_key(s:comment_map, &filetype)
let comment_leader = s:comment_map[&filetype]
if getline('.') =~ "^\\s*" . comment_leader . " "
" Uncomment the line
execute "silent s/^\\(\\s*\\)" . comment_leader . " /\\1/"
else
if getline('.') =~ "^\\s*" . comment_leader
" Uncomment the line
execute "silent s/^\\(\\s*\\)" . comment_leader . "/\\1/"
else
" Comment the line
execute "silent s/^\\(\\s*\\)/\\1" . comment_leader . " /"
end
end
else
echo "No comment leader found for filetype"
end
endfunction
nnoremap <leader><Space> :call ToggleComment()<CR>
vnoremap <leader><Space> :call ToggleComment()<CR>
" coding indent setting
set tabstop=2 " change tab width
set shiftwidth=2 " affects what happens when you press >>, << or =
set softtabstop=2 " tell backspace gose back step or tab width
set expandtab " convert tab to space
" setup key with recursive
map <leader>w :w<CR>
map <leader>q :q<CR>
map j gg
map Q j
" setup key with non-recursive
noremap W j
" setup key for call plugin function
map <C-n> :NERDTreeToggle<CR>
" plugin setting
let g:airline_theme='luna'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
let g:airline_powerline_fonts = 1
visual_key: {
y: 'คัดลอก',
d: 'ลบทั่งบรรทัดออก มันคือการทำ cut text',
>: 'เลือน Indent เข้า',
<: 'เลือน Indent ออก',
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment