I'm using Mac OSX Lion 10.7.2, Terminal.app supports 256 (output of :echo &t_Co).
In my vimrc I have (PATH/TO/vim/vimrc)
syntax on
filetype plugin indent on
set nobackup
When I "vim blah.py" and :colorscheme torte, syntax colors are not loading. For example python keyword doesn't have a proper colors (They have regular text color). That works for .c files but not python.
I updated my syntax/python.vim but still no luck.
Can someone tell me why?
markfw
Your answer is very good but let me just add one thing to it. In your .vimrc instead of adding just
let python_highlight_all=1
you should add it this way
autocmd BufRead,BufNewFile *.py let python_highlight_all=1
This way it only applies to Python file(s).
Hope this help.
if it works in c but not on py, the filetype file and/or syntax file is not at the right location for python.
vim manual should help you, but I also would try :scr command. This lists all the vim script loaded. So you start vim in two different way
vim your.c
vim your.py
and then in each vim session, type :scr. see how the syntax file for C is loaded (it is like chain reaction), and why it doesnt work that way for python may give you clue.
The way that I made it to work (I'm using Terminal) is to have let python_highlight_all = 1
in my ~/.vimrc file and now everything works fine and all objects such as list, tuple, ... are colored.
For more information please look at the syntax/python.vim.
Try to add the following lines to your ~/.vimrc:
set nocompatible
filetype on
syntax enabled
Quit and relaunch Vim or execute :so ~/.vimrc to reload the settings.
nocompatible remove compatibility with the original vi, this is recommended to get a fully functional Vim.
filetype on activate automatic file type detection, this is the option you want for your Python code to be colored.
syntax enabled activate code coloring, but i'm not sure if this is mandatory here.
You can get some more help by typing :help filetype in Vim.
Related
I am a beginner programmer as well as linux user. Before, I was using windows and the python IDLE was so good. I need not needed to press tab button after the "If" statement or any other loops.
Now, I am using Linux and started to write programs through the command line text editor of ubuntu called as "nano". Here, I need to press tab all the time i use "if" statement. It is very tedious. Especially when there is bunch of nested loops, it becomes difficult to remember the tabs count. And i was thinking if there was any idea to make it work like in the IDLE in windows. I also tried to google the problem but i couldn't explain it in few words. I hope you've got what my problem actually is. And i need a descent solution for this.
Try adding the following to ~/.nanorc (you may need to create the file if it doesn't exist):
set autoindent
Note that nano is pretty lightweight editor, so it lacks a lot of features and customization that other editors provide. You might look into something like emacs or vim if you find yourself limited by your editor.
EDIT: More detail as requested:
Type nano ~/.nanorc in your terminal to open the config file with nano.
Once inside nano, type set autoindent to enable auto-indentation.
Then type Ctrl-o Ctrl-x to save the file.
When you run nano add -i to the command (as in nano -i).
Also you might find this useful.
Try just "M-I" (Esc-I) to switch off autoindent before pasting with Ctrl-Ins (or right mouse click)
Editing a python file in vim and hitting Ctrl+x followed by Ctrl+o in insert mode results in
Error: Required vim compiled with +python
E117: Unbekannte Funktion: pythoncomplete#Complete
I've read a lot of postings and did a lot of fumbling until this:
I'm using vim 8.0.54
installed python and vim are both 32 bit
Vim :vers returns ... +python/dyn and +python3/dyn
the python35.dll file mentioned in :vers -DDYNAMIC_PYTHON3_DLL=\"python35.dll\" is located in in the same folder as the gvim.exe
in my _vimrc let g:pymode_python = 'python3' should tell vim to user python3
:echo has ('python3') returns 1
But the error still remains... any idea besides the error in front of the keyboard?
update 2016-11-08:
It's not a good way, but it solved my problem. I changed
setlocal omnifunc=pythoncomplete#Complete to
setlocal omnifunc=python3complete#Complete in the python.vim file in the ftplugin-folder. Now it works just fine. Any recommendations to achieve the same without modifying the python.vim file?
update 2016-11-08:
Finally solved it with autocmd BufNewFile *.py :set omnifunc=python3complete#Complete in my _vimrc
Is this a Vim you compiled? The vers results looks correct. The error E117 is specific to calling a function using vim's eval feature.
However, the let g:pymode_python = 'python3 variable is for a specific "python-mode" plugin.
Is the python3 library in your search path?
Were python and python3 compiled with --enable-shared?
are the questions to answer.
Not sure if vim searches it's own executable folder first or not, but to check so, you can do:
To use the Python interface the Python DLL must be in your search path. In a
console window type "path" to see what directories are used.
A bit more insight possible in the docs: doc/if_pyth.html#python-dynamic
HTH
I have several python scripts which work just fine but one script has (as of this morning) started giving me this error if I try to run it from the bash:
: No such file or directory
I am able to run the 'broken' script by doing python script_name.py and after looking around a bit the general idea that I picked up was that maybe my line ending of the hashbang got changed (silently) so I looked at the line ending of a working script and a broken script via the :set list option in VI as indicated in this question -> View line-endings in a text file
Both files appear to end using the same character (a $) so I am kind of at a loss on how to proceed from here. Specifically, how to actually 'see' the line ending in case the set list was not the right method.
PS: The script is executable and the shebang is in there, I stated that it's just this 1 script that was working fine before the weekend but it started giving me this error as of this morning.
-- edit: --
Running the script through dos2unix does get it working again but I would like to know of any way to visualize the line ending somehow in VI(M) or why Geany somehow converted the line endings in the first place (as I never work on a dos/windows system anyhow).
From the comments above it looks like you have dos line endings, and so the hashbang line is not properly processed.
Line ending style are not shown with :set list in Vim because that option is only used when reading/writing the file. In memory line endings are always that, line-endings. The line ending style used for a file is kept in a Vim per-file option, weirdly called fileformat.
To see/change the line ending style from Vim, you can use the following commands:
:set fileformat
:set ff
It will show dos or unix. You want unix, of course ;-).
To change it quickly you can save the file with:
:w ++ff=unix
Or if you prefer:
:set ff=unix
And then save the file normally.
So see all the gory details just do :help fileformat, :help file-formats and :help fileformats
You can also use the dos2unix command to convert the file format
dos2unix
This helped me to run the python scripts
This normally happens when we open files in windows do changes and save it.
if you open the file locate the ^M characters at the end of every line
Thanks
Personally, I find it kinda wrong using direct path to python interpreter. As you dont use windows platform, you should have program env, usually in /usr/bin (/usr/bin/env). Try using following shebang:
#!/usr/bin/env python
Different distros store python binary in /bin or /usr/bin (or some weird locations), and this one makes your script config-independent (as far as possible, here we have possibility that env is stored elsewhere; still - it is less possible that env is not in /usr/bin than that python is mislocated).
I had similiar problem (if not exactly the same) and that worked for me.
Also, I have both python interpreters (2.7.x and 3.x) installed, so I need to use "python3" argument for env. AFAIR usually distros link different names to different binaries, so "env python" will run python2.7 on my system, "env python3" (also python33, or smth like that) will run p3k, and "env python2" (also python27, etc) will run python 2.7.x. Declaring which version of interpreter should be used seems like a good idea too.
I came across this problem editing my code on Windows, checking it in with git, and checking out and running it on Linux.
My solution was: tell git to Do The Right Thing. I issued this command on the Windows box:
git config --global core.autocrlf true
Modified the files and checked them in; voila, no such problem any more.
As discussed on the Git documentation.
I have GNU Emacs 23 (package emacs23) installed on an Ubuntu 10.04 desktop machine and package emacs23-nox installed on an Ubuntu 10.04 headless server (no X installed). Both installations have the same ~/.emacs file. I run Emacs with -nw on both computers. I don't have python-mode installed on either machine as my understanding is that this is included in Emacs 23.
On the desktop machine, comments in Python (starting with #) are highlighted in red. On the server, comments appear in plain white text like all other non-highlighted text. Any suggestions as to why comments are not being highlighted correctly on the server (nox) installation?
Update: This appears to be a terminal-related issue. I ssh into the server machine from terminator via the screen replacement byobu. If I run emacs on the server with TERM="xterm-256color" emacs, then comments are highlighted, but all the other colours look very strange.
Update: Adding `export TERM="xterm-256color" "solved" this. The syntax highlighting now has very strange colours though: purples lilacs and light browns. My green current line highlight bar is now a light pale yellow/green. Comments are highlighted in red though :)
Update: Solved. Setting TERM="xterm-color" produces "proper" colors, including highlighting of comments. The server was defaulting to a value of "screen-bce" for TERM which was not highlighting comments.
Update: Unsolved. byobu provides keybindings for various function keys to easily create new screen sessions and switch between them. When TERM is set to xterm-color, these function keys no longer work. So I guess I'll just have to be happy with unhighlighted comments in Python code in Emacs.
For me running emacs -nw from inside byobu with TERM=xterm produced the correct colours for syntax highlighting (the comments in python and bash are all red not just the #) and the function keys work. Note I set TERM as part of an alias for running emacs rather than setting it generally in .bashrc:
alias emacs='TERM=xterm; emacs -nw'
See also this post: Terminal emacs colors only work with TERM=xterm-256color
I don't have the programs you are using installed to test this, but I did notice some differences in the way the function keys are defined between screen-bce and xterm-color. You can try using the below steps to copy the settings from screen-bce to xterm-color.
Using the infocmp program, you can view the differences between the terminfo settings for two TERM settings:
infocmp -d screen-bce xterm-color
You can use infocmp to decompile the terminfo file to its source and make changes to it to try to mimic the behavior of the other terminal. Start by decoding the xterm-color terminfo file.
infocmp xterm-color > xterm-color.src
Edit xterm-color.src and modify the definitions of the kf1 through kf19 fields to match the values for screen-bce. Use infocmp to see screen-bce's definitions.
infocmp screen-bce
Finally compile using the tic program.
tic xterm-color.src
If you run it as a non-root user, it will put the compiled terminfo file into $HOME/.terminfo directory. On my system, it seems like Ubuntu picks this up automatically. You can also install it into the standard /usr/share/terminfo when you're satisfied. Running tic as root should do this for you.
Good luck!
I just added
(set-face-foreground 'font-lock-comment-face "red")
to my .emacs
I am new to emacs and I want to use emacs for python development. I am using Ubuntu 9.10. I frustrated to getting emacs work with python. I use GNU Emacs 23.1.50.1 (x86_64-pc-linux-gnu, GTK+ Version 2.18.0).
Here what I did.
*
Emacs come with python mode but it is confusing there are two types of mode one is python-mode.el and other one is python.el. I use emacs 23 so mine is python.el (I think). Do I need python-mode too? Code completion does not work when I press M-Tab , instead of it window manager works. I tried Esc-Tab but it says "No match" . How can I enable code completion?
After that I installed ropemacs
sudo aptitude install python-ropemacs
Then I created .emacs file at ~/.emacs
and I added followings to .emacs file
(require 'pymacs)
(pymacs-load "ropemacs" "rope-")
(setq ropemacs-enable-autoimport t)
Then when I hit M-/ (Alt-/) it doesn't work when I cick from the menu Rope->Code assist it opens a file dialog for choosing root project folder. I choose current folder which has there are some python code. When I try again Code assist from menu it says
"Completion for x: " nothing but empty set. How can make emacs python code completion work?
Then I downloaded anything.el, anything-config, anything-match-plugin to ~/.emacs.d folder Then I added following lines to .emacs file
(require 'anything-config)
(require 'anything-match-plugin)
(global-set-key "\C-ca" 'anything)
(global-set-key "\C-ce" 'anything-for-files)
Guess what it didnt work. I tried "M-x anything" again I get No match.(I guessed may me combination of C-ca (First control-a then e ) might work it says it isnt defined). Could you explain code completion for python with clear explanations (step by step) to someone dummy as me. Thanks.
Edit: I able emacs work with python with the link. Thanks all for answering
I haven't tried anything, and I haven't had much luck with rope (giant source tree causes my emacs to hang upon any file save). Instead, I find the default completion works well enough for my purposes.
The default completion keybinding is M-/. That runs dabbrev-expand which expands the current word to "the most recent, preceding word for which this is a prefix." It's not perfect: It won't parse types, and it won't search imports, but it works in 90% of the cases.
(You'll have to deactivate rope.)
I think you do want the package python-mode installed! The ropemacs variants appears to be for refactoring only, and pymacs is allows Python as an Emacs-extension language -- neither of which is what you need for standard support.
I'm not really sure you had to do anything fancy to get Python development to work. On gNewSense deltah (fork of Ubuntu 8.04) all I did was edit a .py file with the first line being:
#!/usr/bin/python
And then Emacs just figures it out and gives you python mode options. I didn't have to install anything beyond Emacs.
Then again, this may not be helpful as gNewSense pre-installs Emacs by default. I'll have to do it on one of my vanilla Ubuntu installs.
Emacs worked out of the box for me on Ubuntu 9.10.
Did you try C-c TAB (update imports) before trying code completion? I don't think it work unless you do that.