Clipboard fix + Search selection + Search cword fix

* Now use the correct clipboard register depending on whether unnamedplus is available
* Added word boundaries to replace cword function from normal mode
* Added replace selection mapping in visual mode
* Copied VisualSelection() function from stack overflow (source link in code)
This commit is contained in:
Talia 2017-10-31 13:52:03 +01:00
parent f627f0ca1a
commit ebf84e7d34

22
vimrc
View file

@ -81,7 +81,11 @@ set cmdheight=1
set timeoutlen=1200
" Clipboard and Copy/Paste things
set clipboard=unnamed " Allow copying to and from OS clipboard
if has('unnamedplus') " Allow copying to and from OS clipboard
set clipboard=unnamedplus
else
set clipboard=unnamed
end
noremap <leader>d "_d
noremap <leader>d "_d
noremap x "_x
@ -121,6 +125,19 @@ function! QuickfixAddLine(filename, lnum, text)
call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a')
endfunction
" https://stackoverflow.com/a/6271254/4984564
function! VisualSelection()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ''
endif
let lines[-1] = lines[-1][: column_end - 2]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
" === GENERAL COMMANDS ===
command! L lopen | set number | set norelativenumber
command! LAddLine call LocationAddLine(expand("%"), line("."), getline("."))
@ -168,7 +185,8 @@ nnoremap <C-d> :copy .<CR>
nnoremap dx 0"_d$
nnoremap dcx 0d$
nnoremap <leader>: :let @* = @:<CR>
nnoremap <expr> <S-r> ":%s/".expand("<cword>")."/"
nnoremap <expr> <S-r> ":%s/\\<".expand("<cword>")."\\>/"
vnoremap <expr> <S-r> "\<C-c>:redraw<CR>:%s/".VisualSelection()."/"
" Tabs vs. Spaces
nnoremap <C-tab> :setl expandtab!<CR>:set expandtab?<CR>