Variables
:let foo = "bar"
:echo foo
:let foo = 42
:echo 42vimscript는 동적 타입 언어라는 것을 볼 수 있다.
Options as variable
special syntax로 option을 set 할 수 있다. variable 앞에 & 기호를 써서 변수가
아니라 option이라고 명시해 줄 수 있다.
:set textwidth=80
:echo &textwidthboolean 옵션도 마찬가지. 1과 0이 반환되는 것을 볼 수 있다
:set nowrap
:echo &wrap
" display 0
:set wrap
:echo &wrap
" display 1위에서 변수를 지정하는 let 명령어를 사용해서도 option을 변경할 수 있다.
:let &textwidth = 100
:set textwidth?이런식으로 문법을 사용할 수 도 있다.
:let &textwidth = &textwidth + 10
:set textwidth?Local options
local option도 동일하게 사용 가능하다. 두 개의 파일을 열고 각각 다른 local option을 줘 보자.
:let &l:number = 1:let &l:number = 0첫 번 쨰 파일은 첫 줄이 1로, 두 번 째 파일은 0으로 시작되는 것을 볼 수 있다.
Registers as Variables
register도 변수로 사용할 수 있다. a register에 변수를 지정하고 사용해 보자.
:let @a = "hello!"이제 "ap (a register를 붙여넣기) 명령어를 실행시키면 hello!가 붙여넣어 지는 것을 볼 수 있따. 마찬가지로
echo 로 읽을 수도 있음.
:echo @aunnamed, search register도 동일하게 사용 가능하다.
특정 항목을 복사하거나, 검색한 후에 다음 명령어로 확인해보자.
:echo @"
:echo @/Exercises
- Go through your ~/.vimrc file and change some of the set and setlocal commands to their let forms. Remember that boolean options still need to be set to something.
set number
let &number = 1- Try setting a boolean option like wrap to something other than zero or one. What happens when you set it to a different number? What happens if you set it to a string?
let &number = 3
" 0이 아닌 숫자면 true로, string이면 E521: Number required: &number = 'test' 에러가 반환된다.Go back through your ~/.vimrc file and undo the changes. You should never use let if set will suffice -- it's harder to read.
Read :help registers and look over the list of registers you can read and write.
0 - 9
a - z, A - Z
": unnamed register-: small delete register#: Alternate buffer register=: expression register/: Last search registerThe selection and drop registers "*, "+ and "~
The black hole register "_
Three read-only registers ":, "., "%
'tools > vim' 카테고리의 다른 글
| Learn Vimscript The Hard Way - 20: Conditional (0) | 2020.03.27 |
|---|---|
| Learn Vimscript The Hard Way - 20. Variable Scoping (0) | 2020.03.25 |
| Learn vimscript the hard way: 18장 - Responsible Coding (0) | 2020.03.20 |
| learn vimscript the hard way - 17장. status line (0) | 2020.03.18 |
| vim 마크다운 프리뷰에서 grammarly 사용하기: use grammarly online editor with vim markdown-preview.nvim (0) | 2020.03.16 |