:g!/www\.example\.com/d
Showing posts with label vim. Show all posts
Showing posts with label vim. Show all posts
Tuesday, January 14, 2014
Removing Lines that Don't Match a Pattern
Following up on a previous tip, you can also use the "g" and "d" commands to remove lines in your current buffer that don't match a specific pattern. The following example would remove all lines that don't match "www.example.com".
Monday, January 6, 2014
Finding and Replacing Unicode Characters
If you'd like to find a particular multibyte character, you can do the following.
/\%u001cYou can also do a find and replace as you normally would.
%s/\%u001c//g
Thursday, December 19, 2013
Removing Blank Lines
Here's a handy one-liner to remove blank lines from a file.
:g/^$/dBreaking this down. The "g" will execute a command on lines that match a regular expression. The regular expression matches blank lines, and the command is "d" (delete).
Friday, December 13, 2013
Vim.js
I'm not sure what utility this provides, but it's a pretty darn cool hack. Kudos to Lu Wang for this Javascript port of Vim.
http://coolwanglu.github.io/vim.js/web/vim.html
Monday, November 11, 2013
Snipmate
If you like Textmate Snippits, consider installing Snipmate. From the Github page.
SnipMate aims to provide support for textual snippets, similar to TextMate or other Vim plugins like UltiSnips. For example, in C, typing for<tab> could be expanded to:
SnipMate aims to provide support for textual snippets, similar to TextMate or other Vim plugins like UltiSnips. For example, in C, typing for<tab> could be expanded to:
for (i = 0; i < count; i++) {
/* code */
}
The project linked above appears to be a fork of the original plugin, but it's up to date, and it works!
Friday, November 8, 2013
Supertab
If you like Bash auto-completion, you'll love Supertab. Installation and configuration details are available via its Github Page.
Wednesday, November 6, 2013
Vim Gitgutter
Vim Gitgutter Vim Gitgutter shows a diff in the sign (left-hand) column of your editing window. This is a really cool way to see what portions of a file have changed without resorting to git diff.
Edit:
Droggl asked how to disable vim-gutter when viewing log files because of slowness. I've come up with the following solution which seems like it should work.
Assuming your log files end in *.log, add the following to your ~/.vimrc.
Edit:
Droggl asked how to disable vim-gutter when viewing log files because of slowness. I've come up with the following solution which seems like it should work.
Assuming your log files end in *.log, add the following to your ~/.vimrc.
autocmd BufNewFile,BufReadPost *.log setlocal filetype=log filetype plugin onThen make an entry like so in ~/.vim/ftplugin/log.vim
:GitGutterDisableHope that helps!
Basic Recovery
The following commands are useful for recovering an editing session.
Retrieve a list of recoverable files.
Retrieve a list of recoverable files.
vim -rRecover a specific file.
vim -r .file.extension.swp (from swap files listed above)Recover an unnamed (unsaved) file.
vim -r .swpOr from inside of Vim:
:recover .file.extension.swp
Monday, November 4, 2013
Wrap Git With Fugitive
From the Fugitive Github page:
I'm not going to lie to you; fugitive.vim may very well be the best Git wrapper of all time. Check out these features:
View any blob, tree, commit, or tag in the repository with :Gedit (and :Gsplit, :Gvsplit, :Gtabedit, ...). Edit a file in the index and write to it to stage the changes. Use :Gdiff to bring up the staged version of the file side by side with the working tree version and use Vim's diff handling capabilities to stage a subset of the file's changes.
Quite simply, Fugitive provides a ton of awesome hooks for integrating Vim with Git's best features. Check it out!
I'm not going to lie to you; fugitive.vim may very well be the best Git wrapper of all time. Check out these features:
View any blob, tree, commit, or tag in the repository with :Gedit (and :Gsplit, :Gvsplit, :Gtabedit, ...). Edit a file in the index and write to it to stage the changes. Use :Gdiff to bring up the staged version of the file side by side with the working tree version and use Vim's diff handling capabilities to stage a subset of the file's changes.
Quite simply, Fugitive provides a ton of awesome hooks for integrating Vim with Git's best features. Check it out!
Wednesday, October 30, 2013
Sensible Defaults with Vim-Sensible
If you have a fresh Vim install, and you'd like a sensible set of defaults, consider installing the vim-sensible plugin. If you've already installed Pathogen, installing the plugin can be accomplished as follows.
cd ~/.vim/bundle git clone git://github.com/tpope/vim-sensible.git
Monday, October 28, 2013
Pathogen Makes Plugin Management Easy
I have been using Pathogen for installing new plugins whenever possible for quite a while now. In my opinion, Pathogen is the simplest path to extending your existing Vim runtime with additional functionality.
You can install Pathogen with the following command (assuming you're using a Linux operating system).
You can install Pathogen with the following command (assuming you're using a Linux operating system).
mkdir -p ~/.vim/autoload ~/.vim/bundle; \ curl -Sso ~/.vim/autoload/pathogen.vim \ https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vimOnce Pathogen is installed, enable it by adding the following to your .vimrc.
execute pathogen#infect()Once Pathogen is enabled, you can install a wealth of plugins by simply cloning them to your ~/.vim/bundle directory. As an example, you can install the vim-sensible plugin as follows.
cd ~/.vim/bundle git clone git://github.com/tpope/vim-sensible.git
Friday, October 25, 2013
The Wonderful "F" Key
If you press the "f" key in normal mode, Vim will move the cursor forward to whatever character you input after "f" is pressed. As an example, consider the following line:
a quick brown fox
If the cursor was at the absolute beginning of the line, and you pressed "fb" in normal mode, Vim would move the cursor so that it was positioned over the "b" in "brown".
If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".
a quick brown fox
If the cursor was at the absolute beginning of the line, and you pressed "fb" in normal mode, Vim would move the cursor so that it was positioned over the "b" in "brown".
If you press "F", Vim will move the cursor backwards instead of forward. Given the previous sentence, if pressed "Fq", and the cursor was at the end of the line, it would move to the "q" in "quick".
Thursday, October 24, 2013
Back From The Dead
After an almost four year hiatus, I've decided to bring this blog back from the dead. Looking over the last decade, my career as a programmer has been an interesting and challenging endeavor, and over that time period, Vim has been a constant in my professional toolbox. There are countless work days where Vim has saved me hours of pushing bytes around the screen, and a lesser editor would have fallen short of the task.
With this in mind, I feel that I still have a good deal of useful information to share. With the advent of Github and other powerful open source tools, the landscape of the hacker community has evolved. The tools are better, and with reasonable motivation, it feels like any problem is solvable.
In the midst of all of this change, I still believe that Vim is the best tool for the admittedly rote task of munging source code into the best state one can manage given the time constraints and project demands that many of us face.
In lieu of my longstanding love for this text editor (and Linux tools in general), I will resume posting tips to this blog (as they come to mind) in hopes that they can on occasionally help all of you make your hardest problems a little easier and your easy problems a little more fun. Happy Vimming! -Travis
With this in mind, I feel that I still have a good deal of useful information to share. With the advent of Github and other powerful open source tools, the landscape of the hacker community has evolved. The tools are better, and with reasonable motivation, it feels like any problem is solvable.
In the midst of all of this change, I still believe that Vim is the best tool for the admittedly rote task of munging source code into the best state one can manage given the time constraints and project demands that many of us face.
In lieu of my longstanding love for this text editor (and Linux tools in general), I will resume posting tips to this blog (as they come to mind) in hopes that they can on occasionally help all of you make your hardest problems a little easier and your easy problems a little more fun. Happy Vimming! -Travis
Wednesday, December 9, 2009
Vimgrep Tips
I've mentioned vimgrep in a previous post, but I neglected to mention a few useful flags that can be used in conjunction with it.
If you apply the 'g' flag to your vimgrep, it will return all matches instead of just one match per line.
:vimgrep /foo/g **/*
If you apply the 'j' flag, Vim will not automatically jump to the first match.
:vimgrep /foo/j **/*
Thanks to Chanel for pointing these out.
If you apply the 'g' flag to your vimgrep, it will return all matches instead of just one match per line.
:vimgrep /foo/g **/*
If you apply the 'j' flag, Vim will not automatically jump to the first match.
:vimgrep /foo/j **/*
Thanks to Chanel for pointing these out.
Thursday, December 3, 2009
More on Text States
A few people have asked me for more information on text states. An anonymous reader contributed the following in the comments of my previous post on the topic.
Using g+ and g- is very different than using u and ^r.
Try following:
* Create new file
* (in normal mode) Type iOne - Esc
* Type oTwo - Esc
* Type oThree - Esc
* Type oFour - Esc
* Type oFive - Esc
* Type 2u
* Type oSix - Esc
* Type oSeven - Esc
Now you have an undo tree with 2 branches. Typing u only goes up the last branch. Using g- goes up by time - branch doesn't matter here.
Have a look in :help usr_32.txt for good explanation of using the undo tree.
Thanks to whomever contributed the tip!
Using g+ and g- is very different than using u and ^r.
Try following:
* Create new file
* (in normal mode) Type iOne - Esc
* Type oTwo - Esc
* Type oThree - Esc
* Type oFour - Esc
* Type oFive - Esc
* Type 2u
* Type oSix - Esc
* Type oSeven - Esc
Now you have an undo tree with 2 branches. Typing u only goes up the last branch. Using g- goes up by time - branch doesn't matter here.
Have a look in :help usr_32.txt for good explanation of using the undo tree.
Thanks to whomever contributed the tip!
Tuesday, December 1, 2009
Starting on a Specific Line
An anonymous reader writes:
You can open a file on the command line and automatically put the cursor on the last line by typing:
vim + file
If you want vim to start at a specific line you can do the following instead:
vim +LINENUMBER file
Thanks for the tip!
You can open a file on the command line and automatically put the cursor on the last line by typing:
vim + file
If you want vim to start at a specific line you can do the following instead:
vim +LINENUMBER file
Thanks for the tip!
Monday, November 30, 2009
Text States
If you're using Vim 7+, you can use g- and g+ to go between text states. For a more advanced usage see the :help earlier and :help later.
Tuesday, November 24, 2009
Jumping to a Buffer
If you have split windows open with multiple buffers, you can jump directly to a specific buffer number by doing the following:
N<C-w><C-w>
N is the window number you want to move the cursor to.
Thanks to Duff for the coffee!
N<C-w><C-w>
N is the window number you want to move the cursor to.
Thanks to Duff for the coffee!
Monday, November 23, 2009
Indent From Insert
In the comments of my last post, graywh left a great tip that I didn't know about. If you're working in insert mode, you can change the indent level of the current line using <C-t> and <C-d>. These commands work no matter where your cursor is positioned on the current line and adjust the indent level based on your shiftwidth setting.
Thursday, November 19, 2009
Shift-Tab'ing
I have the following in my vimrc:
set sts=4
set et
This allows me to take advantage of the convenience of the tab key when editing while actually inserting spaces into the current buffer. Intuitively I've always wished I could shift-tab to unindent the current line one tab stop. After a minute of fiddling with my vimrc, I found a solution.
imap <S-Tab> <C-o><<
I should also mention that << and >> shifts the provided text based on your shiftwidth setting.
set sts=4
set et
This allows me to take advantage of the convenience of the tab key when editing while actually inserting spaces into the current buffer. Intuitively I've always wished I could shift-tab to unindent the current line one tab stop. After a minute of fiddling with my vimrc, I found a solution.
imap <S-Tab> <C-o><<
I should also mention that << and >> shifts the provided text based on your shiftwidth setting.
Subscribe to:
Posts (Atom)
