a back to vim basics post !
It’s quite obvious that we need different vimrc settings for different files/languages. This is mostly about tabs and characters but it can be extended to more. For example in pytnon (ansible etc) you need to replace the tab to four or eight characters. Most of us are using something like this:
:set tabstop=4 shiftwidth=4 softtabstop=4 expandtab
every time we open a python related file.
But you can set your own options in every file using a comment in the end or in the begging of the file. Like this one:
#!/usr/bin/python2.6
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
... (awesome code) ...
This is called: modeline and is something magic!
Just add the below line to your ~./vimrc file or if you need a more global setting append it to your /etc/vimrc
set modeline
This post is based on this VIM Tip of the day.
Θέλεις να γράψεις μια “δύσκολη” λέξη ή κάποιον τεχνικό όρο που δεν χρησιμοποιείς πολύ συχνά κι έτσι δεν θυμάσαι πως γράφεται. Αλλά τον έχεις αναφέρει στο έγγραφο που χειρίζεσαι μέσω vim τουλάχιστον μια φορά … σωστά!
Τότε την ώρα που γράφεις (δλδ σε insert mode) αρκεί στα πρώτα γράμματα να πατήσεις το ctrl+p
Δίνω παράδειγμα:
w3m -dump https://el.wikipedia.org/wiki/%CE%91%CF%83%CF%80%CE%B9%CF%81%CE%AF%CE%BD%CE%B7 > /tmp/aspirini.txt
Κατέβασα το ελληνικό άρθρο της wikipedia που αναφέρετε στην Ασπιρίνη.
Εάν θες να γράψεις το ακετυλοσαλικυλικό (καλά δεν είναι και τόοσο δύσκολη λέξη):
γράφοντας τα ακε στην συνέχεια πατάμε σε ctrl+p
έχουμε το παρακάτω αποτέλεσμα:
This blog post is based on Sotiris Tsimbonis’s work.
You should always checkzone the dns zone file you have just edited.
But you can also automate this, with a vim wrapper.
small changes @ Thu, 04 Oct 2012 14:03:15 +0300
#!/bin/sh
# ebal, Thu, 04 Oct 2012 14:03:15 +0300
/usr/sbin/named-checkconf
RES=$?
if [ ${RES} -gt 0 ]; then
echo ""
echo "Fix the above errors before editing your zone file"
echo ""
exit ${RES}
fi
ZONE=$1
PREFIX="/var/named/"
CHECKSUM=`/usr/bin/sha1sum ${PREFIX}/${ZONE}`
/usr/bin/vim ${PREFIX}/${ZONE}
echo ""
echo "Checking ${ZONE} for errors..."
echo ""
/usr/sbin/named-checkzone -i local ${ZONE} ${PREFIX}/${ZONE}
RES=$?
if [ ${RES} -gt 0 ]; then
echo ""
echo "You need to fix the errors and try again."
echo ""
exit ${RES}
fi
SHA1SUM=`/usr/bin/sha1sum ${PREFIX}/${ZONE}`
if [[ "$CHECKSUM" != "$SHA1SUM" ]]; then
echo "reloading zone ..."
/usr/sbin/rndc reload ${ZONE}
fi
I use vim as my primary editor.
btw i've never believed in Vim Vs Emacs cause the are two very different programs that do very different staffs with very different ways. Apples and Orange. The only (by me) common thing is that you can use them as editors too.
I use mutt as my primary MUA with $EDITOR=vim.
Writing frequently emails in more than one language can be harsh with no key bindings or a spell checker. You have to be very careful cause a tiny typo error can confuse a lot of people or worse.
People in sysadmin jobs understand what i mean a little better than others.
vim has been integrated with spell checking functionality. English (of course) are embedded.
To read all about that, open vim and on command mode write:
: help spell
If you want globally to map a function key to English spell checking functionality then, in /etc/vimrc write something like that:
:map <f5> :setlocal spell spelllang=en_us<return>
Next time you open vim (or editing an email through mutt) you can press F5 to spell check your text/email.
For Greek spell you need to google it. If you do that, then you’ll find instructions of using openoffice greek spell zip file for creating yours vim spell file (hint: mkspell). You can map it with F6 key and use it as above.
But I am writing both English & Greek and i am boring of typing F[what ever] key or switching languages and mpla mpla mpla mpla …
I use english_greek_spelling_dictionary of Firefox.
So how cool should be if a similar spell checking mechanism exist for vim ? A few days ago, linuxinside.gr had a tribute on pkst (Κώστας Παπαδήμας) and the idea strike me at that moment.
Here are the instructions of making your own
wget -c https://addons.mozilla.org/firefox/downloads/file/108368/english_greek_spelling_dictionary-0.5.5-tb+fx+sm.xpi
unzip english_greek_spelling_dictionary-0.5.5-tb+fx+sm.xpi
cd dictionaries/
At this point we will use mkspell.
Open vim:
vim
and on command mode type:
:mkspell engr English & Greek
The result is something like this:
Reading affix file English & Greek.aff ...
Trailing text in English & Greek.aff line 532: υ
Affix name too long in English & Greek.aff line 871: AA
Reading dictionary file English & Greek.dic ...
First duplicate word in English & Greek.dic line 588565: ΑΒΑ
12794 duplicate word(s) in English & Greek.dic
Compressing word tree...
Compressed 12575870 of 13454281 nodes; 878411 (6%) remaining
Compressed 15867 of 20446 nodes; 4579 (22%) remaining
Writing spell file engr.utf-8.spl ...
Done!
Estimated runtime memory use: 4415720 bytes
If you try to use a region name, then you will be facing the below error msg:
:mkspell en_gr English & Greek
E751: Output file name must not have region name
The result is : engr.utf-8.spl
We can move this to vim default spell location:
sudo cp engr.utf-8.spl /usr/share/vim/vim73/spell/
To map a key to English-Greek spell dictionary, open /etc/vimrc and add the below line:
:map <f6> :setlocal spell spelllang=engr<return>
Here is an example:
and here is the file (if you dont want to make it)