Wednesday, 2 January 2013
Wednesday, 28 November 2012
More VIM amazingness
So I probably missed this in the few tutorials I looked at on vim.
But... oh... my... god...
You can pass your current file to a tool (like bash, or mysql) like this:
Or you can do this to just pipe in the "lines 7 to 9" or the current line to bash:
Or pipe in selected text to mysql:
Paraphrasing those clever folk at stackoverflow you can capture and run macro:
this is also very cool:
http://askubuntu.com/questions/23517/how-to-execute-a-shell-command-in-vim-and-have-the-result-printed-below
These things in your .vimrc are gold:
syntax on
Clearing the highlighting from your last search can be useful:
*/filepat filenames in current directory
**/filepat filenames in current directory or below
*//pattern vimgrep in current directory
**//pattern vimgrep in the current directory or below
But... oh... my... god...
Passing vim contents to the shell (ie bash)
You can pass your current file to a tool (like bash, or mysql) like this:
w | ! . %or
w | ! mysql %
Or you can do this to just pipe in the "lines 7 to 9" or the current line to bash:
7,9:w ! bash
.w ! bash
Or pipe in selected text to mysql:
'<,'>:w ! mysql
Misc
Paraphrasing those clever folk at stackoverflow you can capture and run macro:
Perform desired editing interactively with
vim -w log.vim file1.txt
and then repeat it on other files:
for f in file*.txt; do vim -s log.vim $f; done
or alternatively:
for f in file*.txt; do vim -c '1,55d|25,35s/^/\/\/ /|w! '"${f}_new"'|q!' $f
this is also very cool:
http://askubuntu.com/questions/23517/how-to-execute-a-shell-command-in-vim-and-have-the-result-printed-below
These things in your .vimrc are gold:
syntax on
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
\ "\<lt>C-n>" :
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
Clearing the highlighting from your last search can be useful:
:let @/ = ""
Opening and finding files
Obviously :Ex, :Tex: and :Vex are good, and to those you can look for patterns in the:*/filepat filenames in current directory
**/filepat filenames in current directory or below
*//pattern vimgrep in current directory
**//pattern vimgrep in the current directory or below
Wednesday, 14 November 2012
Installing drush
So we've all established that Drush is the bee's knees for running drupal installations. Right?
So tonight I had to install it on a server where I have limited rights.
This was the process (based on perusing the README.txt):
The bit I like best is greping the .bashrc so I only add the require line once.
I also had to track down php-cli that drush was complaining about. So I just used locate then made a link:
So tonight I had to install it on a server where I have limited rights.
This was the process (based on perusing the README.txt):
# install drushdv=7.x-5.8ptd=~/bin/drushfiles/$dvmkdir -p $ptdtar -xf ~/drush-$dv.tar.gz -C $ptdchmod u+x $ptd/drush/drushln -sf $ptd/drush/drush ~/bin/drushln -sf $ptd/drush/examples/example.bashrc ~/bin/drush.bashrc# put drush.bashrc into .bashrcif grep -Fq "drush.bashrc" .bashrc
then
echo "you already have drush.bashrc in your .bashrc, so no action taken"elseecho "drush.bashrc added to you .bashrc"echo "source ~/bin/drush.bashrc" >> .bashrcfi# tidy up
rm ~/drush-$dv.tar.gz
The bit I like best is greping the .bashrc so I only add the require line once.
I also had to track down php-cli that drush was complaining about. So I just used locate then made a link:
locate php-cli
ln -sf /hsphere/shared/php53/bin/php-cli bin/php-cli
Saturday, 15 September 2012
Vim scripting the hard way
You have to respect someone who writes a book titled this!
http://learnvimscriptthehardway.stevelosh.com/
There is this little pearl in the front page (I tend to loose my .vimrc!!!):
http://learnvimscriptthehardway.stevelosh.com/
There is this little pearl in the front page (I tend to loose my .vimrc!!!):
"To easily find the location and name of the file on any operating system, run
:echo $MYVIMRC"
So I'll read on...Tuesday, 4 September 2012
little things make all the difference
<esc> v takes you straight to your favourite editor in bash... ah bliss... no more wrestling with crippled command line editing for me!!
why did no-one tell me!!
why did no-one tell me!!
Wednesday, 29 August 2012
Drush (aka drupal from bash)
Drush is cool...
# put a link to drush in your bin
ln /usr/local/bin/drush/drush bin/drush
mkdir ~/.drush
touch ~/.drush/aliases.drushrc.php
# pinch another users alias file to get you started:
cp /home/michaeldance/.drush/aliases.drushrc.php .drush/
# edit alias file:
vim ~/.drush/aliases.drushrc.php
# see your aliases
drush sa
# chose an alias
drush use @prod
# check your good to go:
drush st
#drop into an sql shell
drush @ubox sqlc
# check the watchdog
drush watchdog-show
# clear the menu cache
drush @prod cc
# list the packages (eg modules/themes)
drush @prod pml
# filtering them with grep
drush @prod pml | grep agc
# review the watchdog-list
drush @ubox watchdog-list
#fire up the cron
drush @ubox cron
# list your packages
drush @ubox pml
# disable a package
drush @ubox dis activitystream_feed
Saturday, 25 August 2012
Coping with funny file names
I thought that spaces and other odd things in file names was just an irritating Windows thing, but no, it appears the contagion is now part of linux too.
Both the Swiss-army-knife commands find and xargs will cope tho, with just a little tweaking:
Slightly related to this is the challenge of removing files with odd file names. A good tip is the -i flag on rm:
This will check with you for each file starting with c.
Both the Swiss-army-knife commands find and xargs will cope tho, with just a little tweaking:
find /myfolder -type f -size +1M -print0 | xargs -0 ls -lFind, unsurprisingly finds a list of files matching a criteria. Xargs then does something with them. In this case we're just listing files bigger than 1 meg.
Slightly related to this is the challenge of removing files with odd file names. A good tip is the -i flag on rm:
rm -i c*
This will check with you for each file starting with c.
Subscribe to:
Posts (Atom)