I'm trying to move over to vim, and am having some problems porting
some of my function keys over.
I have a macro set up on my F2 key in my other editor that does the
following:
changes the filetype to unix (changes line endings from whatever to
unix)
removes trailing whitespace
converts leading whitespace to tabs based on tabstop length
saves the file
I have figured out how to do all these things by themselves, but
cannot for the life of me figure out how to bring them all together
into a single keystroke (or even better, automagically upon file save)
in my vimrc file.
I tried creating a function that switches the line endings and
performs the whitespace edits, but I'm not sure if I made the function
correctly:
if !exists("CleanupFile")
function! CleanupFile()
" replace all other line ending with unix
execute "%s/\r\n/\r/g"
execute "%s/\r/\r/g"
" replace all leading spaces with tabs
execute "%s/\(\t*\) /\1\t/g"
execute "%s/\\t \{1,3}\t/\t\t/g"
" remove all trailing whitespace
execute "%s/\s$//g"
endfunction
endif
I am also not sure if I am calling that function properly:
" autoload my funcitons
if !exists("autocommands_loaded")
let autocommands_loaded=1
autocmd BufWrite,BufWritePre,BufWriteCmd,FileWritePre,FileWriteCmd
call CleanupFile()
endif
and when that didn't work, I tried to map a key to perform my searches
and save:
map <F2> :%s/\r\n/\r/g | :%s/\r/\r/g | :%s/\(\t*\) /\1\t/g | :%s/\
\t \{1,3}\t/\t\t/g | :%s/\s$//g | :w<CR>
and that doesn't work either.
I'm fairly certain I've made some pretty simple and stupid mistakes
above, but after hours of searching I can't seem to come up with
anything useful to help me.
Either method as a solution would be fine, but I'd also like to ask
what (if any) mistakes I made in my above vimrc file so I can avoid
them in the future.
thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---