Creating a Python specific settings - windows

In this tutorial many setting are configured so Vim works well with Python. I'd like to use some of the settings only on Python files as I will also use the editor to edit lots of sql files.
Is this the correct way to create Python specific settings?
Create a file python.vim and locate it in the following directory:
M:\vimfiles\after\ftplugin\
Add the following to the file:
setlocal tw=79
setlocal colorcolumn=80
setlocal highlight Colorcolumn ctermbg=233
Do I need to use setlocal or will set suffice? Is setlocal highlight correct syntax?

You're mostly right. The use of ~/.vim/after/ftplugin/python.vim is strictly only necessary for settings from the default ftplugin/python.vim file that you want to overrule, but it's also okay to put other Python-related stuff in there. If it gets out of hand, you can split off things into e.g. ~/.vim/ftplugin/python_tools.vim or .../python/mappings.vim (see :help ftplugin-name).
setlocal
Yes, you need to use :setlocal, otherwise your settings will leak into other buffers opened from the Python buffer.
colorcolumn
The 'colorcolumn' setting is window-local, not buffer-local. Filetype plugins should change buffer settings (as the filetype is associated with a buffer, and windows can display different buffers during their lifetime). Therefore, it may happen that the colorcolumn will persist when you, say, edit a Java file in the same window. You'd need to set up elaborate autocmds to make this fully work, but depending on your workflow, you may never be affected by this, or just don't bother.
:setlocal highlight Colorcolumn ctermbg=233
Highlighting is global; you cannot simply prefix setlocal, this won't work! Just define the color with :highlight once in your ~/.vimrc or color scheme, and it'll suffice. Changing the color per filetype would again require autocmds to fully work.

I store my Python-specific settings is in $HOME/.vim/ftplugin/python.vim, since I do nothing to conflict with $VIMRUNTIME/ftplugin/python.vim. If you want to overrule what the ftplugins with your Vim distribution set up, then $HOME/.vim/after/ftplugin/python.vim is what you want, as it is read afterwards.
setlocal will set a variable for the specific buffer. This means that if you open a c file, in the same session, it won't inherit these settings. I would recommend using setlocal.

Related

how to turn off all vim settings for golang?

How could I turn off syntax highlighting in vim, but only for Go?
I've seen a few posts about just turning off the red-highlighting for white space but that's not quite what I'm looking for.
Add the following line to your vimrc file:
autocmd FileType go setlocal syntax=OFF
Considering that the vim documentation states
The syntax and highlighting commands for one language are normally stored in
a syntax file.
The name convention is: "{name}.vim". Where {name} is the
name of the language, or an abbreviation
If you can find a go.vim file (similar to this one) and delete it (or move it), that should disable the syntax highlighting just for Go.

Custom syntax highlighting in Geany

I am trying to create custom syntax highlighting for Kivy '.kv' files in the Geany editor. Although the specific filetype seems irrelavant to the issue I'm having, as any efforts I make at getting syntax highlighting to work for a custom filetype results in a completely non-highlighted file. I believe I have done my homework on this, and nothing seems to work.
I have added the following to ~/.config/geany/filetype_extensions.conf
Kivy=*.kv;
I also have a custom type definition file named 'filetypes.Kivy.conf' in ~/.config/geany/filedefs/. I have tried basing this file off several of the stock type definition files in /usr/share/geany/ and the file never gets any syntax highlighting applied in Geany. Right now, just for experimentation's sake, my 'filetypes.Kivy.conf' file looks like this:
# For complete documentation of this file, please see Geany's main documentation
[settings]
# default extension used when saving files
extension=kv
# single comments, like # in this file
comment_single=#
[keywords]
# all items must be in one line
primary=size canvas
secondary=pos size
[indentation]
width=4
# 0 is spaces, 1 is tabs, 2 is tab & spaces
type=0
This is very loosly based on the stock XML definition file, but like I said I've tried many other stock files. In many cases I only changed the 'extension=' value to kv and still no highlighting was applied, even though going to Document>Set Filetype in Geany and choosing virtually any random filetype (besides my custom entry) would yeild some sort of highlighting within my .kv file. This is even the case when using the unmodified contents of a stock definition which otherwise works fine on my .kv file when specifically selected in Geany!
Also, the Kivy filetype is listed and selected by default in Document>Set Filetype within Geany, so I must be doing something right here!
I realize this similar question has been asked, but the solutions seem irrelavent to my case, as I've tried every related topic on this and many other sites. My Geany version is 1.22 and I'm running Arch Linux. This is driving me nuts - any suggestions?
Thank you!
Set lexer_filetype= property in the [settings] section of your filetype file. Working highlighting requires that there is a lexer that could be used for highlighting the .kv-files.
For more info see http://www.geany.org/manual/#lexer-filetype
There are three important things to obey:
the configuration file should be placed in "~/.config/geany/filedefs"
the configuration file must have the extension ".conf" - otherwise it won't show up at all (the files in "/usr/share/geany/filesdefs", where I copied my base file from, do not have a ".conf" extension!)
you must set the "lexer_filetype" to an existing (presumably builtin) configuration; e.g. "lexer_filetype=Python"

VIM: created syntax not showing up?

HI people
I recently changed to VIM for coding in C.
I'd like to hightlight the operators +-<=& ... etc
I searched in google how should i do it, and i found the answer in this website: I was suppose to do something like:
syntax match Operadores /[][><()&!|+*={}-]/
hi Operadores guifg=#000000 gui=BOLD
Those characters were supposed to appear as black, bold characters.
However, that doesn't happen when I open my .C files. However, if I create a newfile, (where there the C syntax doesn't show up), I am able to see the black, bolded operators.
How can i correct this situation, and why is this happening (it seams like if my syntax is beeing overwrided by the C syntax).
I'm using gvim, and this is my vimrc:
colorscheme nicotine
set smartindent
set number
set guifont=Inconsolata\ Medium\ 11
set numberwidth=5
noremap j jzz
noremap k kzz
Thanks, any help is appreciated.
(And dont forget I'm a novice in VIM, and ..sorry for my English)
The best way to do this is putting those two lines in the following file:
~/.vim/ftplugin/c.vim
creating it if it's not already present (of course you need to adjust the path to your personal Vim directory if you're not on un*x). That file is called for every C file you edit, and it's executed after the default scripts so your syntax won't be overridden.
For ftplugin to work you also have to add
filetype on
although a full
filetype plugin indent on
is usually more generally useful.

What setting in vim counteracts smartindent's refusal to indent # comments in shell scripts?

I recently started using vim 7 (previously vim 6) and the smartindent setting. For the most part, it works well, though I'm so used to typing a tab after an open brace that it is almost counter-productive.
However, there is one piece of maniacal behaviour. When editing a shell script, I try to create a comment at the current indent level, but smartindent will have nothing to do with it. It insists that the comment must be at level 0 (no indent). What's worse, it breaks shift-right ('>>' and friends) so that they do not work. This is outright insubordination, and I'd like to know what's the best way to fix it?
(I'm also not keen on smartindent's ideas about indenting then after if.)
Preferred solutions will save me manual bashing - I'm being lazy. One option would be 'turn off smartindent when editing shell scripts (leave it on for the rest)'. Another option would be guidelines on how to find the control script for smartindent and what to edit to change the characteristics I don't like. The final option (which I don't need advice on how to do - just the hint that it is the best, or only, way to restore sanity) is to leave smartindent unset.
I saw the vaguely related question on "(PHP and) annoying vim unindent rules"; it doesn't provide me with the direct answer, though maybe the cindent and related items mentioned in there are in fact part of the answer.
Find the indent file, (e.g. /usr/share/vim/vim71/indent/sh.vim on my system)
This line looks like the problem:
setlocal indentkeys-=:,0#
Perhaps you can fix this in your .vimrc or load a custom indent file manually.
edit: It looks more complicated than I thought, but maybe there is something specifically set in the indenting file that you would need to fix.
2nd edit: Looks like I was completely wrong, Check out:
Restoring indent after typing hash
or
howto-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing
Well, after exploring some options, including using ':set cindent' instead of ':set smartindent', I've ended up reverting to just using ':set autoindent'. There probably are ways to make this stuff work exactly as I want it to, but it is messy enough and fiddly enough that I can't be bothered. I've worked fine with autoindent for the previous 20-odd years, and the benefits from the extra bells and whistles provided by smartindent are outweighed by the what I regard as its misbehaviour.
Thank you, Juan, for your assistance. Believe it or not, it did help - quite a lot.
I also discovered a couple of other neat commands, though, while following up on this:
>i}
>a}
These right-shift the block of code you are in. The 'i' version indents the body and not the closing braces (my preferred style), and the 'a' version indents the closing braces to (the version that is required at work).
Also, you can apply qualifiers to '%' in commands executed at the shell:
:make %:r.o
This would run make on the 'root' of the current file name (that's '%:r') followed by '.o'. Or, in other words, if I'm editing somefile.c, this executes make somefile.o.
Add the line below in your .vimrc
filetype indent on
(it will set the right indent mode depending on the filetype)
I had this same issue for a long time, until I realized that autoindent and smartindent are both unnecessary if "filetype indent on" is set in your vimrc - 'filetype indent on' uses the indent/sh.vim (or whatever language) file in your vim directory to figure out the indentation rules, and autoindent and smartindent both can interfere with it.
I haven't tested this with sh, but perl suddenly started behaving properly when I switched.
Sidenote: Juan's redirect, "Restoring indent after typing hash", is not a good solution - while it does correct the problem in one situation (typing code in), it doesn't change how the editor thinks it should be indented, so a re-indent (visual =, or normal ==) will shove it back to the left.
The previous answer suggesting:
:inoremap # X^H#
is excellent. It is the answer suggested by the VIM documentation at ":help smartindent". Note that ^H is entered using CTRL-V CTRL-H. The relevant section from the documentation is below.
When typing '#' as the first character in a new line, the indent for
that line is removed, the '#' is put in the first column. The indent
is restored for the next line. If you don't want this, use this
mapping: ":inoremap # X^H#", where ^H is entered with CTRL-V CTRL-H.
When using the ">>" command, lines starting with '#' are not shifted
right.
I have the following lines in my .vimrc and I don't observe the problem.
set smartindent
inoremap # X^H#
I used to have set autoindent after these two lines but it seems that it has no effect.
Yes that is very annoying. smartindent is really only for C like languages.
See how I enable the appropriate indenting based on language at:
http://www.pixelbeat.org/settings/.vimrc

Command switch to toggle Notepads word wrap

I have a costumer showing Notepad with a large set of data that looks totally misaligned if word wrap is on and I want to force it off. Is there a command switch to do this?
I dont think there is a command switch to do this at all. If you want to force it off all the time then you may want to edit the registry:
Hive: HKEY_CURRENT_USER
Key: SOFTWARE\Microsoft\Notepad
Name: fWrap
Type: REG_DWORD
Value: 0
You could even create a .reg file and put it in a batch file to run it and reset it every time notepad runs.
Usually though if you have word wrap turned off, when you open it up again, it will still be turned off.
you could just turn it off by going to Format -> Word Wrap.
I do not believe there is any command-line option to do that.
You can however set the default behavior by setting the registry-value HKEY_CURRENT_USER\Software\Microsoft\Notepad\fWrap to 0.
Depending on your exact requirements, you might be able to solve your problem by making a bat-file that modifies the registry before starting Notepad. That would be a rather large hack, though.
You could just use Wordpad instead of Notepad, it has word wrap off by default.

Resources