From be1cc01fe38c9c25a50c49f1ecdcfffac6292a36 Mon Sep 17 00:00:00 2001 From: Alexander Karle Date: Tue, 6 Mar 2018 19:02:33 -0500 Subject: [PATCH] Adding first function to vimrc, remove trailing whitespace --- setup.sh | 2 ++ vim/functions.vim | 13 +++++++++++++ vim/keys.vim | 3 +++ vim/vimrc | 1 + 4 files changed, 19 insertions(+) create mode 100644 vim/functions.vim diff --git a/setup.sh b/setup.sh index 2a3bd7b..1fa277e 100644 --- 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 new file mode 100644 index 0000000..cae07d8 --- /dev/null +++ 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 index 918cb03..cea7584 100644 --- a/vim/keys.vim +++ b/vim/keys.vim @@ -15,3 +15,6 @@ nnoremap :GFiles " HTML autoclose tag iabbrev + +" Elim Whitespace (through regexp) +nmap _$ :call CMDPreserve("%s/\\s\\+$//e") diff --git a/vim/vimrc b/vim/vimrc index 49e4558..62c1c79 100644 --- 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 -- libgit2 0.28.4