Minor improvements + ]p and [p
* Improved visual selection * Improved standard ]p and [p * Fixed ruby autoindentation
This commit is contained in:
parent
18335cc569
commit
c34d46cd2f
1 changed files with 36 additions and 14 deletions
50
vimrc
50
vimrc
|
@ -101,7 +101,7 @@ endfunc
|
||||||
|
|
||||||
function! s:mld_helper(list, pattern)
|
function! s:mld_helper(list, pattern)
|
||||||
" Helper function for MatchingLinesDict
|
" Helper function for MatchingLinesDict
|
||||||
call add(a:list, {'filename': expand("%"), 'lnum': line("."), 'col': match(getline("."), a:pattern)+1, 'text': matchstr(getline("."), a:pattern)})
|
call add(a:list, {'filename': expand("%"), 'lnum': line("."), 'col': match(getline("."), a:pattern)+1, 'text': matchstr(getline("."), a:pattern)})
|
||||||
endfunc
|
endfunc
|
||||||
function! MatchingLinesDict(pattern)
|
function! MatchingLinesDict(pattern)
|
||||||
let list = []
|
let list = []
|
||||||
|
@ -125,19 +125,32 @@ function! QuickfixAddLine(filename, lnum, text)
|
||||||
call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a')
|
call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" https://stackoverflow.com/a/6271254/4984564
|
" Original implementation: https://stackoverflow.com/a/6271254/4984564
|
||||||
function! VisualSelection()
|
function! VisualSelection()
|
||||||
let [line_start, column_start] = getpos("'<")[1:2]
|
if mode()=="v"
|
||||||
let [line_end, column_end] = getpos("'>")[1:2]
|
let [line_start, column_start] = getpos("v")[1:2]
|
||||||
let lines = getline(line_start, line_end)
|
let [line_end, column_end] = getpos(".")[1:2]
|
||||||
if len(lines) == 0
|
else
|
||||||
return ''
|
let [line_start, column_start] = getpos("'<")[1:2]
|
||||||
endif
|
let [line_end, column_end] = getpos("'>")[1:2]
|
||||||
let lines[-1] = lines[-1][: column_end - 2]
|
end
|
||||||
let lines[0] = lines[0][column_start - 1:]
|
if (line2byte(line_start)+column_start) > (line2byte(line_end)+column_end)
|
||||||
return join(lines, "\n")
|
let [line_start, column_start, line_end, column_end] =
|
||||||
|
\ [line_end, column_end, line_start, column_start]
|
||||||
|
end
|
||||||
|
let lines = getline(line_start, line_end)
|
||||||
|
if len(lines) == 0
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
|
let lines[-1] = lines[-1][: column_end - 1]
|
||||||
|
let lines[0] = lines[0][column_start - 1:]
|
||||||
|
return join(lines, "\n")
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! StringReverse(str)
|
||||||
|
return join(reverse(split(str, ".\\zs")), "")
|
||||||
|
endfunc
|
||||||
|
|
||||||
" === GENERAL COMMANDS ===
|
" === GENERAL COMMANDS ===
|
||||||
command! L lopen | set number | set norelativenumber
|
command! L lopen | set number | set norelativenumber
|
||||||
command! LAddLine call LocationAddLine(expand("%"), line("."), getline("."))
|
command! LAddLine call LocationAddLine(expand("%"), line("."), getline("."))
|
||||||
|
@ -186,7 +199,16 @@ nnoremap dx 0"_d$
|
||||||
nnoremap dcx 0d$
|
nnoremap dcx 0d$
|
||||||
nnoremap <leader>: :let @* = @:<CR>
|
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()."/"
|
vnoremap <expr> <S-r> ":<C-u>%s/".VisualSelection()."/"
|
||||||
|
" Put in new line with indentation
|
||||||
|
nnoremap ]p :let [content, type]=
|
||||||
|
\[getreg(v:register), getregtype(v:register)] \|
|
||||||
|
\call setreg(v:register, content, "V")<CR>]p
|
||||||
|
\:call setreg(v:register, content, type)<CR>
|
||||||
|
nnoremap [p :let [content, type]=
|
||||||
|
\[getreg(v:register), getregtype(v:register)] \|
|
||||||
|
\call setreg(v:register, content, "V")<CR>[p
|
||||||
|
\:call setreg(v:register, content, type)<CR>
|
||||||
|
|
||||||
" Tabs vs. Spaces
|
" Tabs vs. Spaces
|
||||||
nnoremap <C-tab> :setl expandtab!<CR>:set expandtab?<CR>
|
nnoremap <C-tab> :setl expandtab!<CR>:set expandtab?<CR>
|
||||||
|
@ -419,11 +441,11 @@ endfunction
|
||||||
|
|
||||||
augroup rbindent
|
augroup rbindent
|
||||||
autocmd!
|
autocmd!
|
||||||
au BufNewFile,BufRead *.rb :set noexpandtab :retab!
|
au BufNewFile,BufRead *.rb :set noexpandtab | :retab!
|
||||||
|
|
||||||
au BufWritePre *.rb :let ts = &tabstop | set expandtab | set tabstop=2 | retab | let &tabstop=ts
|
au BufWritePre *.rb :let ts = &tabstop | set expandtab | set tabstop=2 | retab | let &tabstop=ts
|
||||||
|
|
||||||
au BufWritepost *.rb :set noexpandtab :silent! :undo :normal <S-tab>
|
au BufWritepost *.rb :set noexpandtab | :silent! :undo | :normal <S-tab>
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
" --- Lua Stuff ---
|
" --- Lua Stuff ---
|
||||||
|
|
Loading…
Reference in a new issue