If, like me, you have your vim setup to do 4-space tabs, you will have a problem when you are editing Makefiles. Makefiles need real \t tabs. There are two ways to deal with this.
The first is manual: instead of pressing the tab key, press ctrl-v ctrl-i
The second way is using a vim comment hint like so:
# vim: noexpandtabs
... somewhere in your file. With this second method you can now simply press the tab key to get real tabs.
If you need vim to interpret a file in a specific way (or set some values for a specific file only), you can put comment hints in the file.
For example, if you have a Python file that doesn't have a .py extension and also doesn't have a #! line indicating that it is indeed Python, then vim will not turn on the correct syntax highlighting for your file (because it thinks it is just plain text.) To force Python syntax highlighting, place a comment hint at the bottom of your file like this:
def eggs():
pass
# vim: syntax=python
If you have a gvim session open on your desktop, and you later have to ssh in to your desktop to edit the same file, you'll get the familiar message that the file you are editing is open elsewhere and you can save, abort, etc etc.
Do this to safely save and quit that session first:
$ vim --serverlist
GVIM
$ vim --servername GVIM --remote-send '<C-\><C-N>:wqa<CR>'
... and now you can open the file up for editing safely from your ssh session.
To automatically remove whitespace at line end when you save:
autocmd BufWritePre * :%s/\s\+$//e
I have set up this mapping:
nnoremap <silent> <F9> :%! perltidy -q -pbp<CR>
... now I just hit F9 and I'm set.
Add this to your ~/.vimrc file:
if has("gui_running")
imap <c-s> <Esc><c-s>
map <silent> <C-S> :if expand("%") == ""<CR>:browse confirm w<CR>:else<CR>:confirm w<CR>:endif<CR>
endif
It's easy - on the current tab that you want in a different spot, just execute:
:tabm num
... where num is the zero-indexed position you want to move it to.
When using vim an interesting idea is to save a session file for each ticket you are working on.
Say you are working on TICKET-881, and you have the 8 files relevant to this ticket open in tabs, you firstly save your session:
:mksession TICKET-881.vim
Then when you need to go back to work on that ticket at a later stage, start up with that session like so:
$ gvim -S TICKET-881.vim
... and all your tabs, environment, cursor positions etc will be like you left them. This can help to reduce the pain of context-switching between tickets and trying to remember exactly what files you were editing at the time.
Make sure your .perltidyrc is setup, then just:
:%!perltidy -q
... and voilĂ - tidy source.
Sometimes the syntax highlighter in vim gets confused with complicated syntax - and colours might go wrong for a string or comment etc.
You can force vim to refresh the syntax highlighting by pressing Ctrl-l (that's the letter L) - just like how you quickly clear the screen in terminals.
Django Python 960.gs Git Vim NetBSD Nginx
This is the blog of Brad Willis, a software engineer living in Brisbane.
Help
Latest entries
*BSD Agile Apache Apple apt Athletics Best-Practice Censorship Comedy Cool Crosswords Deployment Django English Exim Firefox Git Hardcore Health irssi Javascript Jira Languages Linux Makefile Mathematics Mobile Broadband Mutt MySQL NetBSD nginx Nokia OpenVZ OSX Perl Privacy Python Rant Requirements rsync Ruby Shell Slackware SQL SQLite SSH Standards Subversion Television Testing ThisBlog Vim VMWare (Fusion) VPN X zsh
Checking for exceptions in doctests
Homer's Curling Speech
retry in Python
Vim Makefile tabs
Centos (or RH) IPTables
Converting ssh2 public keys to openssh
Vim comment hints
Context managers in Perl
Dish rotation
Git - fixing commit user
apt stuff
Using shell variables in AWK
Linux - Too many open files
Tell gvim to save and quit... remotely
Vim - automatically remove whitespace at EOL
Python - relative paths from within modules
TV Aspect Ratios
Git - Which commits are in your branch only?
Subversion setup cheat sheet
Force detach a screen session
Modify sudo's use of environment variables
Install all Perl modules
Mutt - delete old messages
OpenVZ VPS and swap space
fail2ban on NetBSD for ssh
NetBSD - Using sup
Python - testing for a sys.exit
Python Best Practice Link Dump
Python script names
Perl - Using an expensive module
Speed of git clone
Perl Modules with Custom Prefix
Perl: tr vs. s
Brilliant sysadmin Reference
Why is GRUB better than LILO?
Why is swap space important?
Perldoc Output
Git's Index
Jira Project Keys
Git GUI