Tips & tricks

Go to recent tab in Chrome

For a long time I have been searching for such feature in Chrome, but I could not find anything default. And it was difficult to understand, as it is so obvious for a developer. Windows has it (Alt + Tab), Resharper has it (Ctrl + ,), visual studio without plugins has it, same to Sublime Text, vim etc. But not Chrome, a default development tool for most of web developers. At the same time there are extensions, but most of them work far from what I expect. Below I would like to share what useful I have found. Both are fine, but for sure not flawless.

Ctrl + Tab MRU

ctrltabmru

This is the one I like the most. I have it bound to Ctrl + comma. That means that a combination Ctrl + comma, comma take me to the second recently used tab. It’s obvious, but actually this is the first extension I have found, that supports it.

The bad? Several times it had problems to render the list correctly. On the other hand I tried to reproduce it while writing this blog post and I couldn’t.

Quick Tabs

quicktabs

This one is more advanced, as it allows to search in usage history, recently closed and bookmarks. Unfortunately Ctrl + comma, comma, comma does not work as expected (but still it’s worth to have because of searching functionality).

What about you?

Do you have your own solution for that? I would really like to know if there is something better or at least if there is another useful alternative.

Advertisements
Command line: VIM

Vim for .NET – flickering omnicomplete problem

Since the beginning of my journey with vim I have experienced a problem with flickering screen. After a several tries with Google it turned out that it’s mostly about vim omnicomplete, and even more specifically Omnisharp-vim preview functionality.

In order to get rid of the flickering, you need to change the default omnisharp switch:
set completeopt=longest,menuone,preview
to:
set completeopt=longest,menuone

The consequences are that you will not see the details of selected item in preview window, but actually I have never used it (since what’s shown in the menu is enough).

Command line: VIM

Vim for .NET – Move type to another file

When I started my journey with VIM for .NET, I tried to find VIM alternatives of common shortcuts/refactorings that I used in Visual Studio. Surprisingly I noticed that most of them were already there (Searching, Go To Definition, Find usages, create class etc). The one I had a real problem with was “Move type to another file”. I really like the idea that I can create all the types in one file and then use some shortcut (with ReSharper: Alt + Enter) to distribute them to their own files. As I could not find any existing plugin (which is really strange) I took it as a good time to try myself in writing vimscript. It turned out that it was pretty easy exercise. Here you can find the script that you can append to _vimrc to enable the feature.


function! ExtractClassToFile() abort
    " copy class name
    execute "normal! ?^.*\\sclass\\s\0/class\wviwy"
    " and store for future use (filename)
    let className = getreg('"')

    " cut class code and store it inside default register
    execute "normal! ?^.*class\V/{\%x"	
    " and store for future use
    let classText = getreg('"')
   
    " copy namespace + usings
    execute "normal! ggv/namespace \/{\ly"
    let usingAndNamespace = getreg('"')
    
    " get filename for the new file
    let currFileLocation = expand('%:p:h')
    let newFileName = "\\".className.".cs"
    let newFileFullPath = currFileLocation . newFileName
   
    " open the new file
    execute "e ".newFileFullPath

    " render the file
    let failed = append(line('$'), split(usingAndNamespace, '\n'))
    let failed = append(line('$'), split(classText, '\n'))
    let failed = append(line('$'), '}')

    " remove empty line in the beginning
    execute "normal! dd"
    " save
    execute "w"
endfunction

noremap ef :call ExtractClassToFile()
Command line: VIM, Programming (back-end)

Vim for .NET – Set up

In order to start the journey with VIM for .NET you need to set up the environment and get all the plugins. There is no all-in-one standalone package thus you need to prepare it by yourself. I suggest the following configuration:

1. Install VIM

Install the newest package from (full installation minus “visual studio add-in”):
It is not so trivial as going to VIM homepage and clicking download. Vim.org contains a default compilation of vim for Windows, but compilations differ from each other significantly. VIM for Windows is distributed as GVIM which is a classic VIM for terminal + VIM wrapped up in dedicated window frame and mouse support. Both can be precompiled with different set of features (over 100), like Lua language support, Python intergration, Perl, Ruby etc. Some of these are very important (especially Python). Vim.org copy contains GVIM compiled with Python/Python3, but classic VIM not. That’s why I recommend to download the brew from here (full installation minus “visual studio add-in”): https://sourceforge.net/projects/cream/files/Vim/

Untitled

2. Install Python 2.7.x

Download: https://www.python.org/ftp/python/2.7.10/python-2.7.10.msi

Most of vim extensions are written using Python language (including our most wanted Omnisharp). In order to use it, you need to install Python. Still the most common version is not 3.x but 2.7.x. It is vital to choose the right architecture (x86 vs x64) – it must be same as VIM.
After installing it, you should be able to run

":py print 'hello world'"

in VIM.
Untitled2

3. Install pathogen-vim

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles
mkdir autoload
mkdir bundle
curl -LSso .\autoload\pathogen.vim https://tpo.pe/pathogen.vim

to %SYSTEMDRIVE%%HOMEPATH%\_vimrc add
execute pathogen#infect()
filetype plugin indent on

(you can run ":e $MYVIMRC" in VIM)

Vim is so powerful because of its extensibility. In order to use the full power of it you need a good plugin loader. Pathogen-vim automatically scans /vimfiles and loads plugins. This is a prerequisite for most of other plugins
Untitled3

4. Install Omnisharp-vim

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone https://github.com/OmniSharp/omnisharp-vim.git
cd omnisharp-vim
git submodule update --init --recursive
cd server
msbuild
cd ..\..

If (msbuild is not found, add "C:\Windows\Microsoft.NET\Framework64\v4.0.30319" to your $PATH)

Omnisharp is a tools that analyze the solution and provides metadata for our project. It’s like external Resharper engine (run as console application listenning on http). This is used to add syntax checking of our project, autocomplete, code actions and many more. In order to connect it with VIM you need a wrapper and here we have "omnisharp-vim".
Untitled4

5. Install vim-dispatch

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone git://github.com/tpope/vim-dispatch.git

It’s a plugin that automatically starts OmniSharp server when you open *.cs file. Without it you would have to run :OmniSharpStartServer manually.

6. Install syntastic

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone https://github.com/scrooloose/syntastic.git

It is something like Resharper icons next to the code (describing errors, warnings, hints, suggestions).
Untitled5

7. Install CtrlP

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone https://github.com/ctrlpvim/ctrlp.vim.git

Together with omnisharp it provides support to contextual actions, go-to-everything, buffer explorer (go to previous file) etc
Untitled6

8. Install NERDTree

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone https://github.com/scrooloose/nerdtree.git

“Solution” tree for VIM. Very useful as there is no default alternative (you would have to go to selected file with CtrlP or command line).
Untitled7

9. Install yeoman

npm install -g yo
yo install csharp-cli-app generator

It creates files/projects from template (with online template browser). There are several .NET templates as well. It’s a must for fron-end developers, but VS devs already have built in “add new” wizard (although yeoman has better support from community).
Untitled8

10. Install vim-snipmate

cd %SYSTEMDRIVE%%HOMEPATH%\vimfiles\bundle
git clone https://github.com/tomtom/tlib_vim.git
git clone https://github.com/MarcWeber/vim-addon-mw-utils.git
git clone https://github.com/garbas/vim-snipmate.git

It helps to create useful code snippets – similar to "prop", "for", "class", "wl" etc.

11. Configure _vimrc

All of the plugins above can be adjusted manually using _vimrc file. You can do this on your own or use some sample file, like mine.

That’s it.

There’s a plenty of steps, but I’d bet it’s less time consuming than installation of Visual Studio.