Wednesday, 19 August 2009
Useful ZSH Commands for Vim
(When I used bash, I wrote small scripts to achieve the following)
We frequently re-edit the most recent files, I have aliases/scripts for many of following as they are a bit clunky to type.
vi *(.om[1]) # vi newest file
vi -p *(.om[1,3]) # open 3 newest files in tabs (gvim)
vi *(m0) # re-edit all files changed today!
ls *(^m0) # files NOT modified today
ls -l *(m4) # list files modified exactly 4 days ago
vi **/main.php # where ever it is in hierarchy
ls (x*~x[3-5]) # list files x* except x3 to x5
vi !$ # vi last parameter
vi !-2:2 # second parameter of second but last command
vi !$:r.php # vi last parameter but change extension to .php
^mian^main # modify previous command (good for correcting typos)
^php^cfm # modify previous command replace php by cfm
more zsh tips and tricks here
We frequently re-edit the most recent files, I have aliases/scripts for many of following as they are a bit clunky to type.
vi *(.om[1]) # vi newest file
vi -p *(.om[1,3]) # open 3 newest files in tabs (gvim)
vi *(m0) # re-edit all files changed today!
ls *(^m0) # files NOT modified today
ls -l *(m4) # list files modified exactly 4 days ago
vi **/main.php # where ever it is in hierarchy
ls (x*~x[3-5]) # list files x* except x3 to x5
vi !$ # vi last parameter
vi !-2:2 # second parameter of second but last command
vi !$:r.php # vi last parameter but change extension to .php
^mian^main # modify previous command (good for correcting typos)
^php^cfm # modify previous command replace php by cfm
more zsh tips and tricks here
Sunday, 2 August 2009
Clean up a Mucky Text File with a VIM function
We are often required to clean up a text file usually from kind of export to text from a database , Word file etc. These text files can be full of superfluous white space, non-asciis, control-M etc
Insert the following function into your .vimrc or load directly into the file you editing. Adapt it as necessary .
Execute with
: call Clean()
function! Clean()
" Clean up a text file
" delete pesky (MSDOS) control-M 's
exe ':%s/\r//ge'
" delete pesky non-asciis
exe ':%s/[\x00-\x1f\x80-\xff]/ /eg '
" compress multiple spaces
exe ':%s/\s\s\+/ /eg'
" delete end of line spaces
exe ':%s/\s\+$//e'
" compress multiple blank lines
exe ':silent! v/./,/./-j'
endfunction
Insert the following function into your .vimrc or load directly into the file you editing. Adapt it as necessary .
Execute with
: call Clean()
function! Clean()
" Clean up a text file
" delete pesky (MSDOS) control-M 's
exe ':%s/\r//ge'
" delete pesky non-asciis
exe ':%s/[\x00-\x1f\x80-\xff]/ /eg '
" compress multiple spaces
exe ':%s/\s\s\+/ /eg'
" delete end of line spaces
exe ':%s/\s\+$//e'
" compress multiple blank lines
exe ':silent! v/./,/./-j'
endfunction
Labels: gvim, text files, vim
Subscribe to Posts [Atom]