ste*_*her 1 ruby vim text replace
我有一句话:
contact.psu_code = row[:psu_code] unless row[:psu_code].blank?
Run Code Online (Sandbox Code Playgroud)
我想替换psu_code,比方说contact_disposition,像:
contact.contact_dispositon = row[:contact_disposition] unless row[:contact_disposition].blank?
Run Code Online (Sandbox Code Playgroud)
它只能在我所在的单行中替换,没有确认.我知道,%s/orig/sub但这很麻烦.
你是什么意思,这很麻烦?如果您想在一行上进行搜索和替换,则无需使用%.
:s/psu_code/contact_disposition/g
Run Code Online (Sandbox Code Playgroud)
如果没有g,Vim会在替换单个事件后停止.通过指定g,替换在整条线上完成.
如果您想要确认,c请在之后添加选项g.
这是一个方便的功能:
function! LineReplace()
let search = expand('<cword>')
call inputsave()
let replacement = input('')
call inputrestore()
call setline(line('.'), substitute(getline('.'), search, replacement, 'g'))
endfunction
nnoremap <leader>r :call LineReplace()<CR>
Run Code Online (Sandbox Code Playgroud)
我将其映射到<leader>r,但您可以轻松地将其更改为您想要的任何键映射.