My vim notes

To open all files whose paths are stored in a file into multiple vim buffers:

cat list.txt | xargs vim
xargs vim < /tmp/a
To redirect the output from a command (ps) into vim for easy search and maybe saving it:
ps -ef | vim -
To combine vim and find to open all matched files:
vim `find . -name build.xml`
find . -name web.xml | xargs vim
find . -name web.xml -exec vim {} \; is different: it will find a match, vim it, and repeat, and only 1 buffer in any vim session.

Be careful with file names with spaces. These pipelined use of find and xargs will treat spaces as delimiter between args, and break one arg into two.

vim search & replace in a file(replace old with new in the whole file, CASE sensitive, asking for confirmation). When prompted for confirmation, press 'a' to confirm all ocurrences including and after the current one.
To replace all comma with a new line return: :s/,/\r/gp

To bookmark a location as bookmark a, type ma. To go to bookmark a, type 'a

To turn off syntax highlighting, run command ":sy off", or ":syn off", or ":syntax off", to turn on highlighting again ":sy on", or ":syn on", or ":syntax on". After typing ":sy", you can press TAB key for autocomplete, or press Ctrl-D to list all matching commands.

To turn off highlight after you are done with a search, run command ":nohl"

To turn on highight search, if it's not already on, run command ":set hls"

To save all changed files, run command ":wa"

To save all changed files and exit, run command ":xa"

":x" is the same as ":wq": save and exit

To close all files and exit, run command ":qa", but vim won't exit if there is unsaved changes.

To close all files and exit forcifully, run command ":q!".

To open a file and go the end of the file (to skip long copyright):
vim -c :$ pom.xml

To open a file (e.g., log file) in read-only mode and go to the end of file:
view -c :$ $JBOSS_HOME/standalone/log/server.log
vim -R -c :$ $JBOSS_HOME/standalone/log/server.log

The above commands are similar to tail -f, but easier to search and navigate inside vim.

To open a file with gvim or vim from Mac OS terminal, run
"open -a gvim build.xml"
If you configure Finder to always open *.xml files with gvim, directly run
"open build.xml"
You can still open them with the default TextEdit with
"open -a textedit build.xml"
To customize gvim window size (the default is too small), add the following lines to $HOME/.gvimrc on Mac/Linux/Solaris, or %HOMEPATH%\_gvimrc on Windows:
set lines=80 columns=120
To substitue the current character and stay in insertion mode, type s

To change to overwrite/replace mode (as opposed to insertion), shift-R (Uppercase R)

To undo the last undo: Ctrl-R

To search with case-insensitive option for this search only, /foo\c

To insert the current file name: Ctrl-R-Shift-% (useful when working on java and xml files to fill in class name or root element name.)


Clover said...

I’m very glad to found this website because; it carries awesome and actually good data in favor of readers.


Leslie Lim said...

Pretty good post. I found your website perfect for my needs. Thanks for sharing the great ideas.


sarah lee said...

I really enjoyed reading your article. I found this as an informative and interesting post, so i think it is very useful and knowledgeable. I would like to thank you for the effort you have made in writing this article.


Barbie Chiu said...

Hi, just passing by to see something very interesting and gladly I've found it here. Thank you for your wonderful article it really helped me a lot. You can also visit my site if you have time.



Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Cindy Dy said...

Excellent and decent post. I found this much informative, as to what I was exactly searching for. Thanks for such post and keep it up.

Books and Manual