mirror of
https://github.com/gryf/.vim.git
synced 2025-12-17 11:30:29 +01:00
Added stripping whitespace for visually selected range
This commit is contained in:
13
vimrc
13
vimrc
@@ -316,7 +316,8 @@ map <S-F9> :QFix<CR>
|
|||||||
map <S-F11> :LWin<CR>
|
map <S-F11> :LWin<CR>
|
||||||
|
|
||||||
"remove trailing whitespaces
|
"remove trailing whitespaces
|
||||||
nnoremap <leader>e :StripTrailingWhitespaces!<CR>
|
nnoremap <leader>e :call <SID>StripTrailingWhitespaces(1, 'n')<CR>
|
||||||
|
vnoremap <silent> <Leader>e :<C-U>call <SID>StripTrailingWhitespaces(1, 'v')<CR>
|
||||||
|
|
||||||
" copy current buffer filename (full path)
|
" copy current buffer filename (full path)
|
||||||
nmap ,cn :silent call <SID>CopyFileName(1)<CR>
|
nmap ,cn :silent call <SID>CopyFileName(1)<CR>
|
||||||
@@ -371,7 +372,7 @@ function <SID>Make()
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Remove trailing whitespace
|
" Remove trailing whitespace
|
||||||
function <SID>StripTrailingWhitespaces(force)
|
function <SID>StripTrailingWhitespaces(force, mode) range
|
||||||
if a:force != 1 && g:stripTrailingWhitespace == 0
|
if a:force != 1 && g:stripTrailingWhitespace == 0
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
@@ -382,13 +383,17 @@ function <SID>StripTrailingWhitespaces(force)
|
|||||||
let l = line(".")
|
let l = line(".")
|
||||||
let c = col(".")
|
let c = col(".")
|
||||||
" Do the business:
|
" Do the business:
|
||||||
%s/\s\+$//e
|
if a:mode == 'v'
|
||||||
|
'<,'>s/\s\+$//e
|
||||||
|
else
|
||||||
|
%s/\s\+$//e
|
||||||
|
endif
|
||||||
" Clean up: restore previous search history, and cursor position
|
" Clean up: restore previous search history, and cursor position
|
||||||
let @/=_s
|
let @/=_s
|
||||||
call cursor(l, c)
|
call cursor(l, c)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
command -bang StripTrailingWhitespaces call <SID>StripTrailingWhitespaces(<bang>0)
|
command -bang StripTrailingWhitespaces call <SID>StripTrailingWhitespaces(<bang>0, 'n')
|
||||||
|
|
||||||
function <SID>CopyFileName(full)
|
function <SID>CopyFileName(full)
|
||||||
if a:full
|
if a:full
|
||||||
|
|||||||
Reference in New Issue
Block a user