Tuesday, September 12, 2017

Netrw cheatsheet

To toggle netrw explorer window add this code into your .vimrc:
" Toggle explore with Ctrl-e
function! ToggleExplorer()
  if exists("t:expl_buf_num")
      let expl_win_num = bufwinnr(t:expl_buf_num)
      if expl_win_num != -1
          let cur_win_nr = winnr()
          exec expl_win_num . 'wincmd w'
          close
          exec cur_win_nr . 'wincmd w'
          unlet t:expl_buf_num
      else
          unlet t:expl_buf_num
      endif
  else
      exec '1wincmd w'
      Explore
      let t:expl_buf_num = bufnr("%")
  endif
endfunction
map <silent> <C-e> :call ToggleExplorer()<CR>

<c-e> - open netrw (:Explore vim-command)
- - up one directory
u - change to recently-visited directory
U - change to subsequently-visited directory
qf - display information on file

d - make a directory
% - open a new file in netrw’s current directory
R - rename the file/directory under cursor
D - remove the file/directory under cursor

mf - mark a file
mr - mark files satisfying a shell pattern
mp - print marked files
mu - unmark all marked files
mt - dir under cursor becomes markfile target
mc - copy marked files to markfile target

me - place marked files on arg list and edit them
mx - apply arbitrary shell command to marked file

p - preview file content.
<c-w>z - close preview window.

Changing colorscheme in Ranger

If you want to change the colorschemen in Ranger filemanager just add 'set colorscheme jungle' into the ~/.config/ranger/rc.conf

Friday, August 18, 2017

E126: Missing :endfunction when writing Vim plugins in Python

There no spaces allowed before the trailing EOF.
This code works in Vim compiled with python3 support:
function! MyFunction()
python3 << EOF
print("Test print")
EOF
endfunction

Connection timeout when cloning git repo from Github

Git uses port 9418 to communicate on and it's often not open on a corporate or private firewall. If it's closed you'll need to use https-scheme instead of git. You can make git replace the protocol for you:
git config --global url."https://".insteadOf git://

How To Install GlassFish on Ubuntu Server 16.04

First install java on our ubuntu-server:
sudo apt-get install openjdk-8-jdk-headless
Then download and unpack glassfish server:
wget http://download.oracle.com/glassfish/4.1.2/release/glassfish-4.1.2.zip
unzip glassfish-4.1.2.zip
Now run application server console:
glassfish4/bin/asadmin
Create a new password for the admin user:
asadmin>change-admin-password
Enable Secure Admin Access:
asadmin>enable-secure-admin
Restart all running servers:
asadmin>stop-domain
asadmin>start-domain
Now you can visit the administration page of your Glassfish server that is available on port 4848.

Vim input mode in iPython

$ ipython --TerminalInteractiveShell.editing_mode=vi
... or to set it globally in the profile configuration (~/.ipython/profile_default/ipython_config.py;
c.TerminalInteractiveShell.editing_mode = 'vi'
To create the profile:
$ ipython profile create [profilename]

How to check if a variable is set in Bash?

The right way

if [ -z ${var+x} ]; then echo "var is unset"; else echo "var is set to '$var'"; fi
where ${var+x} is a parameter expansion which evaluates to nothing if var is unset, and substitutes the string x otherwise.

Quotes Digression

Quotes can be omitted (so we can say ${var+x} instead of "${var+x}") because this syntax & usage guarantees this will only expand to something that does not require quotes (since it either expands to x (which contains no word breaks so it needs no quotes), or to nothing (which results in [ -z ], which conveniently evaluates to the same value (true) that [ -z "" ] does as well)).

However, while quotes can be safely omitted, and it was not immediately obvious to all, it would sometimes be better to write the solution with quotes as [ -z "${var+x}" ], at the very small possible cost of an O(1) speed penalty. The first author also added this as a comment next to the code using this solution giving the URL to this answer, which now also includes the explanation for why the quotes can be safely omitted.
The wrong way
if [ -z "$var" ]; then echo "var is unset"; else echo "var is set to '$var'"; fi
This is because it doesn't distinguish between a variable that is unset and a variable that is set to the empty string. That is to say, if var='', then the above solution will incorrectly output that var is unset.

But this distinction is essential in situations where the user has to specify an extension, or additional list of properties, and that not specifying them defaults to a non-empty value, whereas specifying the empty string should make the script use an empty extension or list of additional properties.

Add an 'extract to' option to the Gnome 3 context menu

Suddenly found that "extract to" option is disappeared from the desktop context menu. If you have the same problem you can try to install nautilus-actions to get it back:
sudo apt-get install nautilus-actions
 If it didn't help try to install file-roller and xarchiver with command:
sudo apt-get install file-roller xarchiver
Don't forget to restart nautilus after all.

Make SnipUtils plugin for Vim working on macOS

You have to set up UltiSnipsSnippetsDir to make it run. Put
let g:UltiSnipsSnippetsDir="~/.vim/bundle/vim-snippets/snippets/"
in your .vimrc file.