"Vim"의 두 판 사이의 차이
ph
잔글 (→vim mode in tmux) |
|||
(사용자 2명의 중간 판 26개는 보이지 않습니다) | |||
1번째 줄: | 1번째 줄: | ||
− | + | ==disable focus-in, focus-out event in terminal== | |
− | + | printf "\e[?1004l" | |
− | + | [https://apple.stackexchange.com/a/220625/87063] [https://superuser.com/q/931873/108174] | |
− | + | ||
− | + | ==paste large text to a file== | |
− | + | Do not use vim. Use <code>here document</code>.[https://stackoverflow.com/a/2954835/766330] | |
− | + | cat << END > targetfile | |
− | function! GnuIndent() | + | ... |
+ | > END | ||
+ | |||
+ | ==Insert line numbers== | ||
+ | :%s/^/\=printf('%-4d', line('.’)) | ||
+ | <code>\=</code> is the result of evaluating the following expression<br> | ||
+ | <code>%-4d</code> is a left-aligned decimal number(<code>%4d</code> is right-aligned) | ||
+ | |||
+ | or | ||
+ | |||
+ | :%!nl -ba | ||
+ | |||
+ | ==Make Vim show ALL white spaces as a character== | ||
+ | :set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣ | ||
+ | :set list [https://stackoverflow.com/a/29787362/766330] | ||
+ | 아래와 같이 하면 탭등 구분은 안되지만 일단 공백이 다른 색으로 보임. | ||
+ | :syntax on | ||
+ | :set syntax=whitespace [https://stackoverflow.com/a/19012475/766330] | ||
+ | |||
+ | ==autocomplete에 dash포함== | ||
+ | :set lisp [http://stackoverflow.com/a/10789559/766330] | ||
+ | 다른 방법으로는, | ||
+ | :set iskeyword+=\- [http://stackoverflow.com/a/27070192/766330] | ||
+ | 이용 | ||
+ | |||
+ | ==Auto completion in command line mode== | ||
+ | :help wildmode | ||
+ | I am using | ||
+ | :set wildemode=list:longest | ||
+ | |||
+ | ==Display line numbers== | ||
+ | :highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE | ||
+ | [http://vim.wikia.com/wiki/Display_line_numbers] | ||
+ | |||
+ | |||
+ | |||
+ | ==이미 읽은 파일의 인코딩 변경== | ||
+ | :e ++enc=euc-kr | ||
+ | [http://kldp.org/node/32987] | ||
+ | |||
+ | |||
+ | |||
+ | ==tab으로 편집== | ||
+ | :help tabpage | ||
+ | :help tabe | ||
+ | ref. {{c|:Te}} | ||
+ | |||
+ | |||
+ | |||
+ | ==temporary {{c|ic}} when searching== | ||
+ | insert '\c'(or '\C') at the end. (eg: {{c|/example\c}} will match with 'Example'). | ||
+ | <br>ref. {{c|:help pattern}} | ||
+ | |||
+ | |||
+ | |||
+ | ==Gnu indent== | ||
+ | function! GnuIndent() | ||
setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1,//0 | setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1,//0 | ||
setlocal shiftwidth=2 | setlocal shiftwidth=2 | ||
setlocal tabstop=8 | setlocal tabstop=8 | ||
− | endfunction | + | endfunction |
− | au FileType c,cpp,php call GnuIndent() | + | au FileType c,cpp,php call GnuIndent() |
− | </ | + | |
+ | |||
+ | |||
+ | ==Copy using {{c|t}} command== | ||
+ | :81,91t.<enter> | ||
+ | Copy the current lines to your present cursor location. | ||
+ | [http://stackoverflow.com/a/27501745/766330] | ||
+ | |||
+ | ==Change tab(\t) to space== | ||
+ | :set expandtab | ||
+ | {{red|:retab}} | ||
+ | [http://vim.wikia.com/wiki/Converting_tabs_to_spaces] | ||
+ | |||
+ | ==Reverse all lines== | ||
+ | :g/^/m0 | ||
+ | <c>g</c>: reg match인 모든 곳에서 명령실행 | ||
+ | |||
+ | 혹은 다음과 같이 한다. | ||
+ | :%!tac | ||
+ | |||
+ | [http://vim.wikia.com/wiki/Reverse_all_lines] | ||
+ | |||
+ | ==non-greedy match== | ||
+ | .\{-} | ||
+ | [https://stackoverflow.com/a/1305957/766330] | ||
+ | |||
+ | ==Match except last parenthesis== | ||
+ | <nowiki>:%s/\(.\{-}\)\( \?([^)]*)\)\?$/[[\1]]\2/</nowiki> | ||
+ | ‘optional한 마지막 괄호’만 빼고 다른 모든것을 매치하고 싶었는데, stackoverflow에 물어보니 ‘닫는괄호를 제외한 나머지’와 match하는게 핵심 아이디어 였음. 즉, 괄호 match에 다음을 쓰는 것. | ||
+ | ([^)]*)[https://stackoverflow.com/a/45581831/766330] | ||
+ | <c>magic</c>을 이용한 방법[https://stackoverflow.com/a/45600892/766330]이 더 깔끔해보이긴 함 | ||
+ | /\v(^\w+(\s\w+)?) | ||
+ | <nowiki>:%s,,[[\1]],g</nowiki> | ||
+ | |||
+ | ==Regexp with <c>magic</c>== | ||
+ | \v | ||
+ | [http://vimdoc.sourceforge.net/htmldoc/pattern.html#/magic vimdoc]참고. | ||
+ | 훨씬 깔끔해진다. | ||
+ | |||
+ | ==vim mode in tmux== | ||
+ | set-window-option -g mode-keys vi | ||
+ | |||
+ | 그냥 enter로 빠져나오고 space로 selection시작. 움직임은 vim과 동일 | ||
+ | [https://sanctum.geek.nz/arabesque/vi-mode-in-tmux/ ref] |
2020년 3월 3일 (화) 18:22 기준 최신판
목차
- 1 disable focus-in, focus-out event in terminal
- 2 paste large text to a file
- 3 Insert line numbers
- 4 Make Vim show ALL white spaces as a character
- 5 autocomplete에 dash포함
- 6 Auto completion in command line mode
- 7 Display line numbers
- 8 이미 읽은 파일의 인코딩 변경
- 9 tab으로 편집
- 10 temporary ic when searching
- 11 Gnu indent
- 12 Copy using t command
- 13 Change tab(\t) to space
- 14 Reverse all lines
- 15 non-greedy match
- 16 Match except last parenthesis
- 17 Regexp with magic
- 18 vim mode in tmux
disable focus-in, focus-out event in terminal
printf "\e[?1004l"
paste large text to a file
Do not use vim. Use here document
.[3]
cat << END > targetfile ... > END
Insert line numbers
:%s/^/\=printf('%-4d', line('.’))
\=
is the result of evaluating the following expression
%-4d
is a left-aligned decimal number(%4d
is right-aligned)
or
:%!nl -ba
Make Vim show ALL white spaces as a character
:set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣ :set list [4]
아래와 같이 하면 탭등 구분은 안되지만 일단 공백이 다른 색으로 보임.
:syntax on :set syntax=whitespace [5]
autocomplete에 dash포함
:set lisp [6]
다른 방법으로는,
:set iskeyword+=\- [7]
이용
Auto completion in command line mode
:help wildmode
I am using
:set wildemode=list:longest
Display line numbers
:highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
이미 읽은 파일의 인코딩 변경
:e ++enc=euc-kr
tab으로 편집
:help tabpage :help tabe
ref. :Te
temporary ic when searching
insert '\c'(or '\C') at the end. (eg: /example\c will match with 'Example').
ref. :help pattern
Gnu indent
function! GnuIndent() setlocal cinoptions=>4,n-2,{2,^-2,:2,=2,g0,h2,p5,t0,+2,(0,u0,w1,m1,//0 setlocal shiftwidth=2 setlocal tabstop=8 endfunction au FileType c,cpp,php call GnuIndent()
Copy using t command
:81,91t.<enter>
Copy the current lines to your present cursor location. [10]
Change tab(\t) to space
:set expandtab
:retab
Reverse all lines
:g/^/m0
g: reg match인 모든 곳에서 명령실행
혹은 다음과 같이 한다.
:%!tac
non-greedy match
.\{-}
Match except last parenthesis
:%s/\(.\{-}\)\( \?([^)]*)\)\?$/[[\1]]\2/
‘optional한 마지막 괄호’만 빼고 다른 모든것을 매치하고 싶었는데, stackoverflow에 물어보니 ‘닫는괄호를 제외한 나머지’와 match하는게 핵심 아이디어 였음. 즉, 괄호 match에 다음을 쓰는 것.
([^)]*)[14]
magic을 이용한 방법[15]이 더 깔끔해보이긴 함
/\v(^\w+(\s\w+)?) :%s,,[[\1]],g
Regexp with magic
\v
vimdoc참고. 훨씬 깔끔해진다.
vim mode in tmux
set-window-option -g mode-keys vi
그냥 enter로 빠져나오고 space로 selection시작. 움직임은 vim과 동일 ref