Nautilus: Open with Vim - linux

I'm using arch linux with gnome and I try to open text files with vim by using nautilus. I already created a vim.desktop file in my .local/share/applications folder .
If I choose Vim in Nautilus, nothing happens. My default terminal doesn't work and I already tried to change my default terminal to terminator, but it didn't work. Maybe there is an other option to change the .desktop file to forcing nautilus to open a new terminator window with vim. I guess I need to change the exec parameter.

This should work
[Desktop Entry]
Name=VIM
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=vim %f
Type=Application
Terminal=true
Categories=Development;TextEditor;
Keywords=Text;Editor;

Related

How to make Sublime Text open several files in one window?

Using Sublime Text 3 on the Centos 7.6 (Linux) operating system.
When I use Sublime Text to open files from the command prompt:
[root#localhost www]# sublime sitemap.php
[root#localhost www]# sublime robots.txt
The files are opened in 2 Sublime Text windows, even when the open_files_in_new_window setting is set to false.
How do I make Sublime Text open the files in one window?
I also use a Linux distribution and when I open files from the command line they do open in the same window.
The command you are using on the command line is sublime I suspect that starts Sublime Text with the --new-window option.
Look to see if you have the /usr/bin/subl file on your system. If you do then use subl instead of sublime on the command line and see if that opens the files in the same window.
If /usr/bin/subl is not on your system then you can create it like this:
Note: /usr/bin/subl is just the Sublime Text launcher which is automatically installed on Debian based Linux distributions.
Add these 2 lines to a new file and save it as /home/user/subl:
Note: Change the path to /opt/sublime_text/sublime_text if need be.
#!/bin/sh
exec /opt/sublime_text/sublime_text "$#"
Then run these commands as a super user or with sudo, whatever is easiest with Centos:
$ chown root:root subl
$ mv subl /usr/bin/
Now you should be able to use subl on the command line to open files in Sublime Text and they should open in the same window, e.g.:
$ subl sitemap.php
$ subl robots.txt

Open Cygwin.bat file in current working directory (Windows 10)

New to Cygwin and trying to launch the batch file from the current working directory. I've done similar things before for .exe files in Windows 10 using the Registry Editor (see link):
https://www.windowscentral.com/how-launch-bash-shell-right-click-context-menu-windows-10
My Cygwin.bat file looks like this:
#echo off
SETLOCAL
set HOME=C:\path\to\home
C:
chdir C:\cygwin64\bin
bash --login -i
ENDLOCAL
However, when I right click on a directory in order to "Open Cygwin.bat here", the terminal opens at C:\path\to\home. How can I make sure the terminal opens in the current working directory?
To obtain the expected result you need to use the chere package.
chere -i
is usually enough to create a proper Bash Prompt Here entry in Explorer left mouse button menu.
Please note that the usage of the cygwin.bat is not recommended anyway as does not use mintty as terminal

KDE service menu issues

I have this .desktop file in /home/user/.local/share/applications
[Desktop Entry]
Categories=AudioVideo;Video;
Comment=This Bash script compresses the specified video files (wildcards supported) to lossy h.264 format in an MP4 container
Exec="\\$HOME/Scripts/Git/compress2mp4.sh" %F
GenericName=Batch compress to mp4
Icon=folder-video
MimeType=video/x-msvideo;video/quicktime;video/mpeg;video/mp4;
Name=Compress to mp4
NoDisplay=false
Path=
StartupNotify=true
Terminal=true
TerminalOptions=\s--noclose
Type=Application
Version=1.0
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=
which shows up in the "Open with" menu and works flawlessly.
Then I created another .desktop file and copied it in /home/user/.local/share/kservices5/ServiceMenus
[Desktop Entry]
Type=Service
ServiceTypes=KonqPopupMenu/Plugin
MimeType=video/x-msvideo;video/quicktime;video/mpeg;video/mp4;
Icon=folder-video
Actions=compress2mp4
X-KDE-Priority=TopLevel
X-KDE-StartupNotify=false
X-KDE-Submenu=Video
[Desktop Action compress2mp4]
Name=Compress to mp4
Icon=video-mp4
Exec="$HOME/Scripts/Git/compress2mp4.sh" %F
The service menu shows up but gives this error:
Could not find the program '$HOME/Scripts/Git/compress2mp4.sh'
I tried to replace $HOME with \\$HOME and ~/ but it did not help.
If I type /home/my-user-name/... instead of the $HOME there is a window opens up in the background and closes up right away so I can't catch what is going on there.
Does anyone have an idea on why a .desktop file Type=service does not work while a very similar file Type=application works?
It seems that environment variables are not evaluated by .desktop file processors, as evidenced by similar problems posted online. If anything, it looks that KDE understanding environment variable in /home/user/.local/share/applications is a bug.
For one possible workaround, see this StackOverflow post. Personally, I created service menu with following entry and it did work as expected (pay attention to placement of quotation marks):
Exec=sh -c "$HOME/bin/test.sh %F"
If I use absolute path to script in Exec, it does show something that could be mistaken for "window in background". Name of process appears on taskbar (which usually shows only windows) and quickly disappears. In my case, that was because my test script had only one command inside and finished execution almost instantaneous. How long do you expect your program to run? Have you verified that it does not finish successfully?
If you don't want to use sh workaround and don't want to use absolute path inside .desktop file, consider placing your script in one of directories in $PATH, where .desktop file processor will look for it. You can see value of that variable from plasma point of view by using following command:
tr '\0' '\n' < /proc/$(pidof plasmashell)/environ

.desktop files do not recognize $PATH variable

I have lots of programs installed, for each one I append its directory to the $PATH variable.
this is easy, I open a terminal type the name and it runs, until I decided to make a desktop file for each program. It seems desktop files do not recognize the $PATH variable
[Desktop Entry]
Version=1.0
Terminal=false
Icon=/usr/share/applications/ISE.png
Type=Application
Categories=Digital
Exec=ise
Name=Xilinx ISE
It does not even appear in unity menu, the command ise usually works fine in a terminal, I also tried to use the complete /path/to/ise, still does not appear in search.
but if I remove ise and put for example gedit instead. it appears in search, opens gedit and works fine. how do I make Desktop files recognize the $PATH variable and execute these commands ??

How to activate an existing GVim window

What I'm searching for is a command similar to:
gvim --remote-silent FILE
But without the FILE part. So basically: launch a new GVim instance if none exists, and otherwise activate/focus the existing window. I prefer not to use a dummy file (eg. gvim --remote-silent ~/.vimrc) as that would mess up my bufferlist/MRU.
The reason I'm looking for something like this, is that I'd like to configure a shortcut for GVim (Mod+8) to use in the Linux XFCE window manager.
You can re-activate an existing GVIM instance with
$ gvim --remote-send ":call foreground()<CR>"
That fails when there's no existing server. In that case, just spawn a fresh instance, or check beforehand with gvim --serverlist.
In Ubuntu gvim --remote-silent works but doesn't activate editor window and just waves its icon in sidebar. To change this behavior look here.
This behaviour can be changed from the command line, open a terminal
and type:
dconf write
/org/compiz/profiles/unity/plugins/core/focus-prevention-level 0
To restore the default value:
dconf write
/org/compiz/profiles/unity/plugins/core/focus-prevention-level 1

Resources