0
A
답변
0
당신은 inoremap
이 필요합니다입니다 ;
(현재 버퍼로 제한 - :h :map-<buffer>
). 매핑에서 하나의 =
부호 (정확히?)에 대한 현재 줄을 구문 분석해야합니다. 다시 포맷하고 커서를 뒤로 이동하십시오.
함정 :
- 하는 매핑이 재실행해야 하는가? 이 경우
<c-g>U<left>
및<right>
커서를 필요한만큼 여러 번 움직여야합니다. 그렇지 않으면getline()
+substitute()
+setline()
의 평범한 사용이 효과적 일 것입니다. (사실 아주 간단합니다) ->:call setline('.', substitute(getline('.'), '\s*[<>!=]\?=\s*', ' = ', 'g'))
. - UTF-8 문자가
auto head = "tête";, you won't be able to use
strlen()`처럼 표시 될 수있는 경우.
clang 형식은 이미 이런 종류의 작업을 수행 할 수 있습니다.하지만 다시 작성 가능한 시퀀스를 생성하는 것을 허용하지는 않습니다.
" rtp/ftplugin/c/c_reformat_on_semincolon.vim
" The reodable version.
function! s:semicolon() abort
" let suppose the ';' is at the end of the line...
" and that there aren't multiple instructions of the same line
let res = ''
let line = getline('.')
let missing_before = match(line, '\V\S=')
let c = col('.') - 1
if missing_before >= 0
" prefer lh-vim-lib lh#encoding#strlen(line[missing_before : c])
let offset = c - missing_before " +/- 1 ?
let res .= repeat("\<c-g>U\<right>", offset)
\ . ' '
if line =~ '\V=\S'
let res .= "\<c-g>U\<left> "
let offset -= 1 " or 2 ?
endif
" let offset +/-= 1 ??
else
let offset = c - missing_after" +/- 1 ?
let res .= repeat("\<c-g>U\<right>", offset)
\ . ' '
endif
let res .= repeat("\<c-g>U\<left> ", offset)
return res
endfunction
inoremap <buffer> ; <c-r>=<sid>semicolon()<cr>
이 코드는 완전히 테스트되지 않았습니다. 오프셋을 조정해야하며 논리를 수정할 수도 있습니다.