Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim creating alias for frequently used command [duplicate]

Tags:

python

vim

wsh

waf

Possible Duplicate:
Aliasing a command in vim

So I have to edit waf wscript files a lot . Everytime I execute this command to set the filetype

set filetype=python

is there a way to set up an small alias for the above command ? SO that I can just go in EX mode and type "py" which does the same thing.

like image 365
Vihaan Verma Avatar asked May 23 '12 12:05

Vihaan Verma


2 Answers

If I have understood correctly your question, the following added to your .vimrc shoud work

autocmd BufRead,BufNewFile *.waf set filetype=python

If it is a particular filename like wscript, this works too:

autocmd BufRead,BufNewFile wscript set filetype=python

If you can't rely on an extension or filename you can add a modeline at the top or bottom of your file

# vim: set filetype=python :

See :help modeline for more information.

But it is kinda ugly because you have to modify the file, and if your are working in a team, it can be problematic.

like image 70
Xavier T. Avatar answered Oct 23 '22 15:10

Xavier T.


You don't want go in Ex mode. What you want to go in is Command-line mode.

command! Py set filetype=python

Does exactly what you want: you type :Py<CR> to change the filetype to python.

You can also make it faster with a normal mode mapping:

nnoremap <F11> :set filetype=python<CR>
like image 24
romainl Avatar answered Oct 23 '22 15:10

romainl