Can you set different fonts for different file types in gvim? - vim

For example source code pro for .py files and ubuntu font for .txt files

No, at least not where two different fonts are displayed simultaneously (e.g. when you have both a Python and text file open in two window splits). You can dynamically switch the entire global 'guifont' option triggered by :autocmds, though.
The reason for that is that Vim / GVIM adhere to a classic terminal model, where the entire screen consists of fixed-width display cells. Different fonts, due to their different size properties, would either look very ugly or disrupt that fixed cell model.

As others have pointed out, you can't have multiple fonts in the same instance of gvim (the same desktop window) at the same time. But if you're opening a new gvim for each different type of file, then you can do it with autocommands, specifically something like:
autocmd FileType python setlocal guifont=<font>
Replace <font> with whatever font you want (you can check set guifont? to get the formatting right).
YMMV if you use a lot of buffers, tabs, etc. But personally, I can't think of a time (other than :help) when I have two different filetypes open simultaneously.

Check out the following recent discussion in vim-use groups. There it is claimed that it is possible to change font based on syntax:
vim-use-thread

Related

set tab-stop = 2 in vim permanently for a file

How to set the tab size as 2 for a file permanently in vim as whenever I open a file in other editors like nano or upload the file in github then my indentations are all incorrent whenever I try to resize the tab to 2 for an existing file which has all incorrect indentations. The tab-stop=2 does not permanently resizes the tab and I see all incorrect indentation when I open the same file in nano or view it in github.
Tabs don't have an inherent size so it is up to each program to decide how to display them and there is simply no way to guarantee that a tab will always look the same everywhere.
This is precisely the main issue people have with tabs: you can tell $SOME_TOOL and $SOME_OTHER_TOOL that a tab takes two spaces but that setting can't possibly be carried over to every tool.
Modelines are editor-specific (and they are too intrusive anyway) and Editorconfig is not universally supported so there is really no universal solution beyond using spaces for indentation.

How to highlight portions of a PDF file programmatically (eg. using command line)

I am interested in highlighting portions of a PDF programmatically, hopefully through a command line tool of sorts. My particular PDF file is not OCRed so the text is not searchable, but the particular places that I would like to highlight occur on every page in the same position. I was wondering if there is a tool to do this where I can input the rectangle positions in pixels into the command line tool and it would highlight the relevant portions for me.
Previous Findings
I have looked over the internet and found a few sites noting how to do this by searching for the text. Unfortunately that is not possible for me as my PDF does not have OCR.
I have searched stackexchange for similar questions and found
How to Highlight Text in PDF with commandline (windows)? and https://stackoverflow.com/questions/32713633/how-to-highlight-text-in-pdf-using-acrobat-reader-from-command-line but both were unanswered.
Potential Ideas
The first link had a possible lead with a given link to
Add comments to PDF files automagically with regular expressions
which uses ghostscript to include annotations. Is it possible to use ghostscript to highlight the pages in a similar fashion by coordinates.
The second link mentioned using command line options for the adobe acrobat/reader exe file, but searching the relevant manual for the command line switches does not show any highlighting options. It may be possible that Adobe does not support the highlight option through command line anymore, which would be unfortunate.
My last idea would be using AutoHotkey to create a macro that does an actual highlight for me using a GUI program, but that would be the last resort.
What do you all think? Any ideas on what to do, or things to check out? I am willing to program out a solution and can work out the solution on Windows or Linux if necessary. Thanks in advance.
I would have thought a Highlight annotation was what you wanted.Highlight annotations are a type of text markup annotation and as such take a set of QuadPoints which describe the bounding box(es) to apply the annotation type to.
Since you say you know the co-ordinates this would seem appropriate for your use. Of course, you will have to create the Annotation on every page, and you will have to learn how to program this with a pdfmark, but I believe it should work.
Note that the co-ordinates are in user space (generally 72 points to the inch) NOT pixels, because PDF is not an image format there is no concept of pixels, except for included images.
There are quite a few officially unsupported command line parameters to acrobat or the acrobat reader (acrord32.exe in Windows).
See: https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
This includes a parameter to highlight with four integers at left,right,top,bottom that are in some unspecified units but with 0,0 at the top left of the page.
EXCEPT... I have been unable to get this to work.
I can pass in parameters to search and zoom but highlight never shows anything.
For instance:
start acrord32 /n /s /a "search=MS25441&zoom=300&page=1&highlight=0,55,0,65" floorplan1_ABM_cameras.pdf
Opens the files, searches for the string, zooms to 300% but nothing shows for a highlight no matter what coordinates I specify.

colorize text for text editor (like emacs) based on pre-defined condition?

from https://stackoverflow.com/a/21666354/433570
It's dos based solution though, can it be done for linux based system?
I'm trying to highlight stuff in my log file.
For instance, I want to highlight the line of nginx log which has slower response time than 1 sec.
** edit **
Currently I'm using hi-lock-mode
eg, I put a mark on a line that shows slow response, then use regex & hi-lock to highlight it.
I guess this is ok solution, for now.
I am wondering if there's a better solution.
hi-lock mode with user-defined function rather than regex is what I would hope for.
I would define functions, and mapping between function-color.
Then I would M-x apply [function]
def slow(line):
if ... :
return True
return False
slow: yellow,
iPhone: blue,
I think this would be useful to inspect logs..
I wonder if there's a similar functionality available out there?
Why don't you write your own major mode for your files?
A basic major mode with font-lock support is not hard to implement. There are plenty of documentation on this on the net. All you need is a syntax table (so that Emacs would know which characters start strings etc.) and some font-lock rules for syntax highlighting.
The easiest, though, is to start with an existing one, for example ini-mode, a small major mode for editing Windows-style ini files.
Unless your files have a specific file extension or otherwise follow a specific naming convention, you might want to add an entry to magic-mode-alist, which provides you with a way to recognize specific files based on the content rather than the file name.
If you would like to see your files colored in a terminal window when viewed using more or less, you can use e2ansi, a package that use Emacs to generate an ANSI version of syntax highlighted files.

Auto format a file to print in Vim

Sometimes I work with a file that contains source code, columns, plain text, sometimes all 3. It looks great on the screen. However, when I send it to a printer, it comes out a mess: columns/tables are misalignment, code looks like a spaghetti, etc.
I use Vim (7.2). How do I reformat the file to please the printer?
Perhaps I should shorten the length of a line?
How do you send it to printer? Try :hardcopy command.
You can also lookup printing-related options printfont, printdevice, printoptions, etc.
See also printoptions and others on vimdoc.sourceforge.net
It's not a pure-Vim solution, but I've had good experiences with GNU a2ps for converting (relatively) poorly formatted text documents (a couple Project Gutenberg titles, to be specific) to a nice, printable pdf/postscript file.
If you aren't worried about having to have a one-step process with no intermediary between Vim and the printer, here is a fairly flexible strategy.
If you have a dark background in Vim with light foreground but would like to print black-on-white since white-on-black is great for terminals but not so great for printed media, try colorscheme shine. (Another nice colorscheme for this is Hemisu, which is superior to Shine for printing diffs.)
Use :TOhtml to convert the document to HTML.
Save the file and open it in your browser.
Open print preview from your browser and set up the window appropriately.
For example, I just printed a nearly 200 column file brought in from Vim this way, and it worked out fine (both in the sense of "well" and in the sense of "small print" :) because I was able to use Firefox's print preview to set the file to print in landscape mode.
Print the file from your browser.
I agree there is a problem. yim has 'formatoptions' to 'wrap' lines together the way you want and break lines at appropriate places ('linebreak', 'breakat') which would give you an elementary wysiwyg word-processing capability, except that it only works on the display and has no effect when sent off to print.

modifying font size using shell script

Is there any way to change the font size of terminal window(GNOME or KDE) from inside a shell script
Actually I want to display a file in a particular format on screens of all sizes.
Can i do it using scripts??
For KDE, you can use dcop to set your font size.
For example:
dcop konsole-8540 session-6 setFont Monospace,20,-1,5,50,0,0,0,0,0
(the 20 in the example above is the font size)
I for one would surely not want a shell script (or any other program for that matter) to change my terminal settings! If it were to find a way to do so, I would use it exactly once and them remove it from my machine.
Seriously: This is something you should not do, because the user will probably have set his or her screen size to the way it is for a reason that is probably better than yours for changing it. Consider handicapped people who might need a specific font or very large letters to be able to read the screen at all.
Better try and make your application suitable for any terminal layout - there are variables for telling you how many characters wide and how many lines high your current environment is.

Resources