commit be1cc01fe38c9c25a50c49f1ecdcfffac6292a36 (patch)
parent 9ec50961684295721383fca50bf70aa0ec7a5ba6
Author: Alexander Karle <akarle@umass.edu>
Date: Tue, 6 Mar 2018 19:02:33 -0500
Adding first function to vimrc, remove trailing whitespace
Diffstat:
4 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/setup.sh b/setup.sh
@@ -14,6 +14,7 @@ ln -s $GITVIM/theme.vim $VIMHOME/theme.vim
ln -s $GITVIM/plugins.vim $VIMHOME/plugins.vim
ln -s $GITVIM/pluginsettings.vim $VIMHOME/pluginsettings.vim
ln -s $GITVIM/keys.vim $VIMHOME/keys.vim
+ln -s $GITVIM/functions.vim $VIMHOME/functions.vim
# filetype plugins
FTPLUGDIR=$VIMHOME/ftplugin
@@ -22,6 +23,7 @@ if [ ! -d $FTPLUGDIR ]; then
fi
ln -s $GITVIM/ftplugin/tex.vim $FTPLUGDIR/tex.vim
+ln -s $GITVIM/ftplugin/python.vim $FTPLUGDIR/python.vim
# Link tmux conf
ln -s ~/git/dotfiles/tmux.conf ~/.tmux.conf
diff --git a/vim/functions.vim b/vim/functions.vim
@@ -0,0 +1,13 @@
+" A function to execute a command and return to the old position
+" CREDIT: http://vimcasts.org/episodes/tidying-whitespace/
+function! CMDPreserve(command)
+ " Preparation: save last search, and cursor position.
+ let _s=@/
+ let l = line(".")
+ let c = col(".")
+ " Do the business:
+ execute a:command
+ " Clean up: restore previous search history, and cursor position
+ let @/=_s
+ call cursor(l, c)
+endfunction
diff --git a/vim/keys.vim b/vim/keys.vim
@@ -15,3 +15,6 @@ nnoremap <C-p> :GFiles<CR>
" HTML autoclose tag
iabbrev </ </<C-X><C-O>
+
+" Elim Whitespace (through regexp)
+nmap _$ :call CMDPreserve("%s/\\s\\+$//e")<CR>
diff --git a/vim/vimrc b/vim/vimrc
@@ -48,4 +48,5 @@ if filereadable(expand("~/.vim/autoload/plug.vim"))
source ~/.vim/pluginsettings.vim
endif
source ~/.vim/theme.vim
+source ~/.vim/functions.vim
source ~/.vim/keys.vim